Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I could do this

root@server [/home/user/public_html]# ls /home/user/public_html/.htaccess 

but I'd like to do this

ls --switch .htaccess

is it possible?

share|improve this question
up vote 5 down vote accepted

Using find in combination with pwd is a fine answer but it creates two subshells and isn't necessary. There is a command which will do what you want:

readlink -f .htaccess


$ cd /tmp && touch foo
$ ls ./foo
$ readlink -f ./foo
share|improve this answer
find is not needed, `pwd` is only one subshell and can be replaced by $PWD. readlink -f also follows symbolic links, which is not always desired. – Gilles Nov 8 '10 at 21:19
On FreeBSD and MacOSX, this results in the error readlink: illegal option -- f. Anyone have the solution for other *BSDs? – Stefan Lasiewski May 19 '11 at 23:12
On FreeBSD you can loop over the results from ls, calling realpath on each one. – Brandon Jul 27 '14 at 10:46

You will have to use find and pwd.

Something like:

find `pwd` -name .htaccess -maxdepth 1


From this answer:

ls -d `pwd`/.htaccess

You could use the $PWD variable to cut out unwanted subshells:

find $PWD -name .htaccess -maxdepth 1
ls -d $PWD/.htaccess

See Also:

share|improve this answer
wow I'm surprised that didn't get closed offtopic on SO – xenoterracide Nov 8 '10 at 12:38
at the time, where else could they ask? – Stefan Nov 8 '10 at 12:41
That doesn't make it on-topic there; it has nothing to do with programming – Michael Mrozek Nov 8 '10 at 19:09
i didn't say it was on-topic, just that they might have been more forgiving back then – Stefan Nov 9 '10 at 4:49

realpath exists for this purpose (finding canonical absolute paths):

$ realpath .htaccess
share|improve this answer
realpath has been obsoleted by readlink -f in GNU coreutils, so fewer and fewer Linux systems have it. (And readlink -f also exists on OpenBSD, so it's not completely Linux-specific.) – Gilles Nov 8 '10 at 21:20

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.