find /informatica/dev/SrcFiles* -mtime +7 -and -size +1M -exec tar -cvjf>

So I ran this command and I can't find the file after it was done running (probably because I never named it?). The directory contains thousands of files.

Where do I put the name of what I want the .tar to be called?

Does anybody know where the tar file gets made and put or what it's called after I run it?

  • 3
    Did you really have that > at the end? That makes the command syntactically invalid. – Gilles Aug 2 '13 at 23:47
find /informatica/dev/SrcFiles* -mtime +7 -and -size +1M -exec tar rvf file.tar {} \;

where file.tar is your archive name. If your use the option c with tar, it will create a new archive for each file, overwriting the previous one. If you use r, it will append to the previous archive.

  • okay so when i find the files and want to put them all in the tar file, I should use the r option only? – mkrouse Aug 2 '13 at 15:11
  • Yes, you need to change c to r. If you have too many file in the directory, use ls -ort to search for the most recent ones. – unxnut Aug 2 '13 at 15:13
  • Actually its not doing anthing /informatica/dev/SrcFiles> find /informatica/dev/SrcFiles* -mtime +7 -and -size +1M -exec tar rvf files.8.2.2013.tar {} \; – mkrouse Aug 2 '13 at 16:04
  • 2
    What happens when you issue the command without the -exec part? – unxnut Aug 2 '13 at 18:13
  • @unxnut Is the -and really necessary? I believe it's implied. – Joseph R. Aug 2 '13 at 20:54

You should have referred to the tar man page, simply by issuing the command:

man tar

For your specific question, here is a good example of how to do it:

 find /informatica/dev/SrcFiles* -print0 -mtime +7 -and -size +1M | xargs -0 tar cjvf /mydir/mytarfile.tar.bz2

This way, the tar command will be called only once, instead of being called each time a file is found. Notice the -print0 and -0 arguments. This will avoid word splitting ...

Also, you should make sure that the archive is not placed in the same directory, while its name may come up in the search pattern. You will get an error suggesting that you can't add an archive to itself!


I recommend to use star as star comes with a builtin find. This enables features that cannot be achieved with a separate find command.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.