Copying and Moving Files Using Ubuntu Terminal
To be an Ubuntu power user, you must learn the command line. This is the most powerful part of Ubuntu that you can do almost everything from the terminal without the GUI.
In this tutorial we are going to learn how to copy and move files using Ubuntu terminal.
This is a step-by-step tutorial on learn how to copy and move files using Ubuntu terminal. To follow this tutorial, you need to have the following requirements:
• A computer with Ubuntu operating system installed.
• Basic knowledge of Ubuntu terminal. With basic I mean, how to open a terminal on Ubuntu and how to execute commands.
First open the terminal of your Ubuntu operating system. You can open your terminal by pressing Control, Alt and T at the same time. You can also go to the Unity dashboard and search by the keyword “Terminal” and click on the terminal. Or you can right click on the Desktop and click on “Open Terminal”.
Copying file with ‘cp’ command:
If you want to copy a file on Ubuntu, you have to use ‘cp’ command. ‘cp’ command basically generally takes two arguments, a source, and a destination.
“cp source_file_path destination_file_path”
For example, suppose you have a file, “mysong.mp3” on your Desktop, and you want to copy it to “Downloads” folder of your Home directory.
You use the following command,
“cp ~/Desktop/mysong.mp3 ~/Downloads/mysong_copy.mp3”
Now, we can verify that the file is copied to the destination path using ls command,
Moving a file using ‘mv’ command:
To move a file on Ubuntu from the terminal, you use the ‘mv’ command. ‘mv’ generally takes two arguments, the first one is the source file path, and the second is the destination file path. Source file path is the path of the file you want to move. Destination file path is the location where you want the file to be moved.
Suppose you have google-chrome deb file on Downloads folder and now you want to move it to your Desktop. You use the following command,
“mv ~/Downloads/google-chrome-stable_current_amd64.deb ~/Desktop”
Now let’s verify that the file is really moved to the Desktop. We will use the ‘ls’ command to list the contents on Desktop and Downloads folder.
Google-chrome deb file is not located in Downloads folder anymore. It’s now on the Desktop.
Making identical directories using ‘rsync’ command:
‘rsync’ is the best utility for making identical directories on local and remote computers. That is if you have a directory with lots of files and you want to have a copy of it somewhere on your filesystem, you can use the ‘rsync’ command.
An example of rsync would be to copy all the configuration files under /etc directory to another directory. To do that, first we need to create a folder where we want to copy everything. Let’s call it, “etc_copy”. use the following command to create it,
Now let’s run ‘rsync’,
“sudo rsync -a /etc/ etc_copy”
Now let’s list the directory contents of “etc_copy”
That’s how you use the rsync command on Ubuntu and any other Linux distro.