When I executed the command both commands gave the same output. I created a soft link and a hard link for a file but still both commands gave the same output. Is there a difference between
find -H and
find is not going to treat hard links specially
except insofar as the
-links test is concerned.
Symbolic links to files are going to be treated very similarly, too.
I would read the
find man page to you,
but I assume that you've already read it.
Man pages are written in a cryptic language
that is hard for beginners to understand.
An example would probably help. Do this:
$ mkdir dir1 dir2 dir3 $ touch dir1/file1 dir2/file2 dir3/file3 $ ln -s dir2 two $ cd dir1 $ ln -s ../dir3 three $ cd .. $ ls -lR # I have deleted my user name from the below. .: total 1 drwxr-xr-x 1 0 Sep 4 13:08 dir1 drwxr-xr-x 1 0 Sep 4 13:08 dir2 drwxr-xr-x 1 0 Sep 4 13:08 dir3 lrwxrwxrwx 1 4 Sep 4 13:08 two -> dir2 ./dir1: total 1 -rw-r--r-- 1 0 Sep 4 13:08 file1 lrwxrwxrwx 1 7 Sep 4 13:08 three -> ../dir3 ./dir2: total 0 -rw-r--r-- 1 0 Sep 4 13:08 file2 ./dir3: total 0 -rw-r--r-- 1 0 Sep 4 13:08 file3 $ find dir1 two dir1 dir1/file1 dir1/three two $ find -P dir1 two # This is the default; i.e., same as the above. dir1 dir1/file1 dir1/three two $ find -H dir1 two dir1 dir1/file1 dir1/three two two/file2 $ find -L dir1 two dir1 dir1/file1 dir1/three dir1/three/file3 two two/file2
- In the default behavior (i.e., the
finddoes not follow either symbolic link.
two(in the top-level directory) and
dir1/threeare simply reported as objects.
-H, the symbolic link
dir2is followed (i.e., we get to see
file2, which is in
twois specified on the
findcommand line. Note that
dir1/threeis still reported as an object.
-L, both symbolic links are followed. We get to see
file2, because the
dir2link is followed, and we get to see
file3, because the
../dir3link is followed.
If it's not perfectly clear to you now,
try running the
find commands in my example with
-ls at the end
(as an alternative to the default
three are listed.
You will notice that symbolic links to files
are also reported differently under the different options.
Here's another example:
$ ln -s /bin/sh mysh $ find . -size +9 $ find -H . -size +9 $ find -L . -size +9 ./mysh
The symbolic link
./mysh is small.
It points to
/bin/sh, which is a fairly large file.
./mysh is treated as being small under
-P (default) and
but it is treated as being large under
-L means "look at the file that the link points to".
Yet another example:
find . -type f(and
find -H . -type f) will find plain files only.
find . "(" -type f -o -type l ")"will find plain files and (all) symbolic links.
find -L . -type fwill find plain files and symbolic links that point to plain files. (Also, if the directory tree contains any symbolic links to directories, those directories will also be searched.)