Page 3 of 3 FirstFirst 123
Results 21 to 28 of 28

Thread: Linux Basics: A gentle introduction to 'find'

  1. #21
    Join Date
    Aug 2009
    Beans
    89

    Re: Linux Basics: A gentle introduction to 'find'

    Thanks, erind, for a clear and concise explanation. Tried both your examples and they both worked. Any reason to prefer one over the other?

  2. #22
    Join Date
    Dec 2009
    Beans
    167

    Re: Linux Basics: A gentle introduction to 'find'

    Although in this case the first option ("$@") is simpler, with arrays I've noticed an easier handling of individual tokens, as far as shell quoting is concerned. This quote from mywiki.wooledge.org nicely sums it up:

    Arrays are basically indexed lists of strings. They are very convenient for their ability to store multiple strings together without relying on a delimiter to split them apart (which is tedious when done correctly and error-prone when not).
    From: http://mywiki.wooledge.org/BashGuide/Parameters

  3. #23
    Join Date
    Jan 2012
    Beans
    73

    Re: Linux Basics: A gentle introduction to 'find'

    has anyone mentioned that there is a typo in the very first line? two within within's

  4. #24
    Join Date
    Jul 2009
    Location
    Islamabad / Rawalpindi
    Beans
    87
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Linux Basics: A gentle introduction to 'find'

    i am confused by the following part of that wiki
    It is important to get into the habit of quoting patterns in your search as seen above or your search results can be a little unpredictable. Such a search can be much more sophisticated though. For example if you wished to search for all of the ogg files in your home directory, some of which you think might be named 'OGG' rather than 'ogg', you would run:

    Code:
    find $HOME -iname '*.ogg'
    Here the option '-iname' performs a case-insensitive search while the wildcard character '*' matches any character, or number of characters, or zero characters.
    so in this particular case does it matters to use -name or -iname if we were to search for all files that are .ogg or .OGG ?

    i mean we are using the * doesnt that means 'anything' [case or type of char doesnt matter ?] or is the iname for the .ogg there to make that case insensitive ?

    thanks ... i would recomend this note/tip to be added to that great wiki..

  5. #25
    Join Date
    Apr 2011
    Location
    Maryland
    Beans
    1,461
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Linux Basics: A gentle introduction to 'find'

    The 'iname' bit allows the search to be case-insensitive (thus matching either 'ogg' or 'OGG'. The '*' operator allows any text that comes before the '.ogg' bit. The two are exclusive, though. Let's say you have two files called 'file.ogg' and 'file.OGG'. If you search by:

    Code:
    find $HOME -name '*.ogg'
    You'll only get 'file.ogg' as a result. If you use -iname, though, you'll get both files as a result, because now the search doesn't care about upper or lowercase file names. Does that make more sense?
    Last edited by drmrgd; August 9th, 2012 at 07:21 PM. Reason: lousy typos!

  6. #26
    Join Date
    Jul 2009
    Location
    Islamabad / Rawalpindi
    Beans
    87
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Linux Basics: A gentle introduction to 'find'

    ^^ thanks ... on first read i got the impression that it wont matter to use either iname or name and so were two of my collegues.. we were mistaken by the * .. whearas the .ogg is also a part of the search pattern..

    thanks again ..

  7. #27
    Join Date
    Aug 2012
    Beans
    104

    Re: Linux Basics: A gentle introduction to 'find'

    Quote Originally Posted by chickenPie4breakfast View Post
    has anyone mentioned that there is a typo in the very first line? two within within's
    I have corrected this small blunder .

  8. #28
    Join Date
    Feb 2010
    Location
    Cobourg
    Beans
    163

    Re: Linux Basics: A gentle introduction to 'find'

    I'm looking to be able to find a bunch of pdfs, move those pdfs to another directory, keep the directory structure, and remove the previous structures.
    So far I have been able to use the find command and copy the files while keeping the structure:

    find /home/john/books1/ -regex ".*\(pdf\|epub\|mobi\)$" -type f -exec cp '{}' /home/john/temp/ ';'

    but if I use mv I get all the files in one directory...

    find /home/john/books1/ -regex ".*\(pdf\|epub\|mobi\)$" -type f -exec mv -b '{}' /home/john/temp/ ';'


    Am I stuck using 'cp'? Which is fine, I just need to find a way to then delete them...

    find /home/john/books1/ -regex ".*\(pdf\|epub\|mobi\)$" -type f -exec rm '{}' /home/john/temp/ ';'

    I plan to also have this in a cron job but that shouldn't be a problem once I have figured out the script

    Thanks for any help


Page 3 of 3 FirstFirst 123

Tags for this Thread

Bookmarks

Posting Permissions

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