Looking for command line to find dirs based on size and date

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Looking for command line to find dirs based on size and date
# 1  
Old 03-10-2014
Looking for command line to find dirs based on size and date


My first time on this site, please excuse me if I've come to the wrong forum. I'm fairly new to Unix/Linux and hoping you can help me out.

I'm looking for a command line that will return a list of directories that are larger than 50M and older than 2 days.

I thought it may be something a simple as:
find /wlwork/epc_domain/stage/  -name 'job*' -type d -mtime +2 -size +50M

But that doesn't seem to work.

I had created 2 directories that are larger than 50M so it should have returned something.

I tried
du -sm /wlwork/epc_domain/stage/job* | awk '$1 > 50'

it returns directories that are larger than 50MB but I need to be able to delete the directories that are older than 2 days from this result.

Any suggestions?


Last edited by vbe; 03-10-2014 at 06:12 PM.. Reason: code tags
# 2  
Old 03-10-2014
Perhaps because the names of those 2 dirs dont start with "job"...
# 3  
Old 03-10-2014
I wish it were that easy.

There are several directories that begin with job in that path
# 4  
Old 03-10-2014
One way of doing this is using stat command:
du -sm /wlwork/epc_domain/stage/job* | while read size dir
        d_epoch=$( stat --printf=%Y "$dir" )
        c_epoch=$( date +%s )

        (( diff = ( c_epoch - d_epoch ) / 86400 ))

        if [ $diff -gt 2 ] && [ $size -gt 50 ]
                echo "Deleting dir: $dir"
                # Delete here

# 5  
Old 03-10-2014
If you created those 2 dirs. just now then it wont return anything due to the "-mtime +2" criterion...
# 6  
Old 03-10-2014
A directory is a file that contains several entries where each entry is an inode number and a name. Is is possible that a directory will get to be 50 MB but that would be a lot of entries. You probably mean the sum of the sizes of all the files and subdirectories in a directory. That is a different concept and has little to do with the size of the directory itself.
# 7  
Old 03-11-2014
Thanks for the replies.

Yes I meant the sum of all files and sub-directories in the directory.

We have instances where some of the directories (total sum) are very large due to logging etc. So to keep it clean, I was tasked with setting up a cron to clean up directories based on condition.

I'll keep plugging away Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Append each line based upon the character size

I have a huge file which contains multiple lines. It need to check whether character length is not more than 255 each line. If its not then it should remove the character up to column. I have described in the output below. If its more than that the next line should start with call but if the... (1 Reply)
Discussion started by: JoshvaPeter
1 Replies

2. UNIX for Beginners Questions & Answers

Cut each line based on the character size

Hello All, I have a file which contain below lines. The starting word of each line is call and the end line is semi colon. I need to find the character size of each line and then move it to a file. If the character size is more than 255 then I need to push that line to a next file and I need... (6 Replies)
Discussion started by: JoshvaPeter
6 Replies

3. HP-UX

HP/UX command to pull file name/date based on date

HI, Can anyone tell me how to pull the date and file name separated by a space using the find command or any other command. I want to look through several directories and based on a date timeframe (find -mtime -7), output the file name (without the path) and the date(in format mmddyyyy) to a... (2 Replies)
Discussion started by: lnemitz
2 Replies

4. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt 2012-06-15 08:13" ! -newermt 2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

5. Shell Programming and Scripting

Script to determine Date,TotalFile,total size of file based on date

I have file listed like below -rw-r--r--+ 1 test test 17M Nov 26 14:43 test1.gz -rw-r--r--+ 1 test test 0 Nov 26 14:44 test2.gz -rw-r--r--+ 1 test test 0 Nov 27 10:41 test3.gz -rw-r--r--+ 1 test test 244K Nov 27 10:41 test4.gz -rw-r--r--+ 1 test test 17M Nov 27 10:41 test5.gz I... (5 Replies)
Discussion started by: krish2014
5 Replies

6. HP-UX

find command to display size and date of a file

Hi, The blow code does not yeild any output. find . -name "*.jar" -o -name "*.ksh" -o -name "*.properties" -name "*.war" -o -name "*.ear" -o -name "*.sh" -o -name "*.cfg" -exec ls -l {} \; I wish to print the filename filesize filedate in HP-UX. Can anyone help ? (9 Replies)
Discussion started by: mohtashims
9 Replies

7. Shell Programming and Scripting

Find command and pruning .dirs

I'm sure this has been asked before but I couldn't find it with the search. I have a script that looks for files and then moves to another location for further processing. My problem is I can't seem to prune the .s* directories. It doesn't break anything just wanted a cleaner process. Here... (4 Replies)
Discussion started by: jcalisi
4 Replies

8. UNIX for Advanced & Expert Users

Find file size and date

Hi in my shell script I have to do this 1. there is a file called testing.txt in /home/report directory If the file size is 0(zero) and date is today's date, then I have to print "Successful" else "Failed". 2. There is a file called number.txt which will have text only one line like this... (10 Replies)
Discussion started by: gsusarla
10 Replies

9. Solaris

command to find out total size of a specific file size (spread over the server)

hi all, in my server there are some specific application files which are spread through out the server... these are spread in folders..sub-folders..chid folders... please help me, how can i find the total size of these specific files in the server... (3 Replies)
Discussion started by: abhinov
3 Replies

10. Shell Programming and Scripting

Traversing thru dirs and deleting files based on date

Hi Folks I am pretty new to unix and shellscripting. I need help on writing logic on traversing recursively through a set of directories under a top-level folder and delete files(mostly text) which are 1 month old. Can you people help me on this? Thanks a lot Ravi (5 Replies)
Discussion started by: ravi2082
5 Replies
Login or Register to Ask a Question