Copy contents of directory include hidden files and hidden directory using cp command.
Copy all contents inside Linux directory include the hidden files and hidden directory using cp command.
The cp command also can be use to copy all files and folder include all the hidden files and hidden directory, this is useful if we want to copy all the directory contents, as example that we want to copy the user home directory for backup.
Step:
• Set shopt dotglobe option to enable.
• Copy hidden files and folder.
• Set shopt dotglobe option to disable.
To demonstrate copying all files including the hidden files and directory, make new directory in the current directory, so that we can use this directory to copy all files and directory to this new directory called test.
[root@fedora ~]# mkdir test
[root@fedora ~]# ls
anaconda-ks.cfg Desktop install.log install.log.syslog mbox passwd test
To copy hidden files or hidden directory in Linux Fedora Core system, you need to set the shopt dotglobe option to enable.
[root@fedora ~]# shopt -s dotglob
On this example, we going to copy and preserve the mode, ownership and timestamps of all directory content of Linux home user directory (home directory for fedoracore5 user) to test/ directory, the -r option is to copy directories recursively
.
[root@fedora ~]# cp -pr /home/fedoracore5/ test/
List all contents of the directory to make sure all files including the hidden files and directory also the hidden directory copied.
[root@fedora ~]# ls -al test/fedoracore5/
total 104
drwxr-xr-x 13 fedoracore5 fedoracore5 4096 May 19 00:29 .
drwxr-xr-x 17 root root 4096 May 19 00:33 ..
-rw-r--r-- 1 fedoracore5 fedoracore5 24 May 19 00:27 .bash_logout
-rw-r--r-- 1 fedoracore5 fedoracore5 191 May 19 00:27 .bash_profile
-rw-r--r-- 1 fedoracore5 fedoracore5 124 May 19 00:27 .bashrc
-rw-r--r-- 1 fedoracore5 fedoracore5 5619 May 19 00:27 .canna
drwxr-xr-x 2 fedoracore5 fedoracore5 4096 May 19 00:29 Desktop
-rw------- 1 fedoracore5 fedoracore5 26 May 19 00:29 .dmrc
drwxr-x--- 2 fedoracore5 fedoracore5 4096 May 19 00:29 .eggcups
-rw-r--r-- 1 fedoracore5 fedoracore5 438 May 19 00:27 .emacs
drwx------ 4 fedoracore5 fedoracore5 4096 May 19 00:29 .gconf
drwx------ 2 fedoracore5 fedoracore5 4096 May 19 00:30 .gconfd
drwxrwxr-x 3 fedoracore5 fedoracore5 4096 May 19 00:29 .gnome
drwx------ 7 fedoracore5 fedoracore5 4096 May 19 00:29 .gnome2
drwx------ 2 fedoracore5 fedoracore5 4096 May 19 00:29 .gnome2_private
drwxr-xr-x 2 fedoracore5 fedoracore5 4096 May 19 00:29 .gstreamer-0.8
-rw-r--r-- 1 fedoracore5 fedoracore5 120 May 19 00:27 .gtkrc
-rw-rw-r-- 1 fedoracore5 fedoracore5 140 May 19 00:29 .gtkrc-1.2-gnome2
-rw------- 1 fedoracore5 fedoracore5 183 May 19 00:29 .ICEauthority
drwxr-xr-x 3 fedoracore5 fedoracore5 4096 May 19 00:27 .kde
drwx------ 3 fedoracore5 fedoracore5 4096 May 19 00:29 .metacity
drwxr-xr-x 3 fedoracore5 fedoracore5 4096 May 19 00:29 .nautilus
-rw------- 1 fedoracore5 fedoracore5 0 May 19 00:29 .recently-used
-rw------- 1 fedoracore5 fedoracore5 497 May 19 00:29 .rhn-applet.conf
-rw------- 1 fedoracore5 fedoracore5 129 May 19 00:29 .Xauthority
-rw-r--r-- 1 fedoracore5 fedoracore5 658 May 19 00:27 .zshrc
[root@fedora ~]#
NOTE:
1 To enable shopt dotglob (option to set):
[root@fedora ~]# shopt -s dotglob
2. To disable shopt dotglob (option to unset):
[root@fedora ~]# shopt -u dotglob
Related:
Copy Linux Files and Directory Using cp Command.
Keywords: copy hidden file, copy hidden folder, copy hidden directory, shopt command, shopt dotglob, copy directory contents, copy contents of directory, enable shopt dotglob, disable shopt dotglob, set dotglob, unset dotglob, linux copy directory, linux copy hidden directory.
- 33275 reads
- Email this page
Recent comments
9 years 2 days ago
9 years 4 weeks ago
9 years 16 weeks ago
9 years 23 weeks ago
9 years 33 weeks ago
9 years 36 weeks ago
9 years 43 weeks ago
9 years 50 weeks ago
10 years 2 weeks ago
10 years 7 weeks ago