LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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: 75

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 systemd
Posts: 4,278

Rep: Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694Reputation: 1694
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: 75

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

thanks buddy!
 
  


Reply



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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:02 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration