如何列出Linux目录中文件夹的完整路径? [英] how to list full paths of folders inside a directory in linux?

查看:220
本文介绍了如何列出Linux目录中文件夹的完整路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件夹 / home / Documents / myFolder ,在此文件夹中还有许多其他文件夹。我想要一个文件 list.txt ,其中包含文件夹的所有路径。我想要这样的文本文件内容:

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
 .
 .
 .

我尝试了这个,但这不是我想要的 ls> /home/Documents/myFolde/list.txt
只会打印文件夹名称。我想要完整的路径。

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.

推荐答案

使用查找列出所有目录( -type d ),然后对输出进行sed以获得正确的完整路径:

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

这篇关于如何列出Linux目录中文件夹的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆