Hot answers tagged

9

There are two things to remember: ln -s (without -r) stores the target name literally as you pass it to it if you pass a relative target, it resolves relatively to the link name, not your current working directory Example: I'm in /home/user/d0 and I want a link to /home/user/file so I do: ln -s ../file . ../file is a valid path from d0. Now if ...


8

If you did mkdir /tmp/foo ln -s ../../etc/passwd /tmp/foo Then access /tmp/foo/passwd would convert to /tmp/foo/../../etc/passwd - ie /etc/passwd If you did mkdir /var/tmp/foo ln -s ../../etc/passwd /var/tmp/foo Then access to /var/tmp/foo/passwd would convert to /var/tmp/foo/../../etc/passwd - ie /var/etc/passwd So you can see the "relative symlink ...


7

The basic idea is that you can't access files outside the document root. That's the point of the document root. There are several protections that prevent Apache from following symlinks outside the root. You need to enable FollowSymlinks in the directory containing the link, but if you can browse the files, it means this is already done. You also need to ...


7

Some systems support changing the permission of a symbolic link, others do not. chmod -- change file modes or Access Control Lists (OSX and FreeBSD, using -h) -h If the file is a symbolic link, change the mode of the link itself rather than the file that the link points to. chmod - change file mode bits (Linux) chmod never changes ...


6

In UNIX, directories are special (I feel myself channeling The Church Lady from SNL). Directories contain other files, so deleting them requires a different operation. Even when a directory is empty it still has two files in it (. and ..) so deleting a directory can't be done until it's really empty and the link counts on the relevant files have been ...


6

It can remove files, but directories are not "files". ➜ lab touch file ➜ lab mkdir dir ➜ lab ln -sfT /home file ➜ lab ln -sfT /home dir ln: dir: cannot overwrite directory This is seen in the source: if (remove_existing_files || interactive || backup_type != no_backups) { dest_lstat_ok = (lstat (dest, &dest_stats) == 0); ...


4

You are absolutely correct. What goes in the symlink is exactly what is specified on the command. But the manual tries to say, that the symlink will be interpreted relative to the location of the link, so the user should take care to make the link correctly. Take an example: /tmp/test$ mkdir bar /tmp/test$ ls -l foo/aaa -rw-r--r-- 1 itvirta itvirta 0 Jul ...


3

Yes, the difference is in the order of processing .. and symbolic links. Here's an example of how this can make a difference. I have an external disk mounted at /root/Archives, and a symbolic link pointing to it from my home: $ pwd /home/katsura $ ls -ld Archives lrwxrwxrwx 1 root root 14 Oct 23 2013 Archives -> /root/Archives realpath resolves the ...


3

You mention RHEL in your tags, so I assume this is what you're using. With RHEL 6 and earlier, when you upgrade the tzdata package then it triggers tzdata-update. This reads /etc/sysconfig/clock for the ZONE variable, and will update /etc/localtime as necessary. What this means is that if you change what /etc/localtime is then you must change /etc/...


2

I think this must be one of the silliest command piplines I ever have concocted: $ find . -type l -name "Math*" -print0 | xargs -0 -n 1 -IXXX find XXX/ -type f -name "*.tex" -print0 | xargs -0 fgrep "word" Find all symbolic links called Math*. Do find again on each found path, looking for *.tex files. The xargs need to use -n 1 to call find with no ...


1

You could use rsync rsync -l original_file backup_file From man rsync -l, --links copy symlinks as symlinks I.e. you are copying the link only and not what it points at. Note that this is not moving, but copying, but I assumed that is what you meant for backups.


1

Always check the man pages for help first. It'll save you a lot of time. Or if you're really busy, an ln --help at the shell gives Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) .... Further down the help text, we find ... -s, --symbolic make symbolic links instead of hard links -f, --force remove existing destination files ... which in ...


1

You need to remove file b.txt previously with command rm b.txt, then create symbolic link with your command ln -s a.txt b.txt. You could use hard link from b.txt to a.txt, then execute ln a.txt b.txt, both a.txt and b.txt would point the same file on hard drive and removing a.txt doesn't remove file, which could be read through b.txt. With symbolic link ...


1

Your problem is that you have recursive symlinks. I would consider two options: forget about the -L, get all the files named .tex anywhere in the tree, and then filter them (is there no other criteria than being in a directory that is pointed to by a symlink that starts with "Math"?) Do it in two steps, both without -L: first you search for all symlinks ...


1

GNU ls gives you a choice between coloring files by their type or (if a given type is not colored) by a pattern. That is done by the dircolors program which has a built-in database of types, patterns and colors. ls does not care about the directory path itself. The aspect of "where they refer to" is not easily done with that program. Symbolic links ...


1

Unless the program specifically checks for things, you should be able to do # mv /usr/local/MATLAB /disk2/MATLAB # ln -s /disk2/MATLAB /usr/local And everything should continue working as normal. Indeed on my home machines I do this for the whole of /usr/local (I symlink it to /datadisk/local) so I can upgrade my root disk OS without impacting the ...


1

The permission for symlinks is not evaluated. In former times, there was no way to change the permission bits for symlinks. Since a while, POSIX introduced fchmodat() and all platforms that support this call, are able to change the permission bits for symlinks. Do not expect this to have effects on the symlink though.


1

When you type ln -sT abc/fgh mno/xyz it stores abc/fgh in a new file mno/xyz, and sets the link bit. When you look in mno/xyz you will actually look in mno/abc/fgh. This matters not (as you say) what directory you are in when you create, or use the link. However: They change directories to the location where the relative symlink will be created, so that ...


1

The -h flag (aka --no-dereference) is a good flag to use. Let's say we have this setup: $ ln -s /etc/passwd /tmp/foobar $ sudo chown fred /tmp/foobar Because --dereference is the default, this will actually change /etc/passwd... which is probably not what you want :-) The -h flag would make it change the symlink ownership instead. So you should get ...


1

One way to do it: find . -type l -name 'Math*' -print0 | \ xargs -0 sh -c \ 'find -L "$@" -type f -name "*.tex" -exec fgrep word /dev/null {} +' sh The sh -c '...' sh abomination is necessary to deal with the case when Math* can have spaces. Otherwise, when Math* doesn't expand to filenames with spaces, something like this would work: find -L $(find ...



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