The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Finding the oldest file in a particular directory pavan_movva Shell Programming and Scripting 4 04-08-2009 07:24 AM
Find Oldest file in a directory tree rahulrathod Shell Programming and Scripting 25 01-12-2009 12:45 PM
Removing a file from a directory npatel Filesystems, Disks and Memory 5 05-22-2008 10:47 AM
how to grep the oldest file in a directory ericaworld Shell Programming and Scripting 1 05-29-2007 01:24 PM
Oldest File In A Directory bergerj3 UNIX for Dummies Questions & Answers 2 02-27-2002 03:31 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-10-2006
pavan_movva pavan_movva is offline
Registered User
  
 

Join Date: Oct 2006
Location: India
Posts: 4
Removing the oldest file in a directory

Hi all,

I need your assistance in removing the oldest file in a directory.

I posted the same thread 3 days back and I got the following answer

Code:
ls -1 -t | tail -1 | xargs rm
which is not covering the case when there are directories older than the oldest file.

So, could you please provide an option so that the above command will exclude the directories in the search.

Thanks in advance for your help

Pavan
  #2 (permalink)  
Old 10-10-2006
anbu23 anbu23 is offline Forum Advisor  
Registered User
  
 

Join Date: Mar 2006
Location: Bangalore,India
Posts: 1,398
try this
Code:
ls -1 -lt | awk ' /^-/ { print $9}' | tail -1 | xargs rm
  #3 (permalink)  
Old 10-10-2006
pavan_movva pavan_movva is offline
Registered User
  
 

Join Date: Oct 2006
Location: India
Posts: 4
Thanks a lot anbu23 for your help!!

Regards

Pavan
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0