LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   List specific files and delete results (http://www.linuxquestions.org/questions/programming-9/list-specific-files-and-delete-results-890589/)

niiiro 07-08-2011 08:55 AM

List specific files and delete results
 
Hello people,

A simple questions, I ran the command:

Code:

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


Thanks!

szboardstretcher 07-08-2011 09:00 AM

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

something like:

Code:

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 05:30 AM.