Results 1 to 3 of 3
I'm having some trouble with the tar command I'm trying to backup all files that end with .config in the /etc directory and then name the backup file backup.tar
So ...
- 10-31-2011 #1Just Joined!
- Join Date
- Oct 2011
- Posts
- 1
Question about using tar command
I'm having some trouble with the tar command I'm trying to backup all files that end with .config in the /etc directory and then name the backup file backup.tar
So I use this command using the wild card
tar –cvf backup.tar /etc *.config
and all it does it just backup everything in the /etc directory instead of just backing up files that end with .config and gives and error
tar: *.config: Cannot stat: No such file or directory
Not sure what I'm doing wrong
- 10-31-2011 #2
Using tar
you can't use wildcards directly in a tar command. but there is an alternative.linux user # 503963
- 11-06-2011 #3Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,954
Here is the relevant section from the link provided by scathefire (to whom is due thanks for a good link):
Code:TAR and Wildcard Characters (*) in Creating And Restoring Archives Wildcards can *not* be used directly in tar commands. The following commands will *fail*: host% tar -cf $RMT *.log host% tar -xf $RMT *.log Wildcard functionality can be obtained by combining Unix features with tar. Creating a tar archive of a sub-set: A command placed between back graves (`) will expand on the command line of another command. The ls and find commands will accept wildcards and list sub-sets of files. For example, these two tar commands: host% tar -cf t.tar `ls *.log` host% tar -cf t.tar `find *.log -print` both expand to become: host% tar -cf t.tar gtestit.log test.log The ls or find command, placed between back graves, replaces the file specification on the tar command and expands to a list of files. Sample session: unix:~> ls *.log gtestit.log test.log unix:~> tar -cvf t.tar `ls *.log` a gtestit.log 4 blocks. a test.log 22 blocks. unix:~> tar -cvf t.tar `find *.log -print` a gtestit.log 4 blocks. a test.log 22 blocks. unix:~> tar -tvf t.tar -rw-r--r-- 4018 204 1985 Jan 13 11:58:52 1995 gtestit.log -rw-r--r-- 4018 204 10819 Jan 11 13:43:41 1995 test.logSometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote
