I would like to transverse my home folder and list all symbolic links which point to element having Dropbox in their path. The following command (plus some post processing to remove additional field of info, but that should not be difficult) nearly accomplishes the task
ls -alR ~ | grep -e "->" | grep Dropbox
In the output of my ls
, the marker ->
precedes the path to the target of the symbolic link. In order to only get symbolic links pointing to something in Dropbox I pass the output through the final grep. However there is a problem: this way I only get the name of the symbolic link and not its full path. On the other hand using a command like:
ls -alR ~ | grep -e "->" | grep -E '(Dropbox|:)'
to keep the path listing of ls
(in recursive searches ls
first outputs the folder being listed followed by a colon) results in far too many hits. Any ideas?
ls
output if you have to deal with hostile file names (ones containing, for example,->
or newline or even blanks and tabs sometimes).{}
button above the edit box. (Rumours exist that control-K combination does it too; I've not used it.)ls -la | while read -r line1 && read -r line2; do cp /dev/null $'\n'"$line1"$'\n'"$line2"; done
. It works 'better' if you've got symlinks in the directory. It pretty much guarantees that naïve shell scripts will fail horribly.