Listing absolute paths with `ls`

Normally when you list the files in your directory/sub-directory with the ls command you would get the paths to those files with respect to the current directory.

But what if you wanted to save this list and you wanted the absolute paths rather than the relative paths. Well it doesn’t strike you first but then when you know it, its like, “Oh its that obvious!”

So you do

ls -d $PWD/what_ever_you_are_trying_to_list

The $PWD gets filled with the path to the current directory.

Example:
ls work/*.md

might have yielded

work/this.md
work/that.md
work/something.md
work/someotherthing.md

But,
ls -d $PWD/work/*.md

would yield something like

/home/username/work/this.md
/home/username/work/that.md
/home/username/work/something.md
/home/username/work/someotherthing.md

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s