Skip to main content

How to get the filenames and their absolute paths in one line? [Resolved]

I want to list all the files in a folder and their respective absolute paths line by line as below,

filename1  /home/.../file1  
filename2 /home/.../file2  
filename3 /home/.../file3  

I tried with find $(pwd) -type f, but it only gives the paths.

Question Credit: HirSK
Question Reference
Asked April 14, 2019
Tags: filenames
Posted Under: Unix Linux
5 Answers

Using GNU find:

find "$PWD" -type f -printf '%f %h/%f\n'
  • %f File's name with any leading directories removed (only the last element).
  • %h Leading directories of file's name (all but the last element). If the file name contains no slashes (since it is in the current directory) the %h specifier expands to `.'.

credit: Kusalananda
Answered April 14, 2019

Use this cmd:

find $PWD -type f -printf '%f %h/%f/n'


Looking for some files then go with this:

find $PWD -type f -iname "filenames" -printf '%f %h/%f/n'

credit: tomashubham
Answered April 14, 2019

You can use the following cmd for searching the files with their absolute paths. E.g. I am trying to search .sh files using cmd as follows:

find . -type f -iname "*.sh"

credit: Prvt_Yadv
Answered April 14, 2019
Your Answer