WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES

How to Copy the Contents of a Folder to Another Folder from Terminal in Ubuntu

Topic: Ubuntu / LinuxPrev|Next

Answer: Use the cp Command

You can use the cp command to copy files locally from one directory to another.

For instance, if you want to copy the contents of the source folder to the destination folder in your current working directory, you can use the following command:

cp -a source/. destination/

The -a option copy files recursively, while preserving the file attributes such as timestamp. The period symbol (.) at end of the source path allows to copy all files and folders, including hidden ones.

For example, if your current working directory is /var/www and you want to copy the contents of the assets folder to backup folder, you can simply use the command:

cp -a assets/. backup/

Alternatively, you can provide absolute path like this:

cp -a /var/www/assets/. /var/www/backup/

Both commands will have the same effect, because current working directory doesn't matter when you use absolute path. Any path that starts with a forward slash / is an absolute path.


Related FAQ

Here are some more FAQ related to this topic:

Bootstrap UI Design Templates Property Marvels - A Leading Real Estate Portal for Premium Properties