Looking for some help


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Looking for some help
# 1  
Old 06-21-2012
Question Looking for some help

Please direct me to the appropriate Forum if this is not the one.

Completely green amateur/noob here....

Can you tell me what the (complex?) command line would be for the following request in HPUX would be:

Identify all subfolders under a specified folder which meet the following criteria:
a) created within the last "x" days
b) the subfolder does not contain a file whose name includes "im_" OR alternatively if this is easier...the subfolders contain less than "y" bytes of data
# 2  
Old 06-21-2012
What OS are you on? Most flavors of UNIX do not have "created date" for either files or directories.
# 3  
Old 06-21-2012
HP-UX?

---------- Post updated at 09:56 AM ---------- Previous update was at 09:47 AM ----------

Playing around with commands as we speak and perhaps I should detail what I am looking to accomplish (my request may be barking up the wrong tree)...

What happens:
Files are placed into a newly created folder by an outside application.
These folders are always created within a "specified" directory.

Occassionally, this application generates the folder but fails to place the files into that folder

What I am seeking is a way to identify those folders which were created but failed to have those files placed into them.

The concept is to look for those folders (via manual command line) within a specified time frame by performing a search for any additional folders once a failure is identified.
# 4  
Old 06-21-2012
You have to use ctime - the last time the inode data for the directory was modified. This is usually the same as created time. The du command gives size of directory in kbytes (1024 bytes)

Code:
# x=[some number of days]
x=10
#  y=[some number of kbytes]
y=1024   # one MB
find /starting/directory  -ctime -${x} |
while read dirname
do
   sz=$( du -s $dirname | awk '{print $1}')
   if [ $sz -le $y ];  then
      echo "$dirname  $sz"
   fi
done

This User Gave Thanks to jim mcnamara For This Post:
# 5  
Old 06-21-2012
Brilliant!
Looking like a PRO...

I know a little bit about the du and ls commands but not enough

Thanks...

But where will this data output to? just on screen right?

.....I was trying the following single line command and was just going to sort the results myself:

find /ds100/default -mtime -1 -type d | xargs du -s *

where "ds100/default" is the directory I'm looking in
# 6  
Old 06-21-2012
Yes, that would just print to the terminal, but it's trivial to redirect it anywhere else.
Code:
...
done > output_file

Or just redirect the output of the script itself when you run it.

xargs and * are redundant here. xargs feeds arguments into the program it was given. These commands are equivalent for instance:

Code:
echo a b c | xargs cat
cat a b c

This User Gave Thanks to Corona688 For This Post:
# 7  
Old 06-21-2012
Thank you both (already clicked the button for each of you)

Here is a routine follow question to my command:

find /xx/yy -mtime -1 -type d | xargs du -s

how would I modify that command to give me the total size of all files/subdirectories within yy without breaking down each subdirectory

Assuming as a sample the directory contains the following subdirectories

xx/yy/z1
xx/yy/z1/a
xx/yy/z1/b
xx/yy/z2
xx/yy/z3

I simply want totals for each of z1 (and its subs), z2, and z3

basically looking for totals for each folders in the "third" level
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question