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


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


25

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


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


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

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

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


5

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?


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


3

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


3

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

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


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

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

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.


2

You can't: A symlink is simply an extra inode (a structure that points to the file) and this inode consists of, amongst other things, a deviceId and an inode pointer. The deviceId effectively points to a device special file within the /dev directory and the inode pointer points to a block on that device. Your network location of 10.0.1.103 does not and ...


2

Windows has a special syntax \\MACHINE\DIRECTORY…\FILE meaning the file located at \DIRECTORY…\FILE on the machine called \\MACHINE over the SMB protocol. This is built into the operating system and specialized to one network protocol. Linux has a flexible filesystem based on the notion of mounting. Filesystems are attached to an existing directory, and the ...


2

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


2

The syntax of ln may seem counter-intuitive at first until you see the rationale behind it. The syntax (for soft link creation) is ln -s <TARGET> <LINK_NAME> where <TARGET> is interpreted relative to the location of the soft link. So when you say something like: ln -s file1.txt /home/user9000/Desktop/SymbolicLink.txt This means ...


1

I have made an example to make things much more clearer. Inside a particular directory, I have created 2 files. cat sourcefile This is the sourcefile. ##This is to create a hard link. ln sourcefile destfile ##List the files available. ls destfile sourcefile cat destfile This is the sourcefile. Now assuming you use hardlinks like above to refer ...


1

When you create a hard link, the source path is used at the link creation time, so it must be a path relative to the current working directory (or an absolute path). When you create a symbolic link, the source path is treated as a string; it will be interpreted when the link is used, so it is relative to the directory where the link is. Considering your ...



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