LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 07-08-2011, 08:55 AM   #1
niiiro
Member
 
Registered: Feb 2010
Posts: 63

Rep: Reputation: 1
Lightbulb 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!
 
Old 07-08-2011, 09:00 AM   #2
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux, LFS, Slitaz
Posts: 3,095
Blog Entries: 1

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

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

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

thanks buddy!
 
  


Reply


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 04:35 PM.

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