LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-06-2017, 03:55 AM   #16
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,718
Blog Entries: 4

Rep: Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959Reputation: 3959

Quote:
Originally Posted by prathamesh7478 View Post
Guys could you add your views and let me know

find . -type d -mtime +30 -name "1" -o -name "2" -o -name "3" -o -name "4"
You'll also need to review how boolean logic works and the order of precence for boolean operators. Remember that between each option in find there is an implied AND operator. So when mixing in some OR operators that needs to be taken into account, otherwise you will zap anything and everything in 2, 3, and 4 regardless of its age:

Code:
find . -type d -mtime +30 \( -name "1" -o -name "2" -o -name "3" -o -name "4" \) -print
But that might not get you what you want, if folders are empty. You might find the -mindepth and -daystart options useful.

Code:
find . -mindepth 2 -type d -daystart -mtime +30 \( -name "1" -o -name "2" -o -name "3" -o -name "4" \) -print
 
Old 02-06-2017, 07:00 AM   #17
prathamesh7478
Member
 
Registered: Feb 2013
Location: Pune
Distribution: Unix,Solaris,Ubuntu.
Posts: 35

Original Poster
Rep: Reputation: Disabled
Thanks Turbo for the help.

Its ending up deleting all the folders , I just tested need to do a bit research on your ans and would update you about my progress.

find . -type d -mtime +30 \( -name "1" -o -name "2" -o -name "3" -o -name "4" \) -delete
 
Old 02-06-2017, 08:04 AM   #18
prathamesh7478
Member
 
Registered: Feb 2013
Location: Pune
Distribution: Unix,Solaris,Ubuntu.
Posts: 35

Original Poster
Rep: Reputation: Disabled
Now my main problem here is it will go ahead and delete all the folders (1,2,3,4) now if it is showing that 4 and 3 are the oldest it should only delete 4 and 3 here I think would need to add some sort or heads here then check among 1234 which one is oldest and delete.


[root@localhost backup]# find . -type d -mtime -1 \( -name "1" -o -name "2" -o -name "3" -o -name "4" \) -print
./4
./3
./1
./2
[root@localhost backup]# find . -type d -mtime -1 \( -name "1" -o -name "2" -o -name "3" -o -name "4" \) -delete
[root@localhost backup]# ll
total 8
drwxr-xr-x 2 root root 4096 Feb 4 18:08 setup
[root@localhost backup]#
 
Old 02-06-2017, 08:08 AM   #19
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 23,991

Rep: Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889Reputation: 7889
did you try to combine it with post #12?
 
Old 02-06-2017, 08:33 AM   #20
prathamesh7478
Member
 
Registered: Feb 2013
Location: Pune
Distribution: Unix,Solaris,Ubuntu.
Posts: 35

Original Poster
Rep: Reputation: Disabled
This is my conditions , I have to combine both of this and reach to the final solution


[root@localhost backup]# find . -type d -exec stat --format '%Y :%y %n' "{}" \; | sort -n | awk '{print $5}' | head -2
./1
./2

[root@localhost backup]# find . -type d -mtime -1 \( -name "1" -o -name "2" -o -name "3" -o -name "4" \)
./4
./3
./1
./2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script for deleting the oldest directory within a directory kauuttt Linux - Newbie 6 07-14-2013 05:11 AM
Shell script to delete folders and files dynamically and recursively rjbaca Linux - General 1 06-21-2010 11:26 AM
Shell script/cmd to remove old folders in a directory? exxoid Linux - Newbie 1 03-29-2009 01:38 PM
shell script: delete all directories named directory.# except directory.N brian0918 Programming 3 07-13-2005 06:54 PM
Auto Delete oldest files @ratex when directory is 98% full jmanjohn61 Linux - Software 1 04-05-2005 03:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration