linux copy file command (cp) trick

1. Directory Copy

    a. Copy from the source directory to the target directory, and the target directory has the same name as the original directory

    

# For example, the source directory is /home/root/www, copy to /home/root/backup/www
# In this case, the backup directory must exist first.
mkdir -p /home/root/backup
cp -a /home/root/www /home/root/backup

   b. Copy all files from the source directory to the target directory, but do not create a new directory

  

# For example, the source directory is /home/root/www, copy to /home/root/backup
# If the backup directory exists, add the -T option
cp -aT /home/root/www /home/root/backup
# If the backup directory does not exist, no need to add -T, the directory backup will be created automatically after copying
cp -a /home/root/www /home/root/backup

 

2. Copy hidden files in a directory

#Hidden files start with .,
#Cannot be written as .*, this will copy the .. directory, that is, copy the contents of the parent directory
cp /path/of/source/.[^.]* / www

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326683656&siteId=291194637