Tag Info

Hot answers tagged

36

All the ln means "link", not just the "l". Just the same as ls meaning "list", cp means "copy" and mv means "move". They are part of the "two letter commands", for example: ar — ARchive as — ASsembler bc — Basic Calculator cc — C Compiler cp — CoPy files and directories dc — Desk Calculator dd — Data Description: convert and copy a file df — Disk Free: ...


25

Many programs make use of this technique where there is a single executable that changes its behavior based on how it was executed. There's typically a structure inside the program called a case/switch statement that determines the name the executable was called with and then will call the appropriate functionality for that executable name. That name is ...


22

Patrice identified the source of the problem in his answer, but if you want to know how to get from there to why you get that, here's the long story. The current working directory of a process is nothing you'd think too complicated. It is an attribute of the process which is a handle to a file of type directory where relative paths (in system calls made by ...


17

This is the result of a hard-coded limit in the Linux kernel source; to prevent denial-of-service, the limit on the number of nested symlinks is 40 (found in the follow_link() function inside fs/namei.c, called by nested_symlink() in the kernel source). You would probably get a similar behaviour (and possibly another limit than 40) with other kernels ...


12

Here's what's happening. If you make a symlink with a relative path, the symlink will be relative. Symlinks just store the paths that you give them. They never resolve paths to full paths. Running $ pwd /usr/bin $ ln -s ls /usr/bin/ls2 creates a symlink in /usr/bin to ls relative to the directory that the symlink is in (/usr/bin). The above command would ...


11

A file is an inode with meta data among which a list of pointers to where to find the data. In order to be able to access a file, you have to link it to a directory (think of directories as phone directories, not folders), that is add one or more entries to one of more directories to associate a name with that file. All those links, those file names point ...


11

On linking You generally do not link /usr/local/* with /bin, but this is more of a historical practice, in general, there are a few "technical" reason why you cannot do what you're suggesting. Making links to executables in /bin can cause problems: Probably the biggest caveat would be if you're system is having packages managed by some sort of package ...


9

Use rsync's option -K (--keep-dirlinks). From the manpage: -K, --keep-dirlinks This option causes the receiving side to treat a symlink to a directory as though it were a real directory, but only if it matches a real directory from the sender. Without this option, the receiver’s symlink would be ...


7

I don't fully understand what you're asking. If I didn't know any better I think you were asking if there was a way to detect this while in the midst of dealing with a file. I don't believe this is possible. The only method I can conceive of is doing a find where you specifically start looking through a particular branch in the directory tree. Example $ ...


6

Symlinks themselves have 777 because in Unix, file security is judged on a file/inode basis. If it's the same data they're operating on, it should have the same security conditions, regardless of the name you gave the system to open it. [root@hypervisor test]# ls -l total 0 lrwxrwxrwx. 1 root root 10 Jun 8 16:01 symTest -> /etc/fstab [root@hypervisor ...


6

From the ln man page: When creating hard links, each TARGET must exist. No mention of symlinks there; in fact, this statement seems to imply that this is not the case for symlinks. As I said in my comment on your question, when creating a symlink to a non-existent source, a broken link is created: $ ln -sfv blah blabla 'blabla' -> 'blah' $ file ...


6

By default, du will only count each file once if it is linked to multiple times. If you run du -L bar it will count the file because it only reaches it once. However, if you run du -L * it will only count it the first time it sees it. For example: $ du -L foo bar 16K foo 4.0K bar $ du -L bar foo 16K bar 4.0K foo Notice that swapping the ...


5

You can use readlink to resolve the symbolic link and then dirname to get its directory. cdl () { cd "$(dirname "$(readlink "$1")")"; } bash-3.2$ pwd /foo/bar bash-3.2$ ls -l total 8 lrwxr-xr-x 1 root wheel 11 Jun 15 19:10 foo.sh -> /bar/foo.sh bash-3.2$ cdl foo.sh bash-3.2$ pwd /bar bash-3.2$


5

You could use the symlinks command to convert absolute paths to relative: /tmp$ mkdir -p 1/{a,b,c} 2 /tmp$ cd 2 /tmp/2$ ln -s /tmp/1/* . /tmp/2$ ls -l total 0 lrwxrwxrwx 1 stephane stephane 8 Jul 31 16:32 a -> /tmp/1/a/ lrwxrwxrwx 1 stephane stephane 8 Jul 31 16:32 b -> /tmp/1/b/ lrwxrwxrwx 1 stephane stephane 8 Jul 31 16:32 c -> /tmp/1/c/ We've ...


5

Binary-edit the file (with vim -b for instance) and replace any occurrence of /usr/lib32/libjpeg.so.62 with some path to your libjpeg.so that is exactly the same size like for instance /usr/lib//////libjpeg.so /usr/lib32/libjpeg.so.62 /usr/lib//////libjpeg.so


5

Here is the answer. But that question points to bash as the target of the problem. The explanation is that find finds "$HOME/MySymlinkedPath". It's a symbolic link, not a directory, so the recursive descent stops there. If the expression matched "$HOME/MySymlinkedPath" (for example, in find "$HOME/MySymlinkedPath" -name 'My*'), then find would print that as ...


5

For the one that doesn't work, if we look at the ls -l result, we get the following: [sparticvs@sparta test]$ ls -l build/ total 0 lrwxrwxrwx. 1 sparticvs sparticvs 6 Dec 17 16:08 client -> client Now to understand what is going on here. Let's look at the command you called: ln -s client build/client According to the Man Page, there are two possible ...


4

With links, I'm afraid, this will not be possible. However, you could use a named pipe. Example: # create some dummy files echo alpha >a echo beta >b echo gamma >c # create named pipe mkfifo allfiles # concatenate files into pipe cat a b c >allfiles The last call will block until some process reads from the pipe and then exit. For a ...


4

Assuming you have root on the system, you can use a bind mount. Note that this will leave you with an empty Camera Uploads directory in your ~/Dropbox/Pictures, but avoiding that adds much more complexity (unionfs of some sort). # mount --bind ~user/Dropbox/Pictures ~user/Pictures # mkdir -p ~user/Pictures/Camera\ Uploads # mount --bind ...


4

The hard link is, essentially, the original file. So, the size you see reported is the size of the file being linked to. It is soft links that only take up the space of their names (kinda). As far as the filesystem is concerned, the hard link and the original are the same thing, they point to the same inode so the same size is reported.


4

Filesystems where you can't change the date of a symlink are common. This in itself is not a bug of bindfs or sshfs. Rsync is designed to cope with that. It ignores failures to change the time and other metadata of symbolic links if the underlying filesystem doesn't support it. Under Linux, rsync calls utimensat with the AT_SYMLINK_NOFOLLOW flag to change ...


4

Ah, asked too quickly. On Linux, the answer is to use readlink with the -m switch: $ readlink -m /home/saml/web/../web_login_form_examples/basic-php-parsing.zip /home/saml/web_login_form_examples/basic-php-parsing.zip readlink man page -m, --canonicalize-missing canonicalize by following every symlink in every component of the given name ...


4

The trailing slash in the argument given to -L causes the symbolic link to always be resolved (i.e. at the level of the lstat(2) call). See POSIX.1 Base Definitions, General Concepts, Pathname Resolution, or “Trailing slashes” in Linux’s path_resolution(2). This is not specific to zsh. You can use a simple parameter expansion to strip the trailing slash: ...


4

A more robust solution would be to use an alias in your .bashrc: alias viscrtch='vi /tmp/scratch' This way viscrtch can be used to edit /tmp/scratch from anywhere within the filesystem. If you want the ability to add command line arguments, use a shell function instead: viscrtch(){ vi "$@" /tmp/scratch; } Call it as viscrtch your_options_here Even ...


4

I don't think there's such an utility. With GNU readlink, you could do something like: is_in() ( needle=$(readlink -ve -- "$1" && echo .) || return haystack=$(readlink -ve -- "$2" && echo .) || return needle=${needle%??} haystack=${haystack%??} haystack=${haystack%/} needle=${needle%/} case $needle in ("$haystack" | ...


4

Answering to the questions asked: Is this correct? No, it is a poor practice. Are there some hidden side-effects to my suggestion? Yes there are several side effects. Your suggestion might work or not depending on the application, and might regress or be broken in the long term. There are sensible reasons not to create such a symbolic link: ...


4

Because the object of the ls invocation is not the same. In the first case, the argument is the current directory (.), and the link is displayed only incidentally (because the argument is a directory and the link is in it). In the second case, it is among the explicitly listed arguments, and the special rule "follow symbolic links" applies only to the ...


3

In zsh, there's a modifier for that, or rather two: A to resolve symbolic links (with realpath) and h to extract the “head” (i.e. the dirname). cd $file(:A:h) This only works if the symbolic isn't broken. If there is a chain of symbolic links, it is followed until the ultimate target. If the directory was reached through a symbolic link, you'll be in its ...


3

-h (or --dereference) to dereference will only work upon creation. Reference: http://www.gnu.org/software/tar/manual/tar.html#SEC138 According to a similar answer here: How do I dereference links when extracting from a tar file? you can mount the archive then copy from it, though I have not tested this myself.


3

The reason that cd is aware that you have entered the directory via a symlink is because it is built-in to the shell. The cp command is an external binary and is only passed data via command line arguments and environment variables. Environment variables do not contain data on how you entered the current directory. If you are using bash, you can make cd ...



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