The cp command
The cp command copies files. Here's the basic syntax:
cp [options] source-file destination-file
The following list describes the more important options for the ls command:
- -a: The same as -dpR.
- -b: Makes backup copies of existing files before they're overwritten. Sounds like a good plan to me.
- -d: Copies links rather than the files the links point to.
- -f: Removes files that will be overwritten.
- -i: Interactively prompts for each file to be overwritten.
- -l: Creates links to files rather than actually copying file contents.
- -p: Preserves ownership and permissions.
- -R: Copies the contents of subdirectories recursively.
- -s: Creates symbolic links to files rather than actually copying file contents.
- -u: Replaces destination files only if the source file is newer.
To make a copy of a file within the same directory, use cp like this:
$ cp sendmail.cf sendmail.cf.backup
If you want to copy a file to another directory without changing the filename, use cp like this:
$ cp sendmail.cf /home/doug
You can use wildcards to copy multiple files:
$ cp send* /home/doug
To include files in subdirectories of the source file, use the -R switch, like this:
$ cp -R /etc/*.cf /home/doug
In this example, all files in the /etc directory or any of its subdirectories that end with .cf are copied to /home/doug.
In this tutorial:
- Linux Commands
- Command Shell Basics
- Editing commands
- Wildcards
- Redirection and piping
- Environment variables
- Shell scripts
- Directory and File Handling Commands
- The cd command
- The mkdir command
- The rmdir command
- The ls command
- The cp command
- The rm command
- The mv command
- The touch command
- The cat command
- Commands for Working with Packages and Services
- The rpm command
- Commands for Administering Users
- The usermod command
- The chage command
- The passwd command
- The newusers command
- The groupadd command
- The groupdel command
- Commands for Managing Ownership and Permissions
- The chgrp command
- The chmod command
- Networking Commands
- The ipconfig command
- The netstat command
- The ping command
- The route command
- The traceroute command