Small change. Requires cd'ing to the directory first and specifying . as the search location on the find command. Changed lines in bold:
Code:
#!/usr/bin/env ksh
# read table and generate find commands
# {Y|N} | filesystem | filelist
# provide filename of table as standard input e.g. test_script <table_name
# put rm on the command line as the first parameter to actually
# generate commands that delete files e.g. test_script rm <table_name
# if rm is not put on the command line, the default is to list what would be scratched.
awk -F "|" -v cmd="${1:-ls -l}" '
{
if( $1 == "Y" || $1 == "y" ) # if no-decend, add prune logic that skips directories
no_depth = sprintf( "\\( ! -name \".\" -type d -prune \\) -o" );
else
no_depth = ""; # ok to examine directories -- nothing extra needed
printf( "(cd %s; find . %s ", $2, no_depth ); # output first part of cmd
gsub( ",", " ", $3 ); # allow for pattern,pattern or pattern patern in the list
n = split( $3, a, " " ); # process each filename pattern
for( x = 1; x <= n; x++ )
printf( "-name \"%s\" -mtime +300", a[x] ); # add to command
printf( " -print | xargs %s)\n", cmd ); # finish the command
}
' | ksh # finally pipe to ksh to execute the commands
The last change was to add -mtime +300. I noticed that in order to test my script I had omitted that, but forgot to put it back in. Don't know if you picked up on that, but figured I'd point it out here. (Another reason I almost always list what will be deleted before turning the script loose to actually do the real work. Better to take some time to review than to be sorry.)
There are two things to be aware of if no files are older than 300 days. First, if running in list mode, it will list all of the files in the directory. You can prevent this with a small change:
Hi,
uname -a
SunOS mymac 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise
I need to tar a folder /tmp/moht but do not want these three folders to be included in the tar file -> savejpg, bmpsave and imgsave
I tried --exclude, -path, -not options but it says bad option
Can you help me with... (3 Replies)
Can you please help tweak the below command to exclude all directories with the name "logs" and "tmp"
find . -type f \( ! -name "*.tar*" ! -name "*.bkp*" \) -exec /usr/xpg4/bin/grep -i "user_1" /dev/null {} + >result.out
bash-3.2$ uname -a
SunOS mymac 5.10 Generic_150400-26 sun4v sparc sun4v... (9 Replies)
Hi, im having some issues after i execute the next command:
tar -cvf /varios/restore/test.tar -X /jfma/test1/excludefile /jfma | gzip -c > /varios/restore/test.tar.gz
this creates the desired "test.tar.gz" file, but whe i try to open it it says "tar: 0511-164 There is a media read or write... (6 Replies)
Hi all,
Using grep command, i want to find the pattern of text in all directories and sub-directories.
e.g: if i want to search for a pattern named "parmeter", i used the command
grep -i "param" ../*
is this correct? (1 Reply)
Hi,
Firstly - sorry for the duplicate my other post looked like i was posting a how to for people. But i am wanting some help :P
I want to search from / to find files and exclude my mounted ntfs drives.
I have found this thread (Which I can't post the URL to until i have 5 posts) it's... (4 Replies)
Hi,
I use find command to list all the files in a directory and its sub-directories, but the problem is to exclude certain directories during search. Can i give the directory names in command line to skip them and search rest of the directories?
For example i have directories:
test
../test1... (1 Reply)
Hi,
Can some one help me how to exclude multiple directories using find command..
I have the directory structure below.
/a/a1/b1
/a/c1/c2
/a/d1/d2/d3
I want to exlcude a1,c2and d3 from the above using find,can some one suggest pls..
thanks in advance...
Use code tags... (1 Reply)
Hello,
I have a line in my script to find the files changed in the last 24 hours. It is as below:
find /home/hary -type f -mtime -1
I now want to exclude a directory named "/home/hary/temp/cache" from the above find command. How do I add it to my script?
Any help is appreciated.
... (9 Replies)
Howdy
I have this directory structure ...
eep
eepaptest
eepfatest
eepgltest
eep.old
eeppoptest
ehf
ehfaptest
ehfgltest
ehp
ehpgltest
I want to find files in these directories, but I want to exclude eep, ehf & ehp.
Cany anyone help with the correct command ?? (1 Reply)