LinuxAnswers - the LQ Linux tutorial section.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-08-2011, 08:55 AM   #1
Registered: Feb 2010
Posts: 65

Rep: Reputation: 1
Lightbulb 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...

Old 07-08-2011, 09:00 AM   #2
Senior Member
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,502
Blog Entries: 1

Rep: Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178Reputation: 1178
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.

Last edited by szboardstretcher; 07-08-2011 at 09:05 AM.
Old 07-08-2011, 09:08 AM   #3
Registered: Feb 2010
Posts: 65

Original Poster
Rep: Reputation: 1
Always nice to learn something new and useful in Linux

thanks buddy!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete/move/copy files of specific date imsajjadali Red Hat 26 11-07-2013 11:34 PM
How to delete all files with specific word in filename? moviecarpet Programming 13 05-26-2011 08:44 AM
[SOLVED] Recursive delete specific files from sub-directories. guriinii Linux - Newbie 11 03-07-2011 10:41 AM
How to delete files tat contains a specific word?? linuq Linux - Newbie 4 06-30-2008 12:12 AM
ow do I delete all files which were created on a specific date marsguy Linux - General 9 08-21-2007 08:15 AM

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

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration