Tag Info

Hot answers tagged

41

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 named ls2 in /usr/bin to ls(viz. /usr/bin/ls) relative to the directory that the symlink is in ...


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


38

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


29

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


21

You can't without writing a bit of code. Those symlink shortcuts work because vim is written that way. It looks at how (with what name) it was started and acts as if it had been called with the appropriate command line options. This behavior is hardcoded in the executable, it is not a trick done by the symbolic link. So if you want to do that yourself, the ...


20

First of all, to find what a command's options do, you can use man command. So, if you run man ln, you will see: -f, --force remove existing destination files -s, --symbolic make symbolic links instead of hard links Now, the -s, as you said, is to make the link symbolic as opposed to hard. The -f, however, is not to remove the ...


14

Because in the second ln it doesn't fail it creates a symlink_dir/dir_2 -> dir_2 symbolic link Do a: ls -l symlink_dir/dir_2 And you'll see a (probably broken) symlink there. That's how ln is meant to work if the target is a directory (or a symlink to a directory). A third ln could fail because there's already a dir_2 inside symlink_dir (aka ...


8

As Dubu points out in a comment, the issue lies in your relative paths. I had a similar problem symlinking my nginx configuration from /usr/local/etc/nginx to /etc/nginx. If you create your symlink like this: cd /usr/local/etc ln -s nginx/ /etc/nginx You will in fact make the link /etc/nginx -> /etc/nginx, because the source path is relative to the link's ...


7

ln -f "$(readlink <symlink>)" <symlink>


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

Things to check: Perform an ls -l on /usr/bin/prj-python if its likelrwxrwxrwx (...) /usr/bin/prj-python -> bin/python the file will actually be searched at /usr/bin/bin/python (that's what xralf tried to say). Fix:rm /usr/bin/prj-pythonln -s /full/path/to/your/python /usr/bin/python-prj If your bin/python is a shell script (aka. wrapper-script) check ...


6

You forgot the initial slash before bin/python. This means /usr/bin/prj-python now points to /usr/bin/bin/python. What would you like it to point to exactly?


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

The easiest way to link to the current directory as an absolute path, without typing the whole path string would be ln -s "$(pwd)/foo" ~/bin/foo_link The target argument for the ln -s command works relative to the symbolic link's location, not your current directory. It helps to imagine that the created symlink simply holds the text you provide for the ...


6

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

On the surface, what you've suggested you've tried works for me. Example $ mkdir -p test/src test/firefox $ tree --noreport -fp . `-- [drwxrwxr-x] ./test |-- [drwxrwxr-x] ./test/firefox `-- [drwxrwxr-x] ./test/src Make the symbolic link: $ ln -s test/src test/firefox $ tree --noreport -fp . `-- [drwxrwxr-x] ./test |-- [drwxrwxr-x] ...


5

Read your man page: Question 1 = 1st Form, this is because in linux all items are considered files, even directories. As an example, use your text editor to "open" /etc/, ie: nano -w /etc/ nano will politely tell you /etc/ is a directory Since it's technically legal to create never ending symlinks. In the old days, before the bounds check was written, I ...


4

You can use the -f, --force option of ln to have it remove the existing symlink before creating the new one. If the destination is a directory, you need to add the -n, --no-dereference option to tell ln to treat the symlink as a normal file. ln -sfn target existing_link However, this operation is not atomic, as ln will unlink() the old symlink before ...


4

The results of both has to be the same, in that a hard link is created to the original file. The difference is in the intended usage and therefore the options available to each command. For example, cp can use recursion whereas ln cannot: cp -lr <src> <target> will create hard links in <target> to all files in <src>. (it creates ...


3

It depends on where your temporary directory is. That is, have you created your own temporary directory, or are you using the system's (/tmp)? In your scenario, you are expecting the files/folder to remain after the temporary directory has been cleaned up. If it's in the system's /tmp directory then it may well be cleaned up by the system (it's distro ...


3

The link() system call on the NFS client should map directly to the NFS LINK operation, which the server should implement using its link() system call. So as long as link() is atomic on the server, it will also be atomic on the clients.


3

You can do this in a roundabout way via your shell configuration. Something like alias big_vim='gvim -p -geom 126x512' would work in bash/zsh. It allows you to customise things without messing with sudo/root.


3

This will create symlinks /somedir/dir1/* pointing to /media/sd*/dir1/*. mkdir /somedir/dir1 ln -sf /media/sd*/dir1 /somedir/dir1 If a file or directory exists in more than one /media/sd*/dir1/ then the link will point to the last one, for example if you have: /media/sda1/dir1/Movies /media/sda1/dir1/Pictures /media/sdb1/dir1/Data you will get: ...


3

What is the advantage to keep symbolic links relative to directory? Because this allows one to move the direcoty itself without breaking the symbolic links? Exactly. In addition, is it possible to create a symbolic link with .. (parent directory) in the path without being in the directory? ln -sv '/etc/init.d/rsyslog' '/etc/rc3.d/../init.d/rsyslog' ...


3

But something about the syntax is perplexing and counter to what I would expect. The arguments for ln, in the form that you're using it, are: ln [OPTION]... [-T] TARGET LINK_NAME (1st form) The perplexing, unintuitive thing is that when you're creating a symlink, the target argument for ln isn't expected to be a path to a file, but rather the ...


3

Try using cut, like: cut -d/ -f6 file


3

If you want to use awk, as you seem to indicate in your question, you could set the field separator to / and then print the last field awk -F/ '{print $NF}' filename


3

Also note that the error you gave above ln: creating symbolic link `/etc/init.d/jboss1': Permission denied is not due to the owner of the symlink being somebody else than the owner of the original file. It is (most probably) caused by user askar not having write access to the directory /etc/init.d.


2

You can't do that. VIM check it's running path on start , e.g by linking original binary to rvim , running path become /path/to/rvim , in that case , VIM will add the -Z parameter automatically even if you didn't specify that. But if you're only running VIM in terminal , you should: For bash , add an alias to ~/.bashrc alias vim='vim -Z' Change the ...



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