DEV Community

Cover image for Living in the Shell #11; cp (Copy Files/Directories)
Babak K. Shandiz
Babak K. Shandiz

Posted on • Originally published at babakks.github.io on

3 3

Living in the Shell #11; cp (Copy Files/Directories)

cp 🏭

Creates copies of files and directories.

⚠️ Default behavior is to overwrite destination files.

Copy single file

cp ~/.bashrc ~/.bashrc-copy
Enter fullscreen mode Exit fullscreen mode

Copy multiple files into a new directory -t

cd ~ && cp .bashrc .zshrc target-dir
cd ~ && cp -t target-dir .bashrc .zshrc
Enter fullscreen mode Exit fullscreen mode

Both create target-dir directory and copy .bashrc and .zshrc into it.

Copy by wildcard selection -t

cd ~ && cp -t target-dir *.zip *.txt
Enter fullscreen mode Exit fullscreen mode

Copies all .zip and .txt files to target-dir directory.

Copy a directory -r

cp -r ~/.config ~/.config-copy
Enter fullscreen mode Exit fullscreen mode

Update only newer files -u

cp -ru ~/.config ~/.config-last-backup
Enter fullscreen mode Exit fullscreen mode

This just copies files that modified after the last copy.

Create backup for existing destination files -b

cp -rb ~/.config ~/.config-last-backup
Enter fullscreen mode Exit fullscreen mode

Set to ask for overwriting -i

cp -ri ~/.config ~/.config-last-backup
Enter fullscreen mode Exit fullscreen mode

Set to keep existing files (no overwrite) -n

cp -rn ~/.config ~/.config-last-backup
Enter fullscreen mode Exit fullscreen mode

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

Try REST API Generation for Snowflake

DevOps for Private APIs. Automate the building, securing, and documenting of internal/private REST APIs with built-in enterprise security on bare-metal, VMs, or containers.

  • Auto-generated live APIs mapped from Snowflake database schema
  • Interactive Swagger API documentation
  • Scripting engine to customize your API
  • Built-in role-based access control

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay