Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Normally, ls -la would give this to me but I guess CentOS is different. I need to verify that a symbolic link exists.

share|improve this question
You mean if the file the symbolic link is pointing to exists ? – Dominik Mar 11 '10 at 1:51

If you mean "Does the link actually point to a file?", (which I think you do because lthen:

if [[ -e "$file" ]]; then echo it is there; fi

If just want to test if the file is a symbolic link, than:

if [[ -h "$file" ]]; then echo it is a link; fi

This is tailored toward Bash, and not the most portable way. And as a little bit of trivia you don't need the quotes when using the double bracket syntax.

If you want to search for broken links than use find -L . -type l.

If you just want ls to work again with its different colors for broken links, have a go at eval $(dircolors)

share|improve this answer

If you're looking to verify a file you already know you can use. Additionally file can be used to identify the type of file object:

[akula@jasonlawer ~]$ file /var/www/html/2001914
/var/www/html/2001914: symbolic link to `/tickets/rhev/2001914.zip_FILES/'

If it was provided as part of a package though the easiest thing to do is just use RPM to verify the package using

[akula@jasonlawer ~]$ rpm -V httpd
share|improve this answer

you can use

if [[ -f `readlink filename` ]]; then

readlink command returns target of the symbolic link. -f tests if that file exists. Be carefull about ` character, its not " or '. It helps you to execute inner bash command like a inner query in an sql system.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.