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.
- Add new comment
- 25398 reads
- Email this page
Thanks for Reading and Check Other Popular Linux Topics
All time:
- Configure and Setup Squid Cache Proxy Server on Fedora Core.
- Using Linux rm command to delete, remove hidden files and folder - Basic Linux Command.
- Copy Linux Files and Copy Directory Using cp Command - Linux Basic Command.
- Moving or rename files and directory using Linux mv command - Basic Linux Command.
- Add, view, edit and configure route and static route on Linux Fedora Core - Linux Server Configuration.
- Get and display the size of file and directory in Linux system using du command.
- Step by step Install Setup and Configure Linux Fedora Core Server and Network Management with Screen Shot and Example.
- Create file and display file contents in Linux using cat command.
- Configure Squid to block HTTP request to specific web sites.
- Example of samba smbpasswd file and samba smbusers configuration file.

Recent comments
6 hours 20 min ago
21 hours 43 min ago
2 days 13 hours ago
4 days 18 hours ago
5 days 3 hours ago
5 weeks 3 days ago
9 weeks 3 days ago
14 weeks 1 day ago
14 weeks 1 day ago
14 weeks 6 days ago