We all know we can use tree
to get a nicely formatted text "visualization" of the structure of a directory; say:
$ tree -spugD /usr/include/boost/accumulators/numeric/
/usr/include/boost/accumulators/numeric/
├── [drwxr-xr-x root root 4096 Dec 19 2011] detail
│ ├── [-rw-r--r-- root root 2681 Oct 21 2010] function1.hpp
│ ├── [-rw-r--r-- root root 406 Oct 21 2010] function2.hpp
│ ├── [-rw-r--r-- root root 409 Oct 21 2010] function3.hpp
│ ├── [-rw-r--r-- root root 409 Oct 21 2010] function4.hpp
│ ├── [-rw-r--r-- root root 6725 Oct 21 2010] function_n.hpp
│ └── [-rw-r--r-- root root 530 Oct 21 2010] pod_singleton.hpp
├── [drwxr-xr-x root root 4096 Dec 19 2011] functional
│ ├── [-rw-r--r-- root root 2316 Oct 21 2010] complex.hpp
│ ├── [-rw-r--r-- root root 16627 Oct 21 2010] valarray.hpp
│ └── [-rw-r--r-- root root 12219 Oct 21 2010] vector.hpp
├── [-rw-r--r-- root root 9473 Oct 21 2010] functional_fwd.hpp
└── [-rw-r--r-- root root 21312 Oct 21 2010] functional.hpp
2 directories, 11 files
What I would want, is the reverse of this - given a text file with the contents as above save in dirstruct.txt
, I could write something like this (pseudo):
$ reverse-tree dirstruct.txt -o /media/destpath
... and so, /media/destpath
directory would be created if it doesn't exist, and inside I would get detail
subfolder with files function1.hpp
, etc; as per the tree above.
Of course, I can always do a copy cp -a
and get the same; the idea here would be, that I could change filenames, directory names, sizes, permissions and timestamps in the textfile - and have that reconstructed in the output structure. For files, I first thought I'd be happy with them just being touch
ed (that is, 0 bytes in size) - but it's probably better that the size is reconstructed too - by filling either 0x00 or random bytes, up to the requested size.
Primary use of this would be actually to post questions :)
- some of those rely on a directory structure, say from a program I have installed; but the program in itself is irrelevant to the question; then instead of targetting answerers that may happen to have the program installed, I could simply ask a question in respect to an "anonymized" directory tree, which they themselves could quickly reconstruct on their machines, simply by pasting the tree text description in the post.
So - is there a straightforward way to achieve this?
find
command instead of usingtree
– steeldriver Jul 04 '14 at 12:38