Tuesday, October 10, 2017

linux - using "touch" to create directories?




1) in the "A" directory:

find . -type f > a.txt

2) in the "B" directory:
cat a.txt | while read FILENAMES; do touch "$FILENAMES"; done

3)
Result: the 2) "creates the files" [i mean only with the same filename, but with 0 Byte size] ok. But if there are subdirs in the "A" directory, then the 2) can't create the files in the subdir, because there are no directories in it.

Question: is there a way, that "touch" can create directories?


Answer



What is your desired end result?



If you are trying to duplicate a directory structure there are easier ways. Syncing solutions come to mind first.



e.g.



rsync -a /source/dir/ /dest/dir/ --include \*/ --exclude \*



This will recreate the entire directory structure. You can then run your touch command to finish the rest.



As previously mentioned we may be able to find a more elegant solution if we know the full problem :)


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...