Solved

how to use find command

Posted on 2011-02-27
4
376 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

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…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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