How to copy (and paste) files and folders from the Linux command line
Copying and pasting files is one of the most basic things you can do on your computer. On Linux, you have several options to accomplish this. On the command line, everything takes place more directly, allowing you more control and in some cases, simplifying things significantly.
Copy a single file
Whenever you want to copy a file or directory in the Linux command line, you will use the cp command . cp stands for copy. The syntax is also simple. Use cp followed by the file you want to copy and the destination where you want to reach the copy.
cp your-file.txt ~/Documents/
Of course, the above command assumes that your file is in the same directory you are working on. You can specify both the original file location and where you want to place the copy.
cp ~/Downloads/your-file.txt ~/Documents/
You also have the option to rename your file while copying it. Specify a new name at the destination.
cp ~/Downloads/your-file.txt ~/Documents/new-name.txt
Refer to the article: How to copy and rename files in Linux for more details.
Copy a directory and its content
To copy a directory and its contents, you will need to issue cp to copy. This is quite simple with the -r flag .
cp -r ~/Downloads/pictures-directory ~/Pictures/family-vacation-pics
All the rest of the syntax is identical. Flag -r is used to inform cp that it is working with a directory and must copy its contents.
Copy multiple files
You can also copy multiple files. The Linux command line allows you to target multiple items at once with brackets {} . You can use them to list the names of each file that will be copied with commas.
cp ~/Downloads/{file1.txt,file2.jpg,file3.odt} ~/Documents/
All 3 files are in different file types and will be copied into the Documents folder .
Copy all files of the same type
If you have a lot of files of the same type to copy, you can use wildcards * . This asterisk or wildcard requires the Linux command line to take care of everything placed there. So if you tell Linux to copy * .jpg , it will copy all JPG files, regardless of the name or anything that appears before the .jpg extension.
cp ~/Downloads/*.jpg ~/Pictures/
If you want to use a variety of files, assume JPG and PNG, you can use curly braces {} .
cp ~/Downloads/*.{jpg,png} ~/Pictures/
Move a file or folder
If you're looking to move a file from one place to another, but don't make a copy, you can do it easily, but moving a file requires using the mv command . The syntax is very similar to cp.
mv ~/Downloads/your-file.txt ~/Documents/
Similarly, you can also rename it.
mv ~/Downloads/your-file.txt ~/Documents/renamed.txt
There is a big difference between cp and mv. You do not need the -r flag to move the entire directory.
mv ~/Downloads/downloaded-folder ~/Pictures/vacation-pics
That's all it takes to copy (and paste) files and folders from the Linux command line. You are ready to start copying and moving your files from the command line! You may find that using the command line can be very effective in some situations. However, in other situations, using the GUI will be easier. After working with Linux for a while, you will find out what is the best option for you.
Hope you are succesful.
You should read it
- How to check whether a Linux PC is 64-bit or 32-bit by command line
- 5 reasons why people love the Linux command line
- How to print from the Linux command line
- How to manage Linux services using Systemd
- Basic Linux commands everyone needs to know
- Instructions for using find command in Linux
- How to find the MAC address using the command line in Linux
- How to use the which command in Linux
May be interested
- Update Linux kernel on Ubuntu via UKUUlinux kernel on ubuntu is the core of this operating system. it is the intermediate interface between computer hardware and software applications.
- 10 new features of Linux Ubuntu 19.04the following article summarizes the top 10 new features of ubuntu 19.04 'disco dingo'. let tipsmake.com find out what they are and how much ubuntu 19.04 can surprise you!
- 5 great Linux laptops you can buy nowthe best linux laptops run very smoothly, but not any random computer you install linux for has such a good experience.
- The difference between Ubuntu and Ubuntu-based distributionsjoin tipsmake.com to learn the difference between ubuntu and ubuntu-based distributions, as well as why it's important.
- How to install Plex media server on Ubuntu 19.04are you looking for the easiest and easiest method to install plex media server on ubuntu 19.04? this is the snap command that will set up your plex server.
- Compare Debian and Ubuntuyou may have heard that ubuntu is based on another distribution, debian. so which distribution should you choose? which distribution is easier to fit with many different use cases?