Solved

unix delete the oldest file

Posted on 2008-06-09
5
383 Views
Last Modified: 2013-12-26
In unix environment need csh or ksh script that will mangae directory of files.  Only need the latest 10 log files, thus need script that removes the oldest file.
0
Comment
Question by:sdruss
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 21748612

ls -t|sed 1,10d|xargs rm -f

Open in new window

0
 
LVL 16

Accepted Solution

by:
Hanno Schröder earned 50 total points
ID: 21749248
Display all file ending on ".log", ordered with oldest last, filter out
all but the last one:
# ls -t *.log | tail -1
Now, use the command from above and take it's output as the
argument for remove command
# rm -f `ls -t *.log | tail -1`
0
 
LVL 1

Author Comment

by:sdruss
ID: 21801644
Great good stuff.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 21807060
The answer accepted doesn't match your request.
0
 
LVL 16

Expert Comment

by:Hanno Schröder
ID: 21811261
Tintin,
as far as I can see, he wanted to get "the oldest" file deleted.

Your solution deletes all but the first ten files. Your solution is
much more enhanced and quite elegant -- but unfortunately
seems a bit overcrafted for the original Q.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question