Hi,
I am using the find command to remove all the files in a directory ending .NEW and created more than a day ago.
The command I am using is:
find . -name '*.NEW' -ctime +1 | xargs rm
The problem is that it does not work properly. I still have files which were craeted more than a day ago.
In other words, when I run this
find . -name '*.NEW' -ctime +1
I dont get an output.
Is there anything wrong with the syntax or something else?
Thanx
the right syntax is
find . -name "*.NEW" -ctime +1 | xargs rm
it is double quote at the beginning and the end of "*.NEW" not single quote.
try
find . -name "*.NEW" -ctime +1
make sure you issued the find command from the right directory
I have used both single and double quotes but it doesnt work with either. Also I am in the correct directory.
Since you're using the -ctime option, do an "ls -lc" in the directory to make sure that you know what the ctime is. You may want to try the find command with the -mtime option.
Hi Perderabo,
ls -lc returns the files created more than day ago.
Also, I tried mtime but didnt work either.
Strangely when I use
find . -name '*.NEW' -ctime -1 it gives me the correct results.
Got it.
The command should be
find . -name '*.NEW' -ctime +0
Thanx everyone
You can do the delete as part of the find command:
find . -name "*.NEW" -ctime +0 -print -exec rm {} \;
Note that this prints out the name of each file it deletes.
Hi kemisola,
I would rather use xargs than exec.
xargs rm
By using xargs in this command, I can remove all of the files that end in .NEW, but instead of creating a separate process for each file , only one process is started through xargs.
That way it is more efficient.