Solved

how to use find command

Posted on 2011-02-27
4
363 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Postfix issues with spam/auth attempts under NAT 9 112
number in printf 13 32
linux SFTP 8 61
Recover Lacie Edmini data. 11 55
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
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…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

860 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