[英]How can I export a recursive directory & file listing to a text file in Linux Bash shell with an SSH command?
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. 提前致谢。
使用find
获取目录及其子目录中所有文件的列表,然后使用>
操作数将其通过管道传输到文件。
find > list.txt
The command find > list.txt
will do. 命令find > list.txt
将find > list.txt
。 If you want directory tree list tree -a > list.txt
can be used 如果要目录树,可以使用tree -a > list.txt
find
is a good utility to obtain (recursively) all the content of a directory. find
是一个很好的实用程序(递归地)获取目录的所有内容。 If you want the file (and directory) names with their permissions: 如果您想要文件(和目录)名称及其权限:
find /home/kparisi -printf "%M %p\n"
You can then use ssh
to run this command on the remote server: 然后,您可以使用ssh
在远程服务器上运行此命令:
ssh kparisi@remote.com 'find /home/kparisi -printf "%M %p\n"'
And finally, if you want to store this in a file on your local server: 最后,如果要将其存储在本地服务器上的文件中:
ssh kparisi@remote.com 'find /home/kparisi -printf "%M %p\n"' > file
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.txt
prints sizes of files in a human readable format. 这: tree -ph > fsstruct.txt
以易于阅读的格式打印文件的大小。
Also, it is possible to send output to the file: tree -ph . -o fsstruct.txt
同样,可以将输出发送到文件: tree -ph . -o fsstruct.txt
tree -ph . -o fsstruct.txt
or create HTML: tree -Hph . -o tree.html
tree -ph . -o fsstruct.txt
或创建HTML: tree -Hph . -o tree.html
tree -Hph . -o tree.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.