Tag Info

Hot answers tagged

40

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

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


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


9

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


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

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.


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


7

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


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

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


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


4

You'll probably want to use the find command using the maxdepth option. I created this sample directory structure: /tmp/parent /tmp/parent/subdir2 /tmp/parent/subdir1 /tmp/parent/subdir4 /tmp/parent/subdir4/notme /tmp/parent/subdir3 Let's say I wanted to create a symlink to /tmp/hooks in each subdir but not the notme subdir: root@xxxxxxvlp12 ~ $ find ...


4

This isn't du resolving the symbolic links; it's your shell. * is a shell glob; it is expanded by the shell before running any command. Thus in effect, the command you're running is: du -s /data/ghs/14 /data/ghsb/14 /data/hope/14 /data/rssf/14 /data/roper/14 If your shell is bash, you don't have a way to tell it not to expand symlinks. However you can ...


4

The symlinks appearing in red indicates "broken" links - i.e. the target does not exist. This seems to indicate that whatever was providing /c is not mounted. You need to figure out the device that provides that data and mount it.


4

You have mistaken the output of at least one command. The permissions of a symbolic link are always rwxrwxrwx, or rather they don't have permissions at all: $ touch file $ ls -l total 0 -rw-rw-r-- 1 muru muru 0 Dec 5 20:53 file $ ln -s file link $ ls -l total 0 -rw-rw-r-- 1 muru muru 0 Dec 5 20:53 file lrwxrwxrwx 1 muru muru 4 Dec 5 20:53 link -> ...


4

Use the file command. [sreeraj@server ~]$ ls -l mytest lrwxrwxrwx 1 sreeraj sreeraj 15 Dec 12 09:31 mytest -> /usr/sbin/httpd [sreeraj@server ~]$ file mytest mytest: symbolic link to `/usr/sbin/httpd' or [sreeraj@server ~]$ file -b mytest symbolic link to `/usr/sbin/httpd' [sreeraj@server ~]$ Also, please go read through man page of ls and check ...


4

ls unfortunately doesn't have an option to retrieve file attributes and display them in an arbitrary way. Some systems have separate commands for that (for instance GNU has a stat command or the functionality in GNU find). On most modern systems, with most files, this should work though: $ ln -s '/foo/bar -> baz' the-file $ LC_ALL=C ls -ldn the-file | ...


4

You could just set up some alias', like: $ alias abc="cd /home/user/Desktop/Folder" To store these for the longer term add them to your .bashrc file. This will work if it's just navigation you're looking for - however the 'abc' above won't be any use if you want to script anything. I personally think it might be as easy in the long run to learn and ...


4

Not at all. One involves redirecting all references to a file name ( any kind of file ) to a different file instead ( symlinks ), and the other involves building an executable image by copying code from a library into the executable ( static linking ) or referencing a dynamic library that contains the required code and loading that dynamic library at ...


4

The -i/--in-place flag edits a file in place. By default, sed does the (arguably) simplest possible thing and doesn't check if the file is a symlink, before reading from it, transforming, then truncating and writing. GNU sed has a --follow-symlinks flag, which makes it behave as you want with symlinks: $ echo "cat" > pet $ ln --symbolic pet pet_link $ ...


4

If I undersood the question correctly you need files in myfiles which do not have symlinks in images: #!/bin/bash OIFS="$IFS" IFS=$'\n' files="$(find myfiles/ -type f -name '*.jpg' -or -name '*.cr2')" for f in $files; do list="$(find -L images/ -xtype l -samefile "$f")" if [[ "$list" == "" ]]; then echo "$f does not have symlink." fi ...



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