Solved

unix delete the oldest file

Posted on 2008-06-09
5
387 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 P.S. 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 P.S.
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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 how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

734 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