how to list full paths of folders inside a directo

2019-07-27 04:39发布

This question already has an answer here:

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.

2条回答
Bombasti
2楼-- · 2019-07-27 04:55

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
查看更多
Ridiculous、
3楼-- · 2019-07-27 04:55

you can use find:

find . > /home/Documents/myFolde/list.txt
查看更多
登录 后发表回答