Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-04-2010, 05:52 PM   #16
Registered: Aug 2010
Location: Brooklyn, NY
Distribution: CentOS
Posts: 38

Original Poster
Rep: Reputation: 0

can that be fixed with a Q?
ls -1tQ
Old 12-04-2010, 05:55 PM   #17
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390Reputation: 2390
Originally Posted by vbekker View Post
rm -rf $(ls -1t | tail -n +7)
As already stated by GrapefruiTgirl, this won't work with "special" files.

Try adding ls's -Q option (puts quotes around the filenames):
rm -rf $(ls -1Qt | tail -n +7)

Hope this helps.

And it seems I was a bit slow in replying ;-)

Last edited by druuna; 12-04-2010 at 05:55 PM. Reason: ... Way to slow.....
Old 12-04-2010, 05:56 PM   #18
LQ Guru
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
vbekker - I tried it, now you try it. Let us know how it works.
Old 12-04-2010, 10:13 PM   #19
LQ Guru
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899Reputation: 2899
Well I tried it too ... arooga arooga ... danger will robinson
Old 12-13-2010, 02:25 PM   #20
Registered: Apr 2007
Distribution: centos,rhel, solaris
Posts: 211

Rep: Reputation: 30
rm -rf $(ls -1t | tail -n +7)
hmm isn't supposed to be +8 to retain the items 1 to 7 and only 8 and upwards will be piped to the rm command?

looks like the 'Q' embeds quotation marks:

"file 1"
"file 2"

so what it does is:

rm -rf $"file 1" = but it doesn't delete anything....


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 files in a directory - RM MDeFreitas Linux - Newbie 3 06-25-2010 08:00 AM
sort files inside a directory and sub-directories by latest created walidaly Linux - Software 8 07-25-2009 03:45 PM
Delete Files in directory villumanati Linux - General 7 12-30-2008 02:18 PM
How to delete once whole files in a remote directory? backpacker Linux - Networking 1 03-10-2006 06:04 AM
How can I delete a directory and its files? OrganicX Linux - General 6 09-01-2002 05:25 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:09 AM.

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