# Tag Info

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

18

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

11

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

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

4

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

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 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 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/Movies ... 3 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 ... 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 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 ... 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 ... 1 First of all: don't do this. If you want to have a backup system using hard links to save space, better to use rsync with --link-dest, which will hard link files appropriately to save space, without causing the problems that this causes. If you're using ext[234], you can (ab)use debugfs (warning: this is a corruption of the filesystem): # umount [device] # ... 1 I suggest using find -exec rather than command substitution cos it handles filenames well. If you are trying to copy all pdf files into one single level /dropbox dir? find /zotero -type f -name '*.pdf' -exec cp {} /dropbox/ \; If you want links: find /zotero -type f -name '*.pdf' -exec ln {} /dropbox/ \; Update: You can use rsync on single file, ... 1 As is desired, specifying -n will make ln fail in the second command:$ ln -ns realdir symdir $ln -ns realdir symdir ln: creating symbolic link symdir' to realdir': File exists Note that -v is irrelevant to the outcome. 1 You can see what happens and achieve desired behavior with ln options. Use this alias for ln: alias ln='\ln -vsn' ln options: -v, --verbose print name of each linked file -f, --force remove existing destination files -n, --no-dereference treat destination that is a symlink to a directory as if it were a normal file ... 1 You might want to do that: for dir in dir1 dir2 do [[ ! -d /somedir/$dir ]] && mkdir /somedir/$dir find /media/sd*/$dir -type f -exec bash -c \ '[[ ! -f /somedir/'$dir'/$(basename $1) ]] && ln -s$1 /somedir/'\$dir'/' foo {} \; done This create symbolic links in /somedir/dir1/ (resp. dir2) pointing to all files present under ...

1

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

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