Hot answers tagged

11

You can't do this with a single invocation of ln,but you could loop through all necessary destinations: $ for i in "$HOME/Documents/" "$HOME/Desktop/"; do ln -s "$HOME/file" "$i"; done


6

If you have gnu parallel you could try with parallel ln -s /path/file {} ::: /path/dest1 /path/dest2 /path/dest3 or, to symlink multiple targets to (the same) multiple destinations parallel ln -s {1} {2} ::: /path/file1 /path/file2 ::: /path/dest1 /path/dest2


5

If you're using bash, zsh or any POSIX shell, then cd -P pwd -P or to make it permanent. in bash: set -P or set -o physical in zsh: set -w or set -o chaselinks in other POSIX shells: alias cd='cd -P' in tcsh: set symlinks = chase But the effect you're seeing is created by the shell, not by the link itself. So the answer to your actual question is "no"...


5

It's no less verbose than two separate ln -s invocations: echo $HOME/Documents/ $HOME/Desktop/ | xargs -n 1 ln -s $HOME/file but that only works for absolute paths (because symbolic links are interpreted relative to their parent directory, unless they're absolute). (The relative cost drops of course as the number of links goes up. Also, this snippet ...


4

There's no link from a file to symlinks that point to it, so there's no direct way of considering example and finding link_example which links to it. So deleting symlinks pointing to a file along with the file involves finding all the symlinks first. You don't specify what system you're using, but if you have GNU find, you can delete a file and its links ...


3

With GNU find, you can do: find -L / -xtype l -prune -samefile foo -exec ls -ld {} + That will find all the files of type symlinks which eventually resolve to the same file as foo. That will also include symlinks to symlinks or hardlinks to foo1. With -L, symlinks are followed. We want that to find files linked to foo, but we don't want to follow ...


3

If you don't have write permission in the parent directory, you can't make any changes in the parent directory; this includes deleting the target directory, and creating a symlink. In any case, ln won't overwrite a directory, even with -f.


3

Add the following line to your ~/.inputrc file: set mark-symlinked-directories on See "Readline Init File Syntax" in the Bash Reference Manual for more on this topic.


2

Two possible solutions that spring to mind. 1. Iterate across all the directories in LOREM and symlink them to $HOME cd "$HOME/LOREM" for item in * do test -d "$item" || continue mv -f "$HOME/$item" "$HOME/$item.DELETE_ME_LATER" 2>/dev/null ln -s "$HOME/LOREM/$item" "$HOME/$item" done # Once you are happy that only the correct files have ...


2

If you mean that you want to create symbolic links from $HOME/this, $HOME/there/that, $HOME/Data/ddd, etc. but not $HOME/Data or $HOME/somewhere/Labs, then the criteria for matching should be find "$HOME" ! \( -name Data -o -name Labs \) -exec … You were missing parentheses. Juxtaposition binds tighter than -o so -name Data -o name Labs -exec … executes ...


1

The filesystem on Mac OS X (HFS+) does not support hard links to symbolic links: $ touch file $ ls -l file -rw-r--r-- 1 kk staff 0 Jun 17 18:35 file $ ln -s file slink $ ls -l file slink -rw-r--r-- 1 kk staff 0 Jun 17 18:35 file lrwxr-xr-x 1 kk staff 4 Jun 17 18:36 slink -> file The following would ordinarily create a hard link to a symbolic link, and ...


1

In Bash you can do it by enabling the extglob option: $ shopt -s extglob #Enables extglob $ ls -l "$HOME"/!(Data|Labs|Documents) #Test run $ ln -s "$HOME"/!(Data|Labs|Documents) \ "$HOME"/Documents/ #Create symlinks $ shopt -s extglob #Disable extglob ...



Only top voted, non community-wiki answers of a minimum length are eligible