Delete old version folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete old version folder
# 8  
Old 06-23-2010
Code:
 ls -d 1.* |egrep -v "$(ls -ld Current | awk '{print $NF}' )|$(ls -d 1.* | sort -nt. | tail -1)" | xargs rm -rf


Last edited by Scrutinizer; 06-23-2010 at 02:12 PM..
# 9  
Old 06-28-2010
Sorry Something cropped up and I did not check my emails.

are you saying your current link is already pointing to the latest version?

if so you can try this:
Code:
ls | grep -v Current | sort | sed '$d' | xargs rm -rf

If not, you can try this:

Code:
ls | grep -v Current | grep -v `ls -l Current | awk '{print $NF}'` | sort | sed '$d' | xargs rm -rf

Sorry for the double grep -v. Maybe someone can help to combine them..

---------- Post updated at 01:28 PM ---------- Previous update was at 01:09 PM ----------

Quote:
Originally Posted by Scrutinizer
Try:
Code:
ls -d 1.* | sort -nt. | sed '$d' | xargs rm -rf

Note that this will not work with names that contain spaces..

@Leion, dr.house I think xargs got mixed up with find syntax a bit there, no?

For directory names with spaces one could use this:
Code:
ls -d 1.* | sort -nt. | sed '$d' |  while read line; do rm -rf "$line"; done


oh yar thanks for pointing out the syntax part Smilie

Last edited by Leion; 06-28-2010 at 02:27 AM.. Reason: Change current to Current
# 10  
Old 06-28-2010
Quote:
Originally Posted by Leion
Maybe someone can help to combine them..
You could combine like so for instance:
Code:
ls | egrep -v "Current$|$(ls -l Current | awk '{print $NF}')$"

The $ character is important to make sure that the patterns the grep matches are at the end of the line.
This User Gave Thanks to Scrutinizer For This Post:
# 11  
Old 06-28-2010
Quote:
Originally Posted by Scrutinizer
You could combine like so for instance:
Code:
ls | egrep -v "Current$|$(ls -l Current | awk '{print $NF}')$"

The $ character is important to make sure that the patterns the grep matches are at the end of the line.

The Current$ does not work for me as I used a alias to do a
Code:
ls -F

Code:
leion > ls -ltr
total 0
   0 lrwxrwxrwx   1 leion  group         8 Jun 28 17:33 Current -> 1.0.0.12
   0 -rw-r--r--   1 leion  group         0 Jun 28 17:33 1.0.0.13a
   0 -rw-r--r--   1 leion  group         0 Jun 28 17:33 1.0.0.13
   0 -rw-r--r--   1 leion  group         0 Jun 28 17:33 1.0.0.12
   0 -rw-r--r--   1 leion  group         0 Jun 28 17:33 1.0.0.11
leion > ls | egrep -v "Current$|$(ls -l Current | awk '{print $NF}')$"
1.0.0.11
1.0.0.13
1.0.0.13a
Current@
leion > ls | egrep -v "Current|$(ls -l Current | awk '{print $NF}')$"
1.0.0.11
1.0.0.13
1.0.0.13a

However the combine of my twin grep -v using egrep -v helps.
Thank you for sharing. Smilie
# 12  
Old 06-28-2010
Hi, you're welcome...
To temporarily bypass an alias you can use a backslash:
Code:
\ls | egrep -v "Current$|$(ls -l Current | awk '{print $NF}')$"

# 13  
Old 06-28-2010
Quote:
Originally Posted by Scrutinizer
Hi, you're welcome...
To temporarily bypass an alias you can use a backslash:
Code:
\ls | egrep -v "Current$|$(ls -l Current | awk '{print $NF}')$"


Nice! Smilie
Learnt another thing from you today
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete oldest folder based on folder named as date

Hi, I have a script doing backup to synology server, the script create new folder each day with the date as being folder name i.e. 2018-07-30. Just before creating the new folder I want the script to find the oldest folder from the list and delete it including its content. for example... (3 Replies)
Discussion started by: humble_learner
3 Replies

2. Shell Programming and Scripting

Request for Shell script to move files from Subfolder to Parent folder and delete sub folder

Hi Team, I am new to shell script and there is a requirement where files should be moved from Subfolder to parent folder. Eg: parent folder --> /Interface/data/test/IN Sub folder -->/Interface/data/test/IN/Invoice20180607233338 Subfolder will be always with timestamp... (6 Replies)
Discussion started by: srivarun15
6 Replies

3. Shell Programming and Scripting

How to delete other's folders which are in our own folder?

Hi All, I need a solution for the following scenario. I am the owner for the particular folder and I have given 777 permissions for some specific reasons. So others can able to create folders and files. But when I am done with the work, I need to delete the folders which are created by... (4 Replies)
Discussion started by: manoj_thorali
4 Replies

4. Shell Programming and Scripting

Delete folder in a directory which are two months old

I need help. I have to create a script which will delete multiple directory (folders) that are two months old. Example, I have folders dated April, May, June and July. I have to delete folders April and May and retain June and July and as such that when the July month lapse, the folder June will be... (2 Replies)
Discussion started by: jasperux
2 Replies

5. UNIX for Dummies Questions & Answers

Getting a process/program version from /proc folder

Hello I am writing a script that will first execute ps to get the list of processes running, and the go into the /proc folder for each PID listed and gather relevant information. I looked through the contents of a particular process in the /proc folder and I can't find where I can locate... (2 Replies)
Discussion started by: flagman5
2 Replies

6. Shell Programming and Scripting

Folder permissions to delete

I am using the below command to delete files from directories and subdirectories find /test/abc/xyx -type f -mtime +7 -exec rm -f {} \; there are some subfolders in xyx for which i don't have permission to delete. Is there a way i can check the permission of the folder first and then delete... (4 Replies)
Discussion started by: ch33ry
4 Replies

7. Shell Programming and Scripting

Auto delete the folder

Hi, i have the directory structure directory /home/ncs/controller/logs/ in this path i have following directories cl03032010 cl04032010 cl05032010 cl06042010 i want to delete the folders which are 2 weeks old.. through the crontab (2 Replies)
Discussion started by: mail2sant
2 Replies

8. UNIX for Dummies Questions & Answers

Delete file from folder

Hi all, I amd new in UNIX programming. I have a query. I need to delete some files (like .dec files) from some folders. I have a list of folders. What will be command for it. Please help me. Thanks in Advance. (6 Replies)
Discussion started by: eclairs
6 Replies

9. Shell Programming and Scripting

delete all the files in folder a which exist in folder b

Hi , I need a script which basically deltes all files in folder a which are alreasy present in folder b say folder a has files abc.txt pqr .txt and b has abc.txt pqr.txt rmr.txt then file abc.txt and pqr.txt from a should be deleted (6 Replies)
Discussion started by: viv1
6 Replies

10. UNIX for Dummies Questions & Answers

How can i delete files in folder by date?

Hi, I have some files on a folder and i want to delete all the files that were created on July. Thanks, Kobi. (9 Replies)
Discussion started by: kobibn
9 Replies
Login or Register to Ask a Question