Copy Hidden Files and Hidden Directories ONLY in /home Using Command Line

by mirza irwan osman in Circuits > Linux

3219 Views, 5 Favorites, 0 Comments

Copy Hidden Files and Hidden Directories ONLY in /home Using Command Line

220px-Tux.svg.png

I spend an hour trying to copy hidden files and directories under /home directory using the much loved 'cp' command. What is so hard about copying? It's chicken feet! But not when it comes to copying hidden files and directories under /home directory. So this instructable is more of a reminder to me than me wanting to teach.

Hidden files and hidden directories under /home directories are important in controlling the preferences of the applications installed in the system. Therefore backing up hidden files and directories is an important task.

My backup requirement:

  • First-level hidden directories will be copied.
  • First-level hidden files will be copied.
  • Hidden directories of type Symlinks will not be copied
  • Hidden files of type Symlinks will not be copied
  • First-level directories that are not hidden but contains hidden files will not be copied

Find and Copy Hidden Files and Hidden Directories ONLY

Decide your source directory to copy from. For example /home/john_doe

Decide your destination directory to copy to. For example /media/usb_drive

Open Terminal Emulator

Enter the following command:

find -H /home/john_doe -maxdepth 1 -name '.??*' -a \( -type d -o -type f \) -exec cp '{}' -R /media/usb_drive \; 

OR

find -H /home/john_doe -maxdepth 1 -path './.*' -exec cp '{}' -R /media/usb_drive \;