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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23808798/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 10:30:27  来源:igfitidea点击:

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

linuxbashrecursionsshdirectory

提问by CheeseConQueso

Assume I'm in my pwd- /home/kparisi/

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

What command can I run to export all directories & files from this directory and all subdirectories within it to a text file?

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

I don't need the contents of the files, just their names & paths (and permissions if possible)

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

Thanks in advance.

提前致谢。

采纳答案by gniourf_gniourf

findis a good utility to obtain (recursively) all the content of a directory. If you want the file (and directory) names with their permissions:

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

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

You can then use sshto run this command on the remote server:

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

ssh [email protected] 'find /home/kparisi -printf "%M %p\n"'

And finally, if you want to store this in a file on your local server:

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

ssh [email protected] 'find /home/kparisi -printf "%M %p\n"' > file

回答by Othi

Use findto get a listing of all the files in a directory and its subdirectories, then pipe it to a file with the >operand.

使用find来获取文件的目录及其子目录中所有的列表,然后通过管道它与文件>操作。

find > list.txt

回答by Tiago Lopo

The command find > list.txtwill do. If you want directory tree list tree -a > list.txtcan be used

该命令find > list.txt将执行。如果你想要目录树列表tree -a > list.txt可以使用

回答by zviad

I understand that it is an old question, but anyway if somebody will reach this page, maybe will be useful. I love to do this (assume we have the file "fsstruct.txt" to save directory structure):

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

tree > fsstruct.txt

for me this format is simpler to read.

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

It is easy also to use other features of tree:

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

tree -p > fsstruct.txt

prints file type and permissions before file and it is more accessible when you are reading plain text, which is a file and which is a directory.

在文件之前打印文件类型和权限,当您阅读纯文本时更容易访问,哪个是文件,哪个是目录。

tree -h > fsstruct.txt 

this:tree -ph > fsstruct.txtprints sizes of files in a human readable format.

this:tree -ph > fsstruct.txt以人类可读的格式打印文件的大小。

Also, it is possible to send output to the file: tree -ph . -o fsstruct.txtor create HTML: tree -Hph . -o tree.html

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