简体   繁体   中英

Creating directories and files from TREE command output

I've used a tree command to list recursively about a hundred folders with some 150 files in them. This tree output is saved in a file.

How can I parse this file via bash and recreate these files and folders on a different computer?

Note that I don't need to copy these files. All I need is just the same naming convention on another computer where some custom work will be done.

find will do what you want, something like

find /my/pathto/blah -type d | sed -e "s/^/mkdir -p /g" > commands
find /my/pathto/blah -type f | sed -e "s/^/touch /g" >> commands

The first find will create the instructions to make the directories. The second find will create the instructions to create empty files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM