Questions tagged [symlink]

A special type of file that references an inexistent or existing file or directory. The contents of a symbolic link consist of an arbitrary string that is the path to the file that the symbolic link points to. When the symlink is encountered during pathname resolution, the string stored by the file is used to modify the pathname resolution.

A special type of file that references an inexistent or existing file or directory. The contents of a symbolic link consist of an arbitrary string that is the path to the file that the symbolic link points to. When the symlink is encountered during pathname resolution, the string stored by the file is used to modify the pathname resolution.

The ln command with the -s flag is typically used to create symbolic links. The actual contents of the symbolic link can be examined using the readlink command.

1157 questions
97
votes
8 answers

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 bar.txt /home/beau/bar.txt $ readlink -f…
76
votes
2 answers

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 without the use of any symlinks?
JoelFan
  • 1,329
52
votes
6 answers

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 get the main idea behind linking files and how…
42
votes
4 answers

How to find all symbolic links pointing to any file/directory inside a given directory

On this question or on this one (for example) you will get solutions on how to look for symlinks pointing to a given directory (let's call it /dir1), while I am interested to symbolic links possibly pointing to any file/folder inside /dir1. I want…
Antonello
  • 1,023
41
votes
5 answers

Finding the original file of a symbolic link

So let's say I have a symbolic link of a file in my home directory to another file on a different partition. How would I find the target location of the linked file? By this, I mean, let's say I have file2 in /home/user/; but it's a symbolic link to…
k-Rocker
  • 1,415
15
votes
2 answers

Is symlink's target relative to the destination's parent directory and if so, why?

I've got the following file structure: build/ client/ –> index.js And when I try to create a symbolic link named "client" inside the build directory that refers to the client directory in the cwd like so // Fails $ pwd /home/user/ $ ln -s client…
jibsales
  • 285
14
votes
2 answers

Can I setup a symlink to the most recent folder?

I have some directories: drwxr-xr-x 10 shamoon staff 320B Mar 20 10:05 dryrun-20200320_140542-1vbczul4 drwxr-xr-x 10 shamoon staff 320B Mar 20 10:06 dryrun-20200320_140605-uze15jta drwxr-xr-x 10 shamoon staff 320B Mar 20 10:06…
Shamoon
  • 455
13
votes
5 answers

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 accessing a file through it. I can only imagine one use…
user368507
  • 2,173
11
votes
5 answers

find all symbolic links in a directory tree pointing outside that tree

I frequently move directory trees to other locations or copy their tarballs to other machines, and I would like to have a method to check whether any symlinks in a directory tree A point to locations outside of A since these will be broken in the…
Marcus Junius Brutus
  • 4,587
  • 11
  • 44
  • 65
10
votes
5 answers

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 x86, then the symlink should take me to that…
dogbane
  • 29,677
10
votes
1 answer

Why does catting a symlinked file and redirecting the output to the original file make the latter file empty?

Here's how to reproduce it: echo 'the original file' > orig ln -s orig symb # now symb is symlinked to orig cat symb > orig # this makes orig an EMPTY FILE, but why? orig becomes an empty file after the third command, but why?
Teddy C
  • 457
10
votes
2 answers

Find all absolute links in a directory tree

How do I (recursively) detect all symlinks in a directory that identify their target in an absolute as opposed to in a relative way? Since these links are very likely to break when an entire directory tree is moved I would like to have a way of…
Marcus Junius Brutus
  • 4,587
  • 11
  • 44
  • 65
10
votes
3 answers

What file mode is a symlink?

What file mode indicates that a file is a symbolic link (symlink)? My use case is to detect symbolic links inside a git repository (and its history). I was under the impression that a symlink is a symlink because of its file mode, and that file…
ThorSummoner
  • 4,422
10
votes
4 answers

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 have had config files where $HOME works but ~…
Lerc
  • 203
8
votes
3 answers

ln -s: from one source to many destinations

Pseudocode ln -s $HOME/file $HOME/Documents/ $HOME/Desktop/ where I want to create a symlink from the source to two destinations. Probably, moreutils and pee. How can you create many symlinks from one source?
1
2 3 4 5 6 7