Hot answers tagged

43

It's not a bug. The use case is for when you want to link a file to the same basename but in a different directory: cd /tmp ln -s /etc/passwd ls -l passwd lrwxrwxrwx 1 xxx xxx 11 Jul 29 09:10 passwd -> /etc/passwd It's true that when you do this with a filename that is in the same directory it creates a link to itself which does not do a whole lot of ...


21

You're looking for test: -h pathname True if pathname resolves to a file that exists and is a symbolic link. False if pathname cannot be resolved, or if pathname resolves to a file that exists but is not a symbolic link. If the final component of pathname is a symlink, that symlink is not followed. Most shells have it as a builtin, but test also ...


17

Shell aliases have the feature that you can do (some) name-completion on them (usually bound to tab). Alternatively, you can use the CDPATH feature, which "recently" (within the past 5-6 years) has been improved to support name-completion. If that works for you, it has the advantage that the what you type is the actual name of the directory rather than a ...


16

For the directories you frequent often, but don't change daily, another option is just to have several alias commands in your .bashrc file: alias cdo="cd /u01/app/oracle" alias cdw="cd /var/www/html" A friend has about 50 of those; I have a handful; quick and easy. Just cdo to change directory to /u01/app/oracle


12

In this case, that's a Debian "alternative", so to get more details, you could use: $ update-alternatives --display gnome-text-editor gnome-text-editor - auto mode link best version is /usr/bin/gedit link currently points to /usr/bin/gedit link gnome-text-editor is /usr/bin/gnome-text-editor slave gnome-text-editor.1.gz is /usr/share/man/man1/gnome-...


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


10

You could use tab completion. By default on many Linux distributions, bash is set up so that when you hit the [TAB] key, you're given a list of possible matches, or if there's just one match, it's all filled out. For cd, this is normally a list of subdirectories of the current working directory. You could overwrite that, but I suggest instead making an alias,...


10

readlink is the command you are looking for. $ readlink -e /usr/bin/gnome-text-editor /usr/bin/gedit Various flags (-f, -e, -m) are available according to how you'd like to behave in case of broken links - see man readlink for details.


8

The easiest way to find out of course, is to try it and see. When no 2nd argument is given, ln will create a link in the current directory with the same name as the original: $ ln -s /etc $ ls -l lrwxrwxrwx 1 terdon terdon 4 Jul 29 16:09 etc -> /etc This is also explained in man ln: In the 2nd form, create a link to TARGET in the current ...


7

On a Linux system, when changing the ownership of a symbolic link using chown, by default it changes the target of the symbolic link (ie, whatever the symbolic link is pointing to). If you'd like to change ownership of the link itself, you need to use the -h option to chown: -h, --no-dereference affect each symbolic link instead of any referenced ...


6

I recommend pushd and popd. I personally do find them handy when doing development work / reading source code when multiple directories are involved. They effectively implement a stack structure/LIFO, where you pushd a directory, and the next popd command retrieves it. So, when inside a dir, you would do: pushd . And when you need to retrieve it, you ...


6

Symlinks Autodereferenced references to filenames A symlink is literally a text file that's treated specially by the kernel and whose contents is a path to another file/directory. You can read the contents of a symlink file with readlink, and if you standardly open a symlink file, the system will open the file/directory referenced by contents of the ...


6

Set the mark-symlinked-directories readline option. The usual way to do this is to edit ~/.inputrc, put set mark-symlinked-directories on in there, then start a new bash shell (or press Ctrl+X Ctrl+R to reload your readline settings). Less commonly, you could also put it straight in your ~/.bashrc like this bind 'set mark-symlinked-directories on'


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

Try using realpath: realpath --relative-to=/foo/bar/something /foo/hello/world For more examples, see: Convert absolute path into relative path given a current directory at SO


5

The command you ran created a symbolic link in the current directory. Judging by the prompt, the current directory is your home directory. Creating symbolic links to executable programs in your home directory is not particularly useful. When you type the name of a program, the shell looks for it in the directories listed in the PATH environment variable. To ...


5

$0 doesn't hold the name of the calling program but the name of the called program. The called program is ./my_command so $0 will be ./my_command too. The fact it is a symbolic link doesn't make a difference.


5

rsync -a --copy-unsafe-links src/ dest From the man page: --copy-unsafe-links This tells rsync to copy the referent of symbolic links that point outside the copied tree. Absolute symlinks are also treated like ordinary files, and so are any symlinks in the source path itself when --relative is used. This option has no ...


5

A file does not keep track of the symbolic links pointing to it. Instead, search for symbolic links under your tree and find out which file/dir they point to using readlink: find -type l -exec readlink -e -- "{}" \+ | sort | uniq Since find's default behavior is recursion, this will work for arbitrary depth.


5

Correct for a hard link but not for a symbolic link. The content of a symbolic link is just a string. This allows a symbolic link to point to a filesystem that isn't currently mounted, for instance. A symbolic link is just text; when the kernel encounters one, it essentially inserts the symbolic link into the path that it was looking up, breaking it up into ...


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 ...


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"...


4

You could do this, to supply tar with a list of all files inside protTests except those which are symlinks: find protTests -maxdepth 1 -mindepth 1 -not -type l -print0 | tar --null --files-from - -cvf protTests.tar By the way, your existing command: tar -cvf protTests.tar protTests/* will not archive all files in protTests, it will only archive ...


4

As you showed, system/nrcalc is a symlink on the local system, but it's a directory on the remote server. If the directory on the remote system is not empty, rsync will refuse to delete it (to make way for the symlink) unless you specify --force or one of the --delete options. If you don't want to replace the directory on the far end, but you still need to ...


4

The tilde character is expanded by the shell before the command is executed. It will be replaced by the value of $HOME. So the ln utility which creates the symlink will never see the tilde, only the full path. This path will be stored in the symlink. In Linux, there is no otion to make a symlink variable. They are handled by the kernel. The kernel does ...


4

For now, there's no way. Internally, stow find absolute canonical path of given path by using chdir to move into the path, then use getcwd() function from POSIX module, which is the Perl interface for POSIX getcwd(), to get the absolute path name. As POSIX specified, the path name shall contain no components that are . or .., or are symbolic links.


4

There are at least 2 mechanisms readily available in Linux (but probably not in cygwin). There is the fuse filesystem, see man fuse, which allows you to implement a filesystem in user-space. For example, curlftpfs (see its man page) converts file accesses into curl ftp calls. Then there is the fanotify system call, which allows you to intercept calls made ...


4

A symbolic link is just a reference to the actual file. There is no synchronization or something like that. If you look at the ls output for a symbuolic link you generally see something like: ls -l /bin/bzcmp lrwxrwxrwx 1 root root 6 jul 9 2014 /bin/bzcmp -> bzdiff As you can see the file /bin/bzcmp is just 6 bytes in size which happens to be ...


4

As you figured out, ln only replaced symlinks. Fixing this will involve at least reinstalling the packages which provide the missing symlinks... Using find's -L option combined with the -type l test allows broken symlinks to be identified; then dpkg -S will identify the corresponding package in most cases: dpkg -S $(find -L /usr/bin -type l) Filtering ...


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 ...



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