Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #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

  2. #2
    Linux Enthusiast scathefire's Avatar
    Join Date
    Jan 2010
    Western Kentucky
    Using tar

    you can't use wildcards directly in a tar command. but there is an alternative.
    linux user # 503963

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Here is the relevant section from the link provided by scathefire (to whom is due thanks for a good link):

    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.log
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  4. $spacer_open

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts