How to copy entire directories and exclude specific files on Unix

I have a Unix script package that copies the contents of one directory (calls it dir A) to another (calls it dir B).

Here is the copy statement that I have.

cp -urL /path/to/dir/A /path/to/dir/B 

However, this statement copies hidden files.

How can I exclude the possibility of copying all and all hidden files?

+4
source share
2 answers

Put an asterisk (*) to copy, but ignore hidden files

 cp -urL -r /path/to/dir/A/* /path/to/dir/B 
+6
source

If you use bash as a shell, disable the dotglob shell dotglob .

From man bash

dotglob If set, bash contains file names starting with the character '.' into the results of the extension of the path.

 #!/bin/bash shopt -u dotglob cp -urL /path/to/dir/A /path/to/dir/B 
+3
source

Source: https://habr.com/ru/post/1343669/


All Articles