The UNIX and Linux Forums  

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
Auto copy for files from folder to folder upon instant writing Bashar UNIX for Advanced & Expert Users 2 08-21-2008 03:44 PM
Copying multiple folders to local machine (don't know folder names) leenyburger UNIX for Dummies Questions & Answers 5 06-12-2008 08:38 AM
Batch delete specific folder from user home directories nipodrom Shell Programming and Scripting 2 05-09-2008 07:22 AM
How can i delete files in folder by date? kobibn UNIX for Dummies Questions & Answers 9 10-25-2007 07:04 PM
delete files and folders older than 3 days melanie_pfefer Shell Programming and Scripting 7 12-18-2006 12:58 PM

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

Join Date: Nov 2006
Posts: 234
delete all folders/files and keep only the last 10 in a folder

Hi,

I want to write a script that deletes all folders and keep the last 10 recent folders.

I know the following:

ls -ltr will sort the folders from old to recent.
ls -ltr | awk '{print $9}' will list the folder names (with a blank line at the beginning)
I want to get the 10th folder from the bottom. HOW?
Once I get it, I can run: find . ! -newer <this_object> -exec rm {} \;

Thanks,

PS: Any other suggestion is appreciated
  #2 (permalink)  
Old 11-17-2006
dangral dangral is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2002
Posts: 699
Do a man on tail
  #3 (permalink)  
Old 11-17-2006
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
thanks

ls -ltr | awk '{print $9}' | tail -10 | head -1

will give the file. How to put it in the next command:
find . ! -newer <HERE> -exec rm {} \;

thx.
  #4 (permalink)  
Old 11-17-2006
melanie_pfefer melanie_pfefer is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 234
cd test
FILE0=`ls -ltr | awk '{print $9}' | tail -11 | head -1`
find . ! -newer $FILE0 -exec rm -r {} \;
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 07:32 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