The following uses find
and would still search from the root directory down to the current directory, but would only look inside the directories on that single path:
find / -exec bash -c '[[ $PWD != "$1"* ]]' bash {} \; -prune -name foo -print
The first part of the command, up to the -prune
, will determine whether the current pathname being examined is located in the path of $PWD
. If it's not on the way to the current directory, it is pruned from the search path.
The comparison is carried out by a very short bash
script that simply tests whether the current directory, $PWD
, matches the start of the current pathname.
The bit after -prune
simply tries to match foo
against the filename that is being examined.
Example: Trying to find something called bin
somewhere in the directory structure above where I'm currently at.
$ pwd
/home/kk/local/build/ast/build/src/cmd/ksh93/sh
$ find / -exec bash -c '[[ $PWD != "$1"* ]]' bash {} \; -prune -name bin -print
/bin
/home/kk/local/bin
/home/kk/local/build/ast/bin
On systems without bash
, or where there is a faster-to-start sh
shell:
find / -exec sh -c 'case $PWD in ("$1"*) exit 1; esac' sh {} \; -prune -name bin -print
Does "allowed storage of the target path within the data structures used for storing file information on disk (inodes)" mean that a fast symlink stores the path of the linked file inside the inode of the fast symlink
Yes
Does a fast symlink, as a file itself, actually only have an inode and has no file content?
Depends what you mean by "has file content". No symlinks have file content in the sense that you cannot open()
them and read()
from them. But in the meaning implied by the text you quoted, "The file contained the textual reference to the link’s target". So, yes, that textual reference can be considered the file's "content".
This content is the same regardless of whether the symlink is a fast symlink or a slow symlink. How and where the filesystem choses to store that information in its on-disk data structures is an implementation detail and does not affect this.
Does a slow symlink, as a file itself, have an inode and some file content which is the target path?
From that same point of view, yes!
What does "if the target path exceeds the available inode space" mean?
Depends on the filesystem and the kind of data structures it used to store inodes and how much spare space is in those data structures and whether they are variable-sized or fixed size. The maximum length of the target path of a symlink before it has to fall back to being stored as a slow symlink is an filesystem implementation detail.
By the way, nothing prevents a particular filesystem from using the same trick to store the contents of a short regular file to save space and disk access.
Is there any command that can check if a symlink is a fast or slow one?
At best, filesystem debugging or dumping tools. And it will be completely dependent on the type of filesystem you are interested in (xfs, ext*, btrfs, etc...)
When a symlink has file content, what is the command to show the content of the symlink? (So that if a fast symlink doesn't have file content and a slow one has, we can verfiy that.)
You can obtain the target path (contents) of a symlink with readlink
, but ls -l
will work too.
Best Answer
You can use find to fetch all files of type symlink and add the
-ilname
option to search by name of the link destination. This works just like-iname
but for the link target name instead of the link name.That will still print out the name of the link, not the target. If you want to print the names of the targets, try this:
Or get a full
ls
style outputWhat you mean by "do something with the list" is unclear, but if you wanted to operate on the link files, you could use the
-exec
argument to find:But if you need to operate on the link targets, you will need to use the
-printf
to get the target values and thenxargs
or some loop yourself to operate. You could do something like this:... which also demonstrates how to use
grep
instead offind -ilname
to do your name matching, although you could do that either way.