Tar using Matching pattern and removing leading paths
I'm trying to backup the log files contained in /var/log while removing leading paths at creation.
without removing the leading paths I can do this simply with: tar -cvf ~/backup.tar /var/log/*.log unfortunately I can't seem to remove the leading paths. I have looked online and found using -C will change the working directory for the command but when I do so, it doesn't recognize the pattern glob and says it cannot find the file or directory *.log tar -cvf ~/backup.tar /var/log/ *.log I'm sure my syntax must be off and I've tried some silly variations. |
I think if you go to the /var/log directory and perform that command this way, it may do what you want:
Code:
/var/logs:$ tar -cvf ~/backup.tar *.log |
you can use --transform option to modify filenames, probably something like this:
Code:
tar -cvf ~/backup.tar --transform 's!/var/log!!' /var/log/*.log |
+1 for post#2.
Tip: cd in a subshell to preserve the current directory in the main shell. Code:
pwd |
You can use on extract
Code:
# tar xf --strip-components=NUMBER file.tar |
All times are GMT -5. The time now is 09:18 AM. |