How do I find a file?



  • To find a file you can limit the amount of searching find does by changing directory to area in the unix tree where you think the file may be, then run the find command find will continue until if finds every occurence of your search string, so you can press CTRL-C, if it has listed the file you were looking for, for example the following command looks for the cvs file under the directory /usr

    $ cd /usr
    $ find . -name cvs -print
    ./bin/cvs
    ...
    CTRL-C
    $
    

    A useful way of using find is listing the file via the ls command, here it looks for the file yppoll under /usr/sbin and runs a ls -l against it, using the xargs command, like this:

    $ find /usr/sbin -name yppoll -print | xargs ls -l
    -r-xr-xr-x 1 root root 13408 Feb 13 2006 /usr/sbin/yppoll
    

    The find command can perform complex searches, take a look at the man page for the full list of options

    To find a files beginning with "yp", do the following:

    $ find /usr/sbin -name 'yp*' -print
    /usr/sbin/ypserv_test
    /usr/sbin/ypset
    /usr/sbin/yppoll
    /usr/sbin/yptest
    

    Look for a string in many files, this looks for the word "boot" in the current directory, notice the single quotes and the spaces, it find on file called afile with the word boot in it, an important point is using "type" option of find, this command only looks in regular files only, specified by the "f" after type, otherwise if it comes across a binary file it will mess up your screen, mess up a technical term for changing your character terminal or window (pty) settings, and will display non ascii printable characters, if you do get this exit the terminal or window. Please note in this context terminal does not mean your monitor or screen, just the connection window into your Unix system

    $ find . -type f | xargs grep ' boot '
    ./afile: boot
    

Log in to reply
 

© Lightnetics 2024