Tag Info

Hot answers tagged

37

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


33

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


27

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


20

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


7

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


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


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


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.


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

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


4

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


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

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

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


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


2

There's no flag to do this with ln. Creating directories is not its job. mkdir -p foo/bar/qux will create foo, foo/bar and foo/bar/qux as needed. So call mkdir -p on all but the last path component first. It sounds like you're reinventing the wheel Stow, a simple package manager that merges directory hierarchies by creating directories to the required ...


2

You won't need a convoluted bash script, but a simple one-liner. mkdir --parents will take care of everything, nicely not even printing an error if the directory structure already exists. Just be careful with how you treat these directories on removal, so you don't break other packages. Also, since you're writting it in bash, you can take a look at sorcery ...


2

Question 1: Why does the whole path need to be written out for both files/folders for a soft link, while for a hard link we can leave out the filename for the target file? You don't need to specify the path or the filename for the soft link too, unless the target is in the current directory. For example, if you have a file ~/Downloads/target_file, you ...


2

Found it: If sysctl fs/protected_hardlinks is set, hard links by someone not the owner (and without CAP_FOWNER), must be: not special not setuid not executable setgid both readable and writable according to fs/namei.c. Some guy on SO wanted to have a dropbox folder people could add to but not see into (I think that's a Windows feature), I figured this ...


2

Aliases are good for giving another name to a command, or for passing default arguments. They are not good beyond that, for example to modify an argument. Use a function instead. To support multiple file names easily, change to the target directory first. Use parentheses instead of braces to create a subshell so that the directory change does not affect the ...


2

You might want to use a shell function like this: banana () { emacs /usr/local/nagios/etc/objects/"$1"; } Only works with one filename. To support more than one would make it more complicated.


2

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



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