简体   繁体   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?

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

相关问题 如何在 Linux/Bash 中提取二进制文件的文本部分? - How can I extract the text portion of a binary file in Linux/Bash? 在Linux上,如何通过系统调用或Shell命令监视文件/目录的更改? - On linux, how to monitor the change of a file/directory, by system call or shell command? Linux Shell Bash 按列溢出的文本文件 - Linux Shell Bash Spilt Text file by columes 当我通过 Git Bash 中的 ssh 在远程 Linux 机器上运行命令时,如何将文件的内容直接复制到我的 Windows 剪贴板中? - How can I copy the contents of a file directly into my Windows clipboard when I'm running the command on a remote Linux machine via ssh in Git Bash? Linux Bash 自动命令,源文本文件 - Linux Bash auto command, source text file 使用bash shell脚本检查linux上目录中的最新文件更新 - Check latest file updates in directory on linux using bash shell scripting ssh命令输出以保存在shell脚本中的文本文件中 - ssh command output to save in a text file in shell script 如何在Linux bash shell脚本的curl命令中使用变量来发送带有文件的发布请求? - How to use variable in curl command in Linux bash shell script to send post request with file? unix中的shell脚本(在bash shell中),用于将文件从一个位置(即目录)复制到另一位置,而完全不使用cp命令 - shell script in unix(in bash shell) for copying a file from one location(i.e a directory), to other, without using cp command at all 将文件复制到目录中; Shell,Linux - copying file into directory; Shell, Linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM