Delete the files except the files in a list
Hello everyone,
I want to delete all files in a directory which are older than certain days (I can get it done using grep with -mtime), BUT except the files listed in a temporary file, /tmp/filesnotdelte.txt. For example, under directory mydir, there are files older than 10 days, filename1, filename5, filename6, filename10. in /tmp/filesnotdelete.txt, there are two entries at this time, filename1 and filename6. looking for a simple way to delete files which are not listed in /tmp/filesnotdelete.txt, at this time, only filename5, filename10 should be deleted. NOTE, the entry in the temporary file is NOT always same. Thanks in advance!!! |
Quote:
|
Hello TB0ne,
Thank you very much for your reply! I am looking for one command to achieve it if it is possible. I can delete all files except *.c and *.h in my current directory using this command: $ find . \( \! -name "*\.c" \! -name "*\.h" -type f \) -print0 | xargs -0 /bin/rm -f Just wanted to know if where is a way to use one command to delete all files except the ones listed in a temporary file, OR I have to use array to approach it? Thanks again! |
Quote:
|
It could be done with a for loop and an if instruction inside the script.
|
Thank you fbsduser!
Could you please provide me the sample code, I am not familiar with shell script. Thanks again for your help! |
Quote:
|
All times are GMT -5. The time now is 06:56 PM. |