I have two directories and one is empty.
The first directory has many sub directories with hidden files. When I cp -r
content from first directory to the second one, the hidden files gets copied too. Any solutions to escape them?
at end of the source path is a specific cp syntax that allowes to copy all files and folders, including hidden ones.
We can copy hidden files and folders in Ubuntu distribution through cp command-line utility. In addition to, other cp command-line utility options would also be discussed. It is worth mentioning here that, cp command only copies files (not folders) by default.
cp does not delete files. it does in that it overwrites dirA/dir1 with dirB/dir1, rather than just copying the files in that folder.
Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option. The command above creates the destination directory and recursively copy all files and subdirectories from the source to the destination directory.
You can use rsync
instead of cp
:
rsync -av --exclude=".*" src dest
This excludes hidden files and directories. If you only want to exclude hidden directories, add a slash to the pattern:
rsync -av --exclude=".*/" src dest
You can do
cp -r SRC_DIR/* DEST_DIR
to exclude all .files and .dirs in the SRC_DIR level, but still it would copy any hidden files in the next level of sub-directories.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With