Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I need to have an "image" of a file system without actual contents of the files - just all the names and the structure, so that I can read the file and know what files were stored there and how were they located. As always in these kinds of cases, I tend to believe that there is a beautiful "Unix way" to achieve this with a combination of some standard GNU command-line utilities. Am I right? What is it?

share|improve this question
    
I've added find tag as the command seems to be the solution. –  Ivan Dec 31 '11 at 2:30
add comment

2 Answers

up vote 6 down vote accepted

Like find / -type f > /tmp/list_of_all_the_files.txt ?

share|improve this answer
    
Cool! I thought it was even going to be not a command but a script, and you come up with such a simple perfect solution! –  Ivan Dec 31 '11 at 2:27
add comment

You can run

ls -R | grep ':$' | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/   /' -e 's/-/|/'

It shows all subdirectories niftly formatted as a tree.

Sometimes there is also tree utility available in many linux distributions. If not, then you can install it from here.

It provides following output:

~> tree -d /proc/self/
/proc/self/
|-- attr
|-- cwd -> /proc
|-- fd
|   `-- 3 -> /proc/15589/fd
|-- fdinfo
|-- net
|   |-- dev_snmp6
|   |-- netfilter
|   |-- rpc
|   |   |-- auth.rpcsec.context
|   |   |-- auth.rpcsec.init
|   |   |-- auth.unix.gid
|   |   |-- auth.unix.ip
|   |   |-- nfs4.idtoname
|   |   |-- nfs4.nametoid
|   |   |-- nfsd.export
|   |   `-- nfsd.fh
|   `-- stat
|-- root -> /
`-- task
    `-- 15589
        |-- attr
        |-- cwd -> /proc
        |-- fd
        | `-- 3 -> /proc/15589/task/15589/fd
        |-- fdinfo
        `-- root -> /
share|improve this answer
    
It's better not to parse ls output: link. –  Francesco Turco Oct 14 '12 at 14:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.