0

I am looking for a way to copy a folder, with all the invisible and system files it contains in its "first level", but only some of the other visible, "normal" folders it contains? This is related to a "Time Machine" data transfer, from an old disk to a new one. But I think it is a question interesting in its own.

  • You could do this with rsync and it's --include and --exclude options. – fd0 Aug 23 '15 at 15:36
2

First create a new folder where you will copy the data to: mkdir <dest_folder>. Then use:

# "First level" hidden files
find <source_folder> -d 1 -name ".*" -print0 | xargs -0 -J % cp -R % <dest_folder>
# Normal folders
cp -R <source_folder>/<folder1> <source_folder>/<folder2> ... <dest_folder>
  • cp -r <source_folder>/.* can cause the current working directory to be copied to the destination. Much safer to shopt -s dotglob; cp <source_folder>/* <dest_folder>. Then a second copy with the -R option for any folders. – fd0 Aug 23 '15 at 17:46
  • Interesting. In fact, it will even include <source_folder>/... I didn't notice since i use zsh, which will not include . and ... However, your suggestion will not copy any hidden directories until you explicitly pass them to the second cp -R. It will also copy possibly unwanted non-hidden files in the source directory. – madmax1 Aug 23 '15 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .