how to list full paths of folders inside a directo

2019-07-27 04:29发布

问题:

This question already has an answer here:

  • Unix ls command: show full path when using options 6 answers

I have a folder /home/Documents/myFolder and inside this folder there are lots other folders. I want to have a file list.txt which contains all the paths of the folders. I want the text file content like this:

 /home/Documents/myFolder/1234
 /home/Documents/myFolder/asd2
 /home/Documents/myFolder/asdawgf
 /home/Documents/myFolder/dawt
 .
 .
 .

I tried this one but it was not what I want ls > /home/Documents/myFolde/list.txt it just prints the folder names. I want the full paths.

回答1:

Use find listing all directories (-type d) and then sed the output to get the full path correct:

find . -type d | sed -n 's:^\./:/home/Documents/myFolder/:'p > /home/Documents/myFolder/list.txt


回答2:

you can use find:

find . > /home/Documents/myFolde/list.txt