I have 2 link directories in ~, ~/PathA (a git directory) and ~/PathB. The ~/PathA is a subdirectory of ~/PathB. Those two are linked to other physical disk. I linked a lot of files to file under ~/PathA/config/ in my ~. I want find out all those link files. show "xxxxx -> yyyyy" format.
This method is often used when we use configuration files from old/other machine.
If I write a script or use pipe, it is easy can do but something ugly. But I want if only use find command I can do it.
Edit: After test many time, I got it. The most important place is -lname and -print.
▶ find ~ -type l ! -path '/home/eexpss/磁盘' ! -path '/home/eexpss/bin' -lname '/home/eexpss/bin/config/*' -printf "%p -> %l\n"
/home/eexpss/.local/share/applications -> /home/eexpss/bin/config/.local+share+applications
/home/eexpss/.local/share/nautilus/scripts -> /home/eexpss/bin/config/.local+share+nautilus+scripts
/home/eexpss/.vimrc -> /home/eexpss/bin/config/fedora.vimrc
/home/eexpss/.proxy.pac -> /home/eexpss/bin/config/.proxy.pac
/home/eexpss/.bash_aliases -> /home/eexpss/bin/config/fedora.bash_aliases
/home/eexpss/.icons -> /home/eexpss/bin/config/.icons/
find: ‘/home/eexpss/磁盘/lost+found’: Permission denied
find: ‘/home/eexpss/磁盘/eexp/.gvfs’: Permission denied
/home/eexpss/.vim -> /home/eexpss/bin/config/.vim
/home/eexpss/.gitconfig -> /home/eexpss/bin/config/.gitconfig
I will accept Stéphane Chazelas' answer. thanks.
-lname '/home/eexpss/bin/config/*'
would not find relative symlinks that point inside~/bin/config
(like a/home/eexpss/x -> bin/config/x
or/home/eexpss/etc/x -> ../bin/config/x
), or those expressed as-> /home/eexpss/./bin/config/x
or/home/eexpss/x/y
wherex
is a symlink tobin/config
, etc. – Stéphane Chazelas Mar 27 '17 at 12:31$f
would be expanded by the shell to the content of the$f
shell variable. Possibly you meant%f
(file name without leading path components)? – Stéphane Chazelas Mar 27 '17 at 12:33