Find the answer to your Linux question:
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 | ...
  1. #1
    Just 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.

    Code:
    find $test/$DIR_TYPE/ ! -name 'ade*' -mtime +31 | sort | xargs ls -l >>$LOGFILE
    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?

    Cheers

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    Code:
    find $test/$DIR_TYPE/  \( -name 'ade*' -o -name "mtr*" \) -mtime ....

  3. #3
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    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

  4. #4
    Just 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;

    Code:
    find $lib/$DIR_TYPE/ \( \! -name "av*" \! -name "mpt*" \! -name "*batch*" -mtime +31 -type f \) | sort | xargs ls -l >>$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 \) -exec rm -f {} \; >>$LOGFILE
    I have checked man find but can't see the answer. Any help would be great.

    Cheers

  5. #5
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    If your looking for a good utility to search files and file contents try GTKFind...Gerard4143
    Make mine Arch Linux

  6. #6
    Just 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.

  7. #7
    Linux 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...

    hth
    RHCE #100-015-395
    Please don't PM me with questions as no reply may offend, that's what the forums are for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...