Search code examples
linuxbashrecursiondirectoryfilesystems

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/

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.


Solution

  • find is a good utility to obtain (recursively) all the content of a directory. 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 [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