-   Programming (
-   -   List specific files and delete results (

niiiro 07-08-2011 08:55 AM

List specific files and delete results
Hello people,

A simple questions, I ran the command:


ls -ltr | head -n40
I'd like to delete all the files listed...


szboardstretcher 07-08-2011 09:00 AM

Is your purpose to delete the oldest 40 files in a directory?

something like:


ls -tr | head -n2 | xargs rm

You don't want -l, because it will give you other garbage that you don't need. Please test this before rolling into production, so you understand it.

Modify -n2 to -n40 once it has been tested.

niiiro 07-08-2011 09:08 AM

Always nice to learn something new and useful in Linux :)

thanks buddy!

All times are GMT -5. The time now is 09:26 PM.