Hello I would like to have an advice I'm trying to delete some files that were written on a certain date by doing an ls -l | grep "Aug 1" | xarg doesn't work.
You have suggestions Thank you Greetings
Location: Asia Pacific, Cyberspace, in the Dark Dystopia
Posts: 19,118
Thanks Given: 2,351
Thanked 3,359 Times in 1,878 Posts
You can use find with the -exec flag for this.
For example in Linux:
Code:
find /path/to/files* -mtime +30 -exec rm {} \;
Note that there must be spaces between rm, {} and \;
More Explanation:
The first argument is the path to the files you want to delete. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.
The second argument, -mtime, and this switch is used to specify the number of days old that the file is. If you enter +30, it will find files older than 30 days.
The third argument, -exec, allows you to pass in a command such as rm. The {} \; at the end is required at the end the of the command.
NOTE:
Do not run this without testing it first... for example. always run first and look at the output, for example: