繁体   English   中英

如何使用SSH命令将递归目录和文件列表导出到Linux Bash Shell中的文本文件?

[英]How can I export a recursive directory & file listing to a text file in Linux Bash shell with an SSH command?

假设我在我的pwd - /home/kparisi/

我可以执行什么命令将目录及其中的所有子目录中的所有目录和文件导出到文本文件?

我不需要文件的内容,只需要它们的名称和路径(以及权限)(如果可能)

提前致谢。

使用find获取目录及其子目录中所有文件的列表,然后使用>操作数将其通过管道传输到文件。

find > list.txt

命令find > list.txtfind > list.txt 如果要目录树,可以使用tree -a > list.txt

find是一个很好的实用程序(递归地)获取目录的所有内容。 如果您想要文件(和目录)名称及其权限:

find /home/kparisi -printf "%M %p\n"

然后,您可以使用ssh在远程服务器上运行此命令:

ssh kparisi@remote.com 'find /home/kparisi -printf "%M %p\n"'

最后,如果要将其存储在本地服务器上的文件中:

ssh kparisi@remote.com 'find /home/kparisi -printf "%M %p\n"' > file

我知道这是一个古老的问题,但是无论如何,如果有人将访问此页面,也许会很有用。 我喜欢这样做(假设我们有文件“ fsstruct.txt”来保存目录结构):

tree > fsstruct.txt

对我来说,这种格式更易于阅读。

使用树的其他功能也很容易:

tree -p > fsstruct.txt

在文件之前打印文件类型和权限,并且在读取纯文本(文件和目录)时更易于访问。

tree -h > fsstruct.txt 

这: tree -ph > fsstruct.txt以易于阅读的格式打印文件的大小。

同样,可以将输出发送到文件: tree -ph . -o fsstruct.txt tree -ph . -o fsstruct.txt或创建HTML: tree -Hph . -o tree.html tree -Hph . -o tree.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM