I want to find files in Linux that follow a certain pattern but I am not interested in symbolic links.
There doesn't seem to be an option to the find
command for that.
How shall I do ?
I want to find files in Linux that follow a certain pattern but I am not interested in symbolic links.
There doesn't seem to be an option to the find
command for that.
How shall I do ?
Check the man page again ;) It's:
find /path/to/files -type f
type f
searches for regular files only - excluding symbolic links.
-type f -xtype f
–
Condensed find
are you using? –
Descendant find (GNU findutils) 4.4.2
, here test case: echo >>asdf.txt;ln -s asdf.txt asdf.txt.lnk;find -type f;echo;find -type f -xtype f
–
Condensed ./asdf
which seems to prove that -type f
delivers the same results.. –
Descendant -type f
after the -name
, then find
will still return both regular files and symlinks; but if you specify -type f
before the -name
, then find
returns files only? E.g. find /path/to -name "*.so*" -type f
returns files and symlinks, and find /path/to -type f -name "*.so*"
returns files only. –
Corollaceous ! -type l
For example, if you want to search all regular files in /usr/bin, excluding symlink:
find /usr/bin/ \! -type l
! -type d
–
Chak Do you want it to follow symlinks but not return them (if they match your pattern)?
find -H
?
man find
...
-H Cause the file information and file type (see stat(2)) returned for each symbolic link specified on the command line to be those of
the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be
for the link itself. File information of all symbolic links not on the command line is that of the link itself.
-L Cause the file information and file type (see stat(2)) returned for each symbolic link to be those of the file referenced by the
link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself.
This option is equivalent to the deprecated -follow primary.
I have readed the MAN and now it seems is -P also, using -type r would raise an error. also notice is the DEFAULT behavior now.
-P Never follow symbolic links. This is the default behaviour. When find examines or prints information a file, and the file is a symbolic link, the information used shall be taken from the properties of the symbolic link itself.
Like @AquariusPower say, the use of find -type f -xtype f
solved my problem, and now I get only real files and not symbolic links anymore.
From: https://linux.die.net/man/1/find
I got:
-xtype
c
The same as-type
unless the file is a symbolic link. For symbolic links: if the-H
or-P
option was specified, true if the file is a link to a file of type c; if the-L
option has been given, true if c is 'l'. In other words, for symbolic links,-xtype
checks the type of the file that-type
does not check.
This works for me:
find -H . -maxdepth 1 -type f
Actually, don't really need the -H
© 2022 - 2024 — McMap. All rights reserved.
find
command inside ofbash
andshell
scripts -- Of which are, in fact, both programming and development. Also someone found the question useful -- As proven by the 94 (95 after mine) upvotes. – Disjoined