find - exec | pipe to xargs

arood

New Member
Credits
27
Hi All, I'm new to the forum and desperately trying to work out what's going on here!

I'm trying to do something fairly simple..... find files which have been modified in the past 24hrs with the exception of TAR files.... and then tar them all up nicely.

The command: find .. -mtime -1 -a ! -iname "*.tar"
seems to nicely output the correctly filtered files to STD_OUT.

I've then tried exec and xargs to tar them, but i then get a tar file will all files, not the filtered ones.

I've tried;
find .. -mtime -1 -a ! -iname "*.tar" -exec tar cvf output.tar '{}' \;
and
find .. -mtime -1 -a ! -iname "*.tar" | xargs tar cvf output.tar

both tars include files not modified within 24 hours and contain other tar files. When it gets to itself, the file grows out of control.

Can anyone please help me understand why the first command shows the results filtered, get after the redirection they're expanded back out!??? I'm going mad here.... any help would be much appreciated :)

TIA
 
Last edited:


arood

New Member
Credits
27
UPDATE - CASE SOLVED.

Whilst the output of the first command (i.e. find .. -mtime -1 -a ! -iname "*.tar" ) does not show the additional tar files which are found in the output... it does contain the folder name under which the file is contained.

I've therefore updated the find command to include the "-type f" filter thereby excluding the directory names (which weren't needed as all the required files are listed explicitly).

Updated as it might help someone else one day. Thanks.
 

Fanboi

Active Member
Credits
3,575
Good job! Please mark your question as solved (you can edit the title and add "[Solved)"). Well done.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Members online


Top