Best SSH command to find files?

Discussion in 'Jailbreaks and iOS Hacks' started by -aggie-, Aug 21, 2010.

  1. -aggie- macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #1
    I know about locate and find, but when I use them on SSH, either I get an error or it just returns with nothing (even though I know the files are on my iPhone).

    I’ve used:

    find . -name filename.txt

    and nothing comes up.

    Using:

    locate filename.txt

    I get an error and nothing comes up.
     
  2. ulbador macrumors 68000

    ulbador

    Joined:
    Feb 11, 2010
    #2
    If you want to search the entire phone with that find command, you have to be at the device root

    cd /
     
  3. -aggie- thread starter macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #3
    I am.
     
  4. dgstan macrumors 6502a

    Joined:
    Jun 29, 2010
    #4
    Doesn't the "." after the find command mean "current directory"? What happens if you try it without the dot or use an "*" instead?
     
  5. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #5
    aggie,

    The "locate" command is not what you want.

    Try this:

    find / -name "Helvetica*"

    This recursively looks for and lists any file that starts with "Helvetica*" starting at the root directory.

    This command does the same from the current working directory:

    find . -name "Helvetica*"

    S-
     
  6. -aggie- thread starter macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #6
    Still doesn’t work. It just comes back with a new line; almost like it didn’t find the file. I even went to the directory where the file I am looking for is and tried the command and get nothing.


    Edit: Figured it out. I just needed the -print at the end. Now it searches in all directories at or below where I’m searching:

    find . -name "filename.*" -print

    Edit: @sidewinder: Didn’t notice you had replied. Yes, that works also. Thanks. I’m thinking it was that I didn’t have the filename in quotes and had nothing to do with the -print.
     
  7. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #7
    aggie,

    If you don't care or want to be case sensitive in the search use this command"

    find / -iname "helvetica*"

    Note: On my iPhone, I have not needed the "-print" option. But I am not sure if the standard "find" command needs it nor what "find" command I have on my iPhone. So you might need this command:

    find / -iname "helvetica*" -print

    Heck, if you want to count the number of matches, you could do this:

    find / -iname "helvetica*" -print | wc -l

    S-
     
  8. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #8
    aggie,

    Type "find --version" to get version.

    I have "GNU find version 4.2.33" on my iPhone.

    S-
     
  9. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #9
    I don't need the quotes. This command works just fine on my iPhone:

    find / -iname helvetica.ttf

    S-
     
  10. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #10
    I think I got that version of find from the "Find Utilities" (4.2.33-6). I didn't install these directly myself so I assume some app I installed had them as a dependency.

    S-
     
  11. -aggie- thread starter macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #11
    Yeah, it works now without quotes. Weird. I have the same GNU version.

    BTW, what is the difference between -iname and -name?
     
  12. -aggie- thread starter macrumors P6

    -aggie-

    Joined:
    Jun 19, 2009
    Location:
    Where bunnies are welcome.
    #12
    I went back to the original commands (by scrolling with the up arrow) I sent, and it worked. I have no idea why it didn’t work the first time.
     
  13. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #13
    See post #7....

    S-
     
  14. maturola macrumors 68040

    maturola

    Joined:
    Oct 29, 2007
    Location:
    Atlanta, GA
    #14
    I think the locate database doesn't update automatically, make sure to run "updatedb" command before a search ("locate -u" will do the same)
     
  15. pinter macrumors newbie

    Joined:
    Aug 14, 2010
    Location:
    Canada
    #15
    I use the locate command.

    - First update the database by "updatedb"
    - Wait until its done (20 seconds or so)
    - locate filename

    ie: locate root# locate cydia
    /private/etc/apt/sources.list.d/cydia.list
    etc ....

    Works like a charm for me.
     
  16. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #16
    There are a few issues with the "locate" command.

    The first is that the database takes up a decent amount of space. On my phone it uses almost 1MB. That doesn't sound like much but it all adds up.

    Second, you manually have to update the database.

    Third, the path cannot be constrained. In other words, it searches the entire db.

    The "find" command doesn't have these issues. Yes, it is slower than "locate", but not by much.

    S-
     

Share This Page