Hot answers tagged

42

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


21

You're looking for test: -h pathname True if pathname resolves to a file that exists and is a symbolic link. False if pathname cannot be resolved, or if pathname resolves to a file that exists but is not a symbolic link. If the final component of pathname is a symlink, that symlink is not followed. Most shells have it as a builtin, but test also ...


17

autofs can do this for you. You can configure any number of mountpoints with various options, and the corresponding filesystems are mounted whenever the mountpoint is accessed. After a given amount of inactivity the filesystems are unmounted again. There are no doubt various ways of using autofs, but here's one way of doing what you're trying to do, based ...


17

Shell aliases have the feature that you can do (some) name-completion on them (usually bound to tab). Alternatively, you can use the CDPATH feature, which "recently" (within the past 5-6 years) has been improved to support name-completion. If that works for you, it has the advantage that the what you type is the actual name of the directory rather than a ...


16

For the directories you frequent often, but don't change daily, another option is just to have several alias commands in your .bashrc file: alias cdo="cd /u01/app/oracle" alias cdw="cd /var/www/html" A friend has about 50 of those; I have a handful; quick and easy. Just cdo to change directory to /u01/app/oracle


13

That is a feature of the shell that remembers how you got to where you are. If you have realpath installed you can do: $ realpath /home/dazz/test/1 And lacking that if you have python: $ python -c "import os; print(os.path.realpath('.'))" /home/dazz/test/1 or readlink (from coreutils): $ readlink -f . /home/dazz/test/1 or /bin/pwd (not the shell ...


11

This is the purpose of ln's -f option: it removes existing destination files, if any, before creating the link. ln -sf /path/to/data/folder/month/date/hour/minute/file /path/to/recent/file will create the symlink /path/to/recent/file pointing to /path/to/data/folder/month/date/hour/minute/file, replacing any existing symlink if necessary (and working fine ...


10

You could use tab completion. By default on many Linux distributions, bash is set up so that when you hit the [TAB] key, you're given a list of possible matches, or if there's just one match, it's all filled out. For cd, this is normally a list of subdirectories of the current working directory. You could overwrite that, but I suggest instead making an ...


9

You can do this with systemd, so you don't have to install extra software and just have a small amount of extra configuration. Simply add noauto,x-systemd.automount to the options in fstab. noauto to not mount automatically on boot and x-systemd.automount to let systemd mount it on access. Source: ArchWiki - fstab


8

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


7

Contrast pwd and /bin/pwd. pwd, which is a built-in command in many shells, tells you where your shell thinks you are (and hence treats symlinks "soft links" as if they were real directories. /bin/pwd is an external program that tells you where you really are, if necessary by traversing the filesystem tree up to /. It takes no account of symlinks because ...


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


6

I wanted to preserve my symlinks as symlinks. For that you can use the -l option. -l, --links copy symlinks as symlinks Since I was copying frameworks on OS X, I found this helpful.


6

Other answers have covered /bin/pwd vs the shell's builtin pwd. If you want to follow symlinks in the Windows style you mentioned, use cd -P: it will change the PWD variable accordingly. If you want to use -P by default, you can add this line to your .bashrc or .zshrc: set -P Other shells may vary.


6

I recommend pushd and popd. I personally do find them handy when doing development work / reading source code when multiple directories are involved. They effectively implement a stack structure/LIFO, where you pushd a directory, and the next popd command retrieves it. So, when inside a dir, you would do: pushd . And when you need to retrieve it, you ...


6

Symlinks Autodereferenced references to filenames A symlink is literally a text file that's treated specially by the kernel and whose contents is a path to another file/directory. You can read the contents of a symlink file with readlink, and if you standardly open a symlink file, the system will open the file/directory referenced by contents of the ...


6

Set the mark-symlinked-directories readline option. The usual way to do this is to edit ~/.inputrc, put set mark-symlinked-directories on in there, then start a new bash shell (or press Ctrl+X Ctrl+R to reload your readline settings). Less commonly, you could also put it straight in your ~/.bashrc like this bind 'set mark-symlinked-directories on'


5

The -i/--in-place flag edits a file in place. By default, sed does the (arguably) simplest possible thing and doesn't check if the file is a symlink, before reading from it, transforming, then truncating and writing. GNU sed has a --follow-symlinks flag, which makes it behave as you want with symlinks: $ echo "cat" > pet $ ln --symbolic pet pet_link $ ...


5

Welcome to the future. It is now 2012, and in your brand new Fedora version 17 /bin is now merely a symbolic link to /usr/bin. There is no separate /bin directory. Further reading Joe 'Zonker' Brockmeier (2012-01-30). The Ever-Changing Linux Filesystems: Merging Directories into /usr. linux.com. Harald Hoyer and Kay Sievers (2012). UsrMove. Fedora ...


5

The command you ran created a symbolic link in the current directory. Judging by the prompt, the current directory is your home directory. Creating symbolic links to executable programs in your home directory is not particularly useful. When you type the name of a program, the shell looks for it in the directories listed in the PATH environment variable. To ...


5

$0 doesn't hold the name of the calling program but the name of the called program. The called program is ./my_command so $0 will be ./my_command too. The fact it is a symbolic link doesn't make a difference.


5

rsync -a --copy-unsafe-links src/ dest From the man page: --copy-unsafe-links This tells rsync to copy the referent of symbolic links that point outside the copied tree. Absolute symlinks are also treated like ordinary files, and so are any symlinks in the source path itself when --relative is used. This option has no ...


5

A file does not keep track of the symbolic links pointing to it. Instead, search for symbolic links under your tree and find out which file/dir they point to using readlink: find -type l -exec readlink -e -- "{}" \+ | sort | uniq Since find's default behavior is recursion, this will work for arbitrary depth.


4

From the ldd command it looks like the binary is looking in /lib/x86_64-linux-gnu and not /usr/lib/x86_64-linux-gnu where you found the symlink. Try running these and see if you still get the same error: sudo ln -s /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 /lib/x86_64-linux-gnu/libcrypto.so.6 sudo ln -s /lib/x86_64-linux-gnu/libssl.so.1.0.0 ...


4

If I undersood the question correctly you need files in myfiles which do not have symlinks in images: #!/bin/bash OIFS="$IFS" IFS=$'\n' files="$(find myfiles/ -type f -name '*.jpg' -or -name '*.cr2')" for f in $files; do list="$(find -L images/ -xtype l -samefile "$f")" if [[ "$list" == "" ]]; then echo "$f does not have symlink." fi ...


4

The first problem is that your find command will only find links that used full paths, not relative ones. To illustrate: $ ln -s /home/terdon/foo/NonExistantFile foo $ ln -s NonExistantFile bar $ tree . |-- bar -> NonExistantFile `-- foo -> /home/terdon/foo/NonExistantFile In the example above, I created two broken links. The first used an absolute ...


4

/proc/<pid>/exe does not follow the normal semantics for symbolic links. Technically this might count as a violation of POSIX, but /proc is a special filesystem after all. /proc/<pid>/exe appears to be a symlink when you stat it. This is a convenient way for the kernel to export the pathname it knows for the process' executable. But when you ...


4

I can provide you with a perl snippet to do this for you: #!/usr/bin/perl # foreach my $i (@ARGV) { # If it is a symlink then... -l $i and do { # First indirection; ensure that it exists and is not a link my $j = readlink($i); print "$i\n" if -e $j and ! -l $j } } If you save that as /usr/local/bin/if-link and make it ...


4

You actually don't need any symlinks, just edit your ~/.bashrc and add the following statement: PATH=$PATH:$HOME/PocketMine This avoids polluting your filesystem with unnecessary clutter like symlinks. If you are a csh/tcsh user rather than a bash user, then edit ~/.cshrc and add set path = ( $path ~/PocketMine ) Personally I'd go one step further ...


4

You could do this, to supply tar with a list of all files inside protTests except those which are symlinks: find protTests -maxdepth 1 -mindepth 1 -not -type l -print0 | tar --null --files-from - -cvf protTests.tar By the way, your existing command: tar -cvf protTests.tar protTests/* will not archive all files in protTests, it will only archive ...



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