Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 396
  • Last Modified:

unix delete the oldest file

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
sdruss
Asked:
sdruss
  • 2
  • 2
1 Solution
 
TintinCommented:

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

Open in new window

0
 
Hanno P.S.IT Consultant and Infrastructure ArchitectCommented:
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
 
sdrussAuthor Commented:
Great good stuff.
0
 
TintinCommented:
The answer accepted doesn't match your request.
0
 
Hanno P.S.IT Consultant and Infrastructure ArchitectCommented:
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!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now