Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
/home/user/public_html/.htaccess

is it possible?

share|improve this question
add comment

3 Answers

up vote 6 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

Output

$ cd /tmp && touch foo
$ ls ./foo
./foo
$ readlink -f ./foo
/tmp/foo
share|improve this answer
2  
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
1  
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
add comment

You will have to use find and pwd.

Something like:

find `pwd` -name .htaccess -maxdepth 1

OR

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
add comment

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

$ realpath .htaccess
/home/user/public_html/.htaccess
share|improve this answer
1  
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
add comment

Your Answer

 
discard

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.