A special type of file that references a file or directory.

learn more… | top users | synonyms (1)

50
votes
3answers
13k views

Why hard links not allowed to directories in UNIX/Linux

I read in text books that UNIX/Linux doesn't allows hard links to directories but soft links do. Is it because, when we have cycles and if we create hardlinks, and after some time we delete the ...
43
votes
6answers
11k views

How can I find broken symlinks

Is there a way to find all symbolic links that don't point anywere? find ./ -type l will give me all symbolic links, but makes no distinction between links that go somewhere and links that don't. ...
27
votes
7answers
8k views

What is the difference between symbolic and hard links?

When would you use one over the other?
23
votes
3answers
6k views

How can I “relink” a lot of broken symlinks?

I have a directory tree which has a bunch of symbolic links to files under /home... however, I have moved /home to /mnt/home and need a way to "relink" all of the symlinks. Does such functionality ...
21
votes
2answers
855 views

Symbolic link recursion - what makes it “reset”?

I wrote a little bash script to see what happens when I keep following a symbolic link that points to the same directory. I was expecting it to either make a very long working directory, or to crash. ...
14
votes
1answer
1k views

What does ln stand for?

In Linux you can use the ln command to make links. $ touch foo $ ln -s foo foo_link $ ls -l lrwxrwxrwx 1 cklein cklein 3 May 29 16:11 foo_link -> foo I assume that the 'l' in ln stands ...
13
votes
1answer
1k views

Why are reboot, shutdown and poweroff symlinks to systemctl?

In Arch Linux, if I do ls -l in /sbin, I can see that reboot, shutdown and poweroff are all symlinks to /usr/bin/systemctl. But issuing reboot, shutdown and systemctl commands obviously does not all ...
13
votes
2answers
1k views

pwd without symlinks

If I do pwd I notice it uses whatever symlinks I used to get into the current directory. Can I get it to tell me the "real" directory I'm in ... i.e. the path from the root to my current directory ...
12
votes
4answers
7k views

Converting relative path to absolute path

Is there a *nix command to get absolute(and canonicalized) path from relative path(with current path) or symbolic link?
12
votes
2answers
6k views

Do symbolic links actually make a difference in disk usage?

I've read in so many websites that, in Linux, symbolic links (soft links, symlinks) are just like pointers that reference another file, which may be located anywhere (like Windows shortcuts). However, ...
11
votes
3answers
4k views

How can I remove all symbolic links with a special target?

With the command: ls -la * I can list all my symbolic links. How can I remove all symbolic links which are linked to a special folder? For example: In my directory usr/local/bin I have the ...
11
votes
3answers
18k views

How to get full path of original file of a soft symbolic link?

I want to scp a file to a server. The file is a symbolic link, and actually what I want to do is copying the source file. Anyway I don't want to track source file's path manually, because it can be ...
10
votes
5answers
340 views

Is there an algorithm to decide if a symlink loops?

Unix systems usually just error out if they are confronted with a path that contains a symlink loop or just too many symlinks, because they have a limit to the number of symlinks they will traverse in ...
10
votes
4answers
778 views

Include / in symlink to a directory?

Symlinking to a directory gives to different results with ls -l depending on whether I ln -s dir or ln -s dir/. But what's the actual difference, and which one should I prefer why?
10
votes
2answers
319 views

Convert absolute symlink to relative symlink with simple Linux command

I have a complete sub-filesystem inside a path /home/user/system containing the standard Linux structure with directories /bin, /home, /root, /usr, /var, /etc,... This sub-filesystem contain symbolic ...
9
votes
4answers
3k views

symbolic link to a directory and relative path

I've created symlink with absolute path to the directory (Blink) and have for example following tree: $ ls -l /tmp/A total 0 lrwxrwxrwx 1 root root 6 Apr 3 12:27 Blink -> /tmp/B -rw-r--r-- 1 root ...
9
votes
4answers
7k views

Make a symbolic link to a relative pathname

I can do this: $ pwd /home/beau $ ln -s /home/beau/foo/bar.txt /home/beau/bar.txt $ readlink -f bar.txt /home/beau/foo/bar.txt But I'd like to be able to do this: $ pwd /home/beau $ cd foo $ ln -s ...
9
votes
1answer
2k views

Create a symbolic link relative to the current directory

I'm trying to create a symbolic link in my home directory that points to a directory on my external HDD. It works fine when I specify it like this: cd ~ ln -s /run/media/name/exhdd/Data/ Data ...
9
votes
1answer
3k views

Make cd follow symbolic links

I have my code mounted as an sshfs in my home directory, but the hierarchy is difficult to remember, so I created a symlink in my home directory leading to that directory. Is there a way so that when ...
9
votes
1answer
128 views

Strategies for maintaining a reference to a file after it was moved or renamed?

I've had a mac at work lately, and was amazed to see that Xcode would still find my latest project after I renamed its folder and moved it someplace else. Now I understand that this is the result of ...
8
votes
3answers
363 views

Symlink to part of the file?

Is there possible to create file that is just a sub-sequence of bytes from another file, like a symlink, but referencing only part of the file?
8
votes
2answers
898 views

find usage with -L

I have link -> file I do find -L . -name 'link' And get ./link Why is that? man find says: -L : Follow symbolic links. When find examines or prints information about files, ...
8
votes
2answers
1k views

mv a file without breaking a symlink to that file

Is it possible to mv a file w/out breaking a symbolic link to that file? My initial response to this is no, and I'm working out a script based solution to change the links immediately following the ...
7
votes
3answers
7k views

Are there any drawbacks from using mount --bind as a substitute for symbolic links?

Symlinks have limitations in how functions like ls, mv, and cp can operate on them because unlike shell initiated commands like cd, these functions do not have information about how the user accessed ...
7
votes
4answers
527 views

Linking /proc/mnt to /proc/mounts

I understand that /proc filesystem reflects the output of various processes. Unfortunately, I have a propietary (romdump) binary that expects the mount table to appear as /proc/mtd, while my Android ...
7
votes
2answers
1k views

Providing /bin and /lib inside a chroot jail

I need to be able to provide the /bin and /lib directories inside a chroot jail so that programs can dynamically link properly. Is there a way to accomplish this without making a copy of the /bin and ...
7
votes
1answer
2k views

How can I access a directory outside a chroot from within it?

I have a user which is chrooted to her home directory, but I want her to also be able to manage files within /var/www. As such, I did the following: root@server:/home/username# ln -s /var/www www ...
7
votes
4answers
2k views

How does one atomically change a symlink to a directory in busybox?

I am trying to (as close as possibly) atomically change a symlink. I've tried: ln -sf other_dir existing_symlink That just put the new symlink in the directory that existing_symlink pointed to. ln ...
7
votes
2answers
1k views

Is a symbolic/soft link similar to a shortcut/alias on a desktop?

It sounds to me like the basic idea of soft/symbolic links compared to shortcuts (on a PC) or aliases (on a Mac) are the same thing. Am I way off? Are they similar?
7
votes
2answers
4k views

How to create backup from symbolic links?

I have a directory with symbolic links to other directories. I want to archive the symbolic links, not as links but as archives containing the files of directories they refer to, using tar command. ...
7
votes
2answers
108 views

Why is there a mix of symlinks and hardlinks in /bin?

I understand the technical difference between symlinks and hardlinks, this is a question about their use in practice, particularly I'm curious to know why both are used in seemingly similar ...
7
votes
1answer
89 views

Can you change a dynamic link target without recompiling?

I downloaded a program that unfortunately doesn't come as a source distribution. When I go to run it, I get the error error while loading shared libraries: libjpeg.so.62: cannot open shared object ...
7
votes
1answer
309 views

Is there a way to make perl -i not clobber symlinks?

A friend of mine points out that if you do: perl -pi.bak -e 's/foo/bar/' somefile when "somefile" is actually a symlink, perl does just what the docs say it will do: It does this by renaming ...
7
votes
3answers
85 views

How can I find out if a relative symlink is internal to a certain subtree or not?

I want to test if a relative symlink points within the subtree of a certain directory. This example would yield false since it points outside the foo directory: /foo>readlink bar ../fie.txt While ...
7
votes
2answers
320 views

Git do not overwrite symlinked directory on branch checkout

How can I make directory read-only with git? The situation is - in project, I have a symlink to shared framework. I don't want it to be overwritten/changed in any way (not even mtime or atime). How ...
6
votes
3answers
1k views

How to make a symbolic link to /usr/bin/vim but with start-up parameters?

After I make&make install vim from source, I found many symbolic links of vim in /usr/local/bin, such as evim, rvim, view... The vim(1) man page said that "rvim" is equivalent to "vim -Z" and so ...
6
votes
1answer
419 views

Why do some symbolic links affect program behavior?

One thing that has been puzzling me for some time is this: % which halt /sbin/halt % file /sbin/halt /sbin/halt: symbolic link to `reboot' However, executing sudo halt does, of course, not reboot ...
6
votes
2answers
4k views

Why change the owner of a symbolic link in linux?

In linux it's possible to change the owner or the group owner of a symbolic link (symlink). I was wondering why someone would want to do that, since permissions of a symlink are not used when ...
6
votes
5answers
936 views

Dynamic Symlinks

I have built my app for different architectures and would like to create a "dynamic symlink" which takes me to the right version based on a variable. If the machine I am currently logged in to, is ...
6
votes
4answers
1k views

Is there a standard symbolic link to the current users home directory?

The shell can expand ~ to your home directory. $HOME usually has the same deal, but often you want to refer to the current users home directory from a context that may not support such expansion. I ...
6
votes
1answer
279 views

Why wouldn't a symlink to a symlink work?

I've run into a weird issue when installing SWI-Prolog using homebrew on my OSX 10.9 box. I'm trying to debug it to figure out whose bug it is (SWI-Prolog's, homebrew's, or OSX's), so I can report it ...
6
votes
2answers
550 views

Find files that were not installed by the package manager

I'd like to get a list of all files in my Gentoo Linux system that were not installed by the package manager (Portage). This is because I want to keep my system as clean as possible, removing all ...
5
votes
2answers
302 views

Why do hard links seem to take the same space as the originals?

Thanks to some good Q&A around here and this page, I now understand links. I see hard links refer the same inode by a different name, and copies are different "nodes, with different names. Plus ...
5
votes
3answers
188 views

Getting relative links between two paths

Say I have two paths: <source_path> and <target_path>. I would like my shell (zsh) to automatically find out if there is a way to represent <target_path> from <source_path> as ...
5
votes
1answer
2k views

Symbolic link permissions

I have access to a remote Linux machine where everytime I create a symbolic link, it is created by default with the following permissions: lrwxrwxrwx If I try to change the permissions of the ...
5
votes
3answers
175 views

How to ls using the long format (-l) while still following directory symlinks?

I've noticed that ls -l doesn't only change the formatting of the output, but also how directory symlinks are handled: > ls /rmn biweekly.sh daily.sh logs ... > ls -l /rmn lrwxrwxrwx 1 root ...
5
votes
1answer
1k views

list files by symlink target

How do I get list of files (and then do something with that list) by filtering through the symbolic link target name, and not the symlink name? For example from the following list I'm only interested ...
5
votes
4answers
468 views

Portable way to get script's absolute path?

What is a portable way for a (zsh) script to determine its absolute path? On Linux I use something like mypath=$(readlink -f $0) ...but this is not portable. (E.g., readlink on darwin does not ...
5
votes
2answers
5k views

How do I copy a symbolic link?

I have a symbolic link to a file in one directory. I would like to have that same link in another directory. How do I copy a symbolic link? I tried to cp the symbolic link but this copies the file ...
5
votes
1answer
288 views

How to replace a symbolic link with an equivalent hard link?

Having a (single, no batch filesystem processing needed) symlink, what a command line to use to turn it into a hard link to the same file?