Show All Symbolic (Soft) Links

ls -l | grep ^l
Shows all linked file and destinations. The 'ls -l' command lists the files in long (1 file per line) format, and the grep command displays only those lines that starts with an l (lower case L) -- a linked file. Updated: Remove reference to hard links because this command does not apply to hard link as others kindly pointed out.
Sample Output
$ ll | grep ^l
lrwxrwxrwx  1    4 Aug 26  2008 awk -> gawk*
lrwxrwxrwx  1    3 Aug 26  2008 bsh -> ash*
lrwxrwxrwx  1    4 Aug 26  2008 csh -> tcsh*

By: haivu
2009-04-02 17:47:36

These Might Interest You

  • == remove broken links == find -L . -type l -exec rm -rf {} \; == how this work == "symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken. If you want to search for symbolic links when -L is in effect, use -xtype." -- manpage of find.

    find -L . -type l
    jianingy · 2010-07-23 06:32:41 3
  • The symlinks command can show status of all symbolic links, including which links are dangling, which symlinks point to files on other file systems, which symlinks use ../ more than necessary, which symlinks are messy (e.g. having too many slashes or dots), etc. Other useful things it can do include removing all dangling links (-d) and converting absolute links to relative links (-c). The path given must be an absolute path (which is why I used $(pwd) in the example command).

    symlinks -r $(pwd)
    kFiddle · 2009-05-01 23:33:10 1
  • The "type" builtin command is handy to find out what executable will be used if you issue a command. But on some distros, particularly when using /etc/alternatives, certain executables get buried under layers and layers of symbolic links and it becomes hard to find which one. If you put the above command in your .bashrc, it adds a "-c" option to the type command that will weed through the symbolic links and prints the actual file that will be executed. Show Sample Output

    type () { if [ "$1" = "-c" ]; then shift; for f in "$@"; do ff=$(builtin type -p "$f"); readlink -f "$ff"; done; else builtin type $typeopts "$@"; fi; }
    splante · 2011-04-07 18:57:51 0
  • The tag function takes a tag name as its first argument, then a list of files which take that tag. The directory $HOME/tags/tagname will then hold symbolic links to each of the tagged files. This function was inspired by tmsu (found at Example: tag dog airedale.txt .shizturc This will create $HOME/tags/dog which contains symbolic links to airedale.txt .shizturc and

    tag() { local t="$HOME/tags/$1"; [ -d $t ] || mkdir -p $t; shift; ln $* $t;}
    bartonski · 2012-02-08 12:40:45 4

What Others Think

Does not show hard linked files
citybadger · 477 weeks and 3 days ago
Hard links are not a link file type. The are regular files. As such, your command will only show you soft, or symbolic links. echo foo > foo.txt ln foo.txt bar.txt ls -l bar.txt
atoponce · 477 weeks and 2 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: