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

learn more… | top users | synonyms (1)

70
votes
6answers
19k 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 ...
65
votes
7answers
24k 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. ...
37
votes
6answers
1k views

Is there a downside to deleting all of the broken symbolic links in a system?

I was running a script that iterated over all the files on my Linux system and created some metadata about them, and it threw an error when it hit a broken symbolic link. I am newish to *nix, but I ...
29
votes
7answers
12k views

What is the difference between symbolic and hard links?

When would you use one over the other?
26
votes
2answers
2k 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. ...
25
votes
3answers
9k 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 ...
18
votes
4answers
12k 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?
18
votes
1answer
45k 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 ...
17
votes
3answers
30k 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 ...
15
votes
1answer
2k 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 ...
15
votes
5answers
12k 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 ...
15
votes
1answer
5k 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 ...
14
votes
1answer
2k 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 ...
14
votes
2answers
2k 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 ...
13
votes
2answers
1k views

What is the difference between 'rm' and 'unlink'?

Assuming you know the target is a symbolic link and not a file, is there any difference between using rm and unlink to remove the link?
12
votes
3answers
726 views

Determining if a file is a hard link or symbolic link?

I'm creating a shell script that would take a a filename/path to a file and determines if the file is a symbolic link or a hard link. The only thing is, I don't know how to see if they are a hard ...
12
votes
3answers
7k 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 ...
12
votes
2answers
9k 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, ...
12
votes
6answers
2k 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 ...
11
votes
3answers
11k 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 ...
11
votes
2answers
449 views

How to define a symbolic link that I can use in all of my directories

Is it possible to write a symbolic link such that no matter where am I on the file system, I can use for example project to point the directory home/me/project? I would like to use commands like cd ...
11
votes
1answer
4k 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 ...
10
votes
3answers
449 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?
10
votes
4answers
5k 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 ...
10
votes
4answers
1k 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
432 views

Strange difference between pwd and /bin/pwd

I added a symlink to the current directory with ln -s . aa. If I execute cd aa, and after that I executed pwd, the response is /home/sim/aa. But if I execute /bin/pwd it prints /home/sim (the current ...
10
votes
5answers
944 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
2answers
2k 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 ...
10
votes
2answers
2k 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
2answers
8k 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. ...
9
votes
1answer
138 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
2k 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 ...
8
votes
3answers
249 views

Going into a directory linked by a link

When I cd a link, my current path is prefixed with the link's path, rather than the path of the directory the link links to. E.g. ~/dirlinks/maths$ ls -l logic lrwxrwxrwx 1 tim tim 71 Jul 27 10:24 ...
8
votes
4answers
3k views

Changing the timestamp of a symlink

I know how to change the timestamp of a regular file: touch -t 201301291810 myfile.txt I was not able to do the same with a symlink. Is it possible? Distro: RHEL 5.8
8
votes
4answers
3k 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 ...
8
votes
2answers
2k 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

Java location from /usr/bin/java

I'm trying to find my java location within my Linux system and got this [980@b449 ~]$ which java /usr/bin/java [980@b449 ~]$ readlink -f $(which java) ...
8
votes
1answer
380 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
4answers
725 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
2answers
2k 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
1answer
3k 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 ...
7
votes
5answers
1k 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 ...
7
votes
2answers
125 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
153 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
3answers
152 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
434 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
4answers
4k views

Find only destination of symlink

For use in a shell-script, I'm looking for a commandline-way to get the destination of a symbolic link. The closest I've come so far is stat -N src, which outputs src -> dst. Of course I could ...
6
votes
4answers
8k views

List symlinks in current directory?

This question talks about finding directories in a current diretory. The solution is basically: ls -d */ That's great but how can I easily list symlinks? Do I have to use something like find . ...
6
votes
1answer
457 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 ...