WriteBash - With a file manager, we can drag and drop a file from one directory to another, copy and paste files, etc. So why use these old command line programs? The answer is power and flexibility. While it is easy to perform simple file manipulations with a graphical file manager, complicated tasks can be easier with the command line programs. And in Linux, to copy files or directories, you will use the
Use simple cp
cp command is quite simple, you call the
cp command under the command structure below, the source and destination here may be the name (or path) of the file or directory.
cp source destination
For example, I would copy the
install.log file into a second file named
These special characters are called wildcards. Using wildcards (which is also known as globbing) allows you to select filenames based on patterns of characters. The table below lists the wildcards and what they select.
|*||Matches any characters|
|?||Matches any single character|
|[characters]||Matches any character that is a member of the set characters|
|[!characters]||Matches any character that is not a member of the set|
|[[:class:]]||Matches any character that is a member of the specified|
Table below lists the most commonly used character classes:
|[:alnum:]||Matches any alphanumeric character|
|[:alpha:]||Matches any alphabetic character|
|[:digit:]||Matches any numeral|
|[:lower:]||Matches any lowercase letter|
|[:upper:]||Matches any uppercase letter|
Use cp command with wildcards
Here are some examples using the
cp command with wildcards:
- The first example: copy all files/folders in the folder
/rootto the directory
cp * /home
- The second example: copy all files beginning with the
cp install* /home
- The third example: copy files starting with
cp [ad]* /home
To show more options, run command below:
cp command to make copying in Linux is easy, but very effective in difficult cases that you can not do with graphics management.
If you appreciate what we share in this blog, you can support us by:
- Stay connected to: Facebook | Twitter | Google Plus | YouTube
- Subscribe email to recieve new posts from us: Sign up now.
- Start your own blog with SSD VPS - Free Let's Encrypt SSL ($2.5/month).
- Become a Supporter - Make a contribution via PayPal.
- Support us by purchasing Ribbon Lite Child theme being using on this website.
We are thankful for your support.