A collection of computer systems and programming tips that you may find useful.
Brought to you by Craic Computing LLC, a bioinformatics consulting company.

Friday, January 27, 2012

Getting absolute paths with the Unix ls command

The standard Unix command ls lists filenames and directories in the specified directory. The default behaviour is to list just the filenames as including the full pathname would clutter the screen.

But sometimes you want the absolute paths. I need this all the time if I want to create a file containing a list fo filenames. The obvious command to get all the YAML files, for example, is:
$ ls -1 *yml

In order to get the full pathnames you need to use this:
ls -1 -d $PWD/*yml


Maisam said...
This comment has been removed by a blog administrator.
vijay said...

Thanks for the tip on ls command examples in unix

Archive of Tips