Skip to content
Advertisement

Printing full path of directories

I am trying to get full paths of folder and print them into a into a file.

ls -ltR|grep "^d"|awk -v P="$(pwd)" '{print $NF " = " P"/"$NF}'

I have been using this command to get paths. But they are not proper. Ex. When trying to print path of Documents/Folder/Folder2 comes as Documents/folder2 instead of proper path.

I have tried going over directory using for loop and printing out solution like this:

for dir in */
do
     dir=ls -ltR|grep "^d"|awk -v P="$(pwd)" '{print $NF " = " P"/"$NF}'
     echo $dir
done

Advertisement

Answer

How about simply:

find  ./*

It will print all the paths starting with ‘.’

If you want the absolute path try the following:

find  `pwd` 
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement