1753758 Members
4982 Online
108799 Solutions
New Discussion юеВ

Re: Find command

 
SOLVED
Go to solution
Kumar_Chand
Occasional Contributor

Find command

Hi, I'm new to UNIX..
Could you please explain me what does the below find command execute?

find /home -xdev -type f -name core -exec ls -ld {}\;
2 REPLIES 2
Bill Hassell
Honored Contributor
Solution

Re: Find command

> find /home -xdev -type f -name core -exec ls -ld {}\;

This command looks through the /home directory (and sub-directories) looking for a file named "core" and if found, shows the file with an ls -d command.

Here are the details:
/home = starting directory
-xdev = do not cross any moutpoints within /home. A mountpoint could be an NFS mount from another system or another logical volume (lvol).
-type f = locate only ordinary files, not directories or symlinks, etc
-name core = match only files named "core"
-exec ls -ld = when a match is found run the command ls -ld on the file
{} = a placeholder where the filename would be required for ls -ld
\; = the exec option needs the command line terminated with either \; or +

The man page for find covers all these details.


Bill Hassell, sysadmin
Matti_Kurkela
Honored Contributor

Re: Find command

Add "echo" after -exec and it will just display the command lines it would execute, instead of actually executing them:

find /home -xdev -type f -name core -exec echo ls -ld {}\;

Your original command will go through /home and all the sub-directories of /home that are within the same filesystem (i.e. it will not cross mount points, because of the -xdev option).

It will look for regular files (option -type f) named "core" (option -name ...). For each file it finds, your command will run "ls -ld ".

For example, if the /home filesystem contains files /home/kchand/project1/core, /home/luser/core and /home/joe/very/deep/directory/structure/core, then find would run the following commands:

ls -ld /home/kchand/project1/core
ls -ld /home/luser/core
ls -ld /home/joe/very/deep/directory/structure/core

MK
MK