Tag Info

Hot answers tagged

60

There are many reasons for broken symbolic links: A link was created to a target which no longer exists. Resolution: remove the broken symlink. A link was created for a target which has been moved. Or it's a relative link that's been moved relative to its target. (Not to imply that relative symlinks are a bad idea — quite the opposite: absolute symlinks ...


28

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


20

Jim's answer explains how to test for a symlink: by using test's -L test. But testing for a "hard link" is, well, strictly speaking not what you want. Hard links work because of how Unix handles files: each file is represented by a single inode. Then a single inode has zero or more names or directory entries or, technically, hard links (what you're calling ...


17

Do not blindly remove all dangling symbolic links. They may exist just to carry some information, and may be safer than normal files since a symlink creation is atomic. For instance, Firefox creates a lockfile "lock" that is a symlink whose value has a form like "IP_address:+PID".


17

autofs can do this for you. You can configure any number of mountpoints with various options, and the corresponding filesystems are mounted whenever the mountpoint is accessed. After a given amount of inactivity the filesystems are unmounted again. There are no doubt various ways of using autofs, but here's one way of doing what you're trying to do, based ...


15

Anytime you have these types of questions it's best to conceive of a little test to see what's actually happening. For this you can use strace. unlink $ touch file1 $ strace -s 2000 -o unlink.log unlink file1 rm $ touch file1 $ strace -s 2000 -o rm.log rm file1 When you take a look at the 2 resulting log files you can "see" what each call is actually ...


13

That is a feature of the shell that remembers how you got to where you are. If you have realpath installed you can do: $ realpath /home/dazz/test/1 And lacking that if you have python: $ python -c "import os; print(os.path.realpath('.'))" /home/dazz/test/1 or readlink (from coreutils): $ readlink -f . /home/dazz/test/1 or /bin/pwd (not the shell ...


12

An example: $ touch f1 $ ln f1 f2 $ ln f1 f3 $ ln -s f1 s1 $ ln -s f2 s2 $ ln -s ./././f3 s3 $ ln -s s3 s4 $ ln s4 s5 $ ls -li total 0 10802124 -rw-r--r-- 3 stephane stephane 0 Nov 12 19:55 f1 10802124 -rw-r--r-- 3 stephane stephane 0 Nov 12 19:55 f2 10802124 -rw-r--r-- 3 stephane stephane 0 Nov 12 19:55 f3 10802345 lrwxrwxrwx 1 stephane stephane 2 Nov 12 ...


10

which 2 commands? /usr/bin/java is a soft (symbolic) link to /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/bin/java There is no difference as they are the same file. If you type something like ls -l /usr/bin/java You might get a result such as: lrwxrwxrwx. 1 root root 22 Aug 5 17:01 /usr/bin/java -> /etc/alternatives/java Which would mean ...


9

You can do this with systemd, so you don't have to install extra software and just have a small amount of extra configuration. Simply add noauto,x-systemd.automount to the options in fstab. noauto to not mount automatically on boot and x-systemd.automount to let systemd mount it on access. Source: ArchWiki - fstab


8

A symlink actually stores the path you give literally, as a string¹. That means your link ~/mylink contains "." (one character). When you access the link, that path is interpreted relative to where the link is, rather than where you were when you made the link. Instead, you can store the actual path you want in the link: ln -s "$(pwd)" ~/mylink using ...


8

Using the -h and -L operators. -h file true if file is a symbolic link -L file true if file is a symbolic link http://www.mkssoftware.com/docs/man1/test.1.asp According to this SO thread, they have the same behavior, but -L is preferred.


8

Becoming familiar with your file system layout is all part of becoming a competent user - any time you spend with that aim in mind is not time wasted. However, with that said, you can indeed make it easier to move around the file system. Note that in Linux/UNIX, the file system is presented as a single tree, no matter how many devices make up your storage, ...


7

Because bash (and possibly other shells) track the path you descended, including symlinks, in order to make your trail back up look like the one down. Bash knows how you got to the working directory because cd must be a shell built-in. When you run ls .. the shell can't substitute the "symbolic path" because grep .. is also valid and translating .. would be ...


7

Contrast pwd and /bin/pwd. pwd, which is a built-in command in many shells, tells you where your shell thinks you are (and hence treats symlinks "soft links" as if they were real directories. /bin/pwd is an external program that tells you where you really are, if necessary by traversing the filesystem tree up to /. It takes no account of symlinks because ...


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

Both the fnord and the Gatling webserver use the Unix filesystem as their configuration database (as opposed to, say, Microsoft IIS, which uses the Windows registry, or Apache, which uses a complex-to-parse configuration file). For example, virtual hosts are just directories, and creating a new virtual host is as simple as mkdir www.example.com:80 ...


6

With a single file, rm and unlink do the same task, remove the file. As POSIX defined, rm and unlink both call to unlink() system call. In GNU rm, it calls to unlinkat() system call, which is equivalent to the unlink() or rmdir() function except in the case where path specifies a relative path. Note On some systems, unlink can also remove directory. At ...


6

GNUly: find . -lname '/foo*' -printf '%p\0%l\0' | awk -vRS='\0' ' { getline target sub("^/foo", "/bar", target) printf("%s\0%s\0", target, $0) }' | xargs -r0n2 ln -sfT Or with recent GNU sed: find . -lname '/foo*' -printf '%l\0%p\0' | sed -z 's|^/foo|/bar|;n' | xargs -r0n2 ln -sfT Beware that you will potentially be ...


6

Other answers have covered /bin/pwd vs the shell's builtin pwd. If you want to follow symlinks in the Windows style you mentioned, use cd -P: it will change the PWD variable accordingly. If you want to use -P by default, you can add this line to your .bashrc or .zshrc: set -P Other shells may vary.


6

This is the purpose of ln's -f option: it removes existing destination files, if any, before creating the link. ln -sf /path/to/data/folder/month/date/hour/minute/file /path/to/recent/file will create the symlink /path/to/recent/file pointing to /path/to/data/folder/month/date/hour/minute/file, replacing any existing symlink if necessary (and working fine ...


5

If you use newer coreutils (I'm using coreutils-8.22-11), it has an option to do that: ln --help | grep relative can hold arbitrary text; if later resolved, a relative link is -r, --relative create symbolic links relative to link location For example: $ mkdir /tmp/test $ touch /tmp/test/to $ ln -rs /tmp/test/to /tmp/test/from $ ls -l ...


5

When you write ln -s VALUE link_name it creates a symbolic link with value VALUE. This is what you got. If you want to create a relative link, it is best to cd to the directory where you want to put the link: $ cd ~/bin $ ln -s ../programming/tmux/tmux . Shell completion will help you.


5

You could write a script that runs trough directory B that creates a link for every file in directory A. But, if you want to merge the two folders, I recommend using an overlay filesystem such as aufs. I use it myself for such a task. Use the following mount command (You may have to install the tools to manage aufs): mount -t aufs -o ...


5

Since your primary aim is to have a combined view of your local and external Music folder, I think a union mount via overlayfs could be used, especially if the files are not being written to. The basic command is, in older kernel versions (<3.18): mount -t overlayfs -o lowerdir=/read/only/directory,upperdir=/writeable/directory overlayfs /mount/point ...


5

SLINK has its own inode, and this inode will point to the inode of A.DAT. No, it doesn't reference the inode at all. It points to the name of A.DAT. If the name is changed, the reference breaks. This is why symlinks can work across filesystems. The inode (or whatever data structure is used) may not be visible, but the name is.


5

Welcome to the future. It is now 2012, and in your brand new Fedora version 17 /bin is now merely a symbolic link to /usr/bin. There is no separate /bin directory. Further reading Joe 'Zonker' Brockmeier (2012-01-30). The Ever-Changing Linux Filesystems: Merging Directories into /usr. linux.com. Harald Hoyer and Kay Sievers (2012). UsrMove. Fedora ...


5

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


4

use readlink to get the target of a symlink: target=$(readlink $1) then use the power of shell, to remove everything before the last /; id=${target##*/} or remove everything after the last /: base=${target%/*} then use the power of shell to do simple arithmetic newid=$((id+1)) finally glue them together: newtarget=${base}/${newid} or, in one ...


4

I insert disable_symlinks off; in my nginx.conf and i resolved, works fine! http { disable_symlinks off; } Thanks Andy



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