Reputation: 61
I am using the following command while I am sudoing the correct user;
ls -t1 /cs/wlsconfig/wls10.3.2/servers/cmt/logs | tail -n +10 | xargs rm -r
But I get the following exception while using this command;
rm: cannot remove `cmt.log00045': No such file or directory
Irrespective of the fact that running the following command does return results with a list of files;
ls -t1 /cs/wlsconfig/wls10.3.2/servers/cmt/logs | tail -n +10
Any leads would be appreciated !
Upvotes: 2
Views: 912
Reputation: 21489
You need to prepend the path to your rm
call or change into the directory first. Try this:
cd /cs/wlsconfig/wls10.3.2/servers/cmt/logs
ls -t1 | tail -n +10 | xargs rm -r
However this won't work with file names containing spaces. This is one of the reasons why it is a bad idea to parse the output of ls.
Take a look at these similar questions and their solutions:
Upvotes: 3