Solved

how to use find command

Posted on 2011-02-27
4
346 Views
Last Modified: 2012-05-11
If I'm logged in as root and change to the root directory the following command works as expected:
find -name myfile

If however I do:
find / -name myfile
it lists every directory on the drive.
This second option would be handy so I wouldn't have to switch to the root every time I want to search for a file.

Why does it do that and what should I type/
0
Comment
Question by:davidpm
4 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 34993713
You syntax is right but it may be possible there are multiple files with the same name

find / -name myfile

Its searching the whole system for any files named  myname and displayign their pathnames.  

You can be more specific about type of files by adding extension to file name or use grep to get only specific files you want
0
 
LVL 35

Accepted Solution

by:
torimar earned 250 total points
ID: 34993756
If you use the find command on the / root filesystem and you are not root, then the command usually will list all those folders that you cannot access for permissions issues - which will be all the folders on the system except the home folder of the user you are logged in as.

You could suppress the error messages by adding a redirection to your command:

find / -name myfile 2>/dev/null
0
 
LVL 10

Assisted Solution

by:APNFSSC
APNFSSC earned 250 total points
ID: 34993969
Hi,

Try this, the -type f tell's find to ignore directories and only list files.

find / -type f -name myfile
0
 

Author Closing Comment

by:davidpm
ID: 34994093
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now