Copying Directories
Explore how to copy directories in the command-line interface by using the cp command with and without the recursive -r option. Understand how to duplicate directory contents including subdirectories, handle destination paths, and avoid nested copies to effectively manage files and backups.
We'll cover the following...
We'll cover the following...
Simple copy
When we copy a directory, we’re duplicating its contents, including all files and subdirectories. Let’s demonstrate by making a backup of the code directory in our structure. Try copying files/code to files/backups/code:
mkdir -p files/{movies,music,photos,docs/{diagrams,markdown},code/{go,js,elm}}
touch files/docs/markdown/chapter{1..3}.md
mkdir files/backups
clear
cp files/code files/backups/code
...