Results 1 to 7 of 7
hi, this is probably really easy for some people but I'm stuck trying to amend part of a script.
Code:
find $test/$DIR_TYPE/ ! -name 'ade*' -mtime +31 | sort | ...
- 09-18-2008 #1Just Joined!
- Join Date
- Sep 2008
- Posts
- 3
using 'find' for file names with either/or text string in them
hi, this is probably really easy for some people but I'm stuck trying to amend part of a script.
At the moment the above code looks in a certain directory for files with ade in the file name. I'd like to amend the script so that it looks for files that have 'ade*' and/or 'mtr*' in the file name. Can anyone point me at a good resource so that I can get this working?Code:find $test/$DIR_TYPE/ ! -name 'ade*' -mtime +31 | sort | xargs ls -l >>$LOGFILE
Cheers
- 09-18-2008 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
Code:find $test/$DIR_TYPE/ \( -name 'ade*' -o -name "mtr*" \) -mtime ....
- 09-19-2008 #3
Are you familiar with man pages? They are basically a manual for (just about) every command on your system. You can access them by typing "man COMMAND" from a terminal.
I suggest having a look at the find man page ("man find"), which explains how find works, and all of its options.DISTRO=Arch
Registered Linux User #388732
- 03-27-2009 #4Just Joined!
- Join Date
- Sep 2008
- Posts
- 3
hi again,
I have this command working which finds all files apart from those starting with av, mpt, or that have batch within the name, or those files that have been accessed in the last thirty days. This info is put into a list and outputted to a logfile;
Instead of outputting this data to a log file I would like to remove these files. I'm trying the code below but just can't work out the syntax as this command does not work.Code:find $lib/$DIR_TYPE/ \( \! -name "av*" \! -name "mpt*" \! -name "*batch*" -mtime +31 -type f \) | sort | xargs ls -l >>$LOGFILE
I have checked man find but can't see the answer. Any help would be great.Code:find $lib/$DIR_TYPE/ \( \! -name "av*" \! -name "mpt*" \! -name "*batch*" -mtime +31 -type f \) -exec rm -f {} \; >>$LOGFILE
Cheers
- 03-27-2009 #5
If your looking for a good utility to search files and file contents try GTKFind...Gerard4143
Make mine Arch Linux
- 03-27-2009 #6Just Joined!
- Join Date
- Sep 2008
- Posts
- 3
cheers dude. i will checkit out. however, i have the find part sorted out, i just can't apply the rm -f command properly.
- 03-30-2009 #7Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
I'd use the -print0 option with find to output the file names null terminated and pipe the results in to xargs using the -0 (zero) option so it recognises null as the terminator...
hthRHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.


Reply With Quote