Delete, Copy, Move, and Rename Files using command-line in Linux

Learn how to delete, copy, move, and rename files using command-line in the Linux Terminal. These work on any Linux distro.

If you’re using a Linux operating system, it’s beneficial to learn the Linux Terminal commands as well. It may seem a bit scary at first, but once you get proper guidance and a bit of practice, you get the hang of it. It’s more efficient and faster most of the times.

We’re going to explain today how to delete, copy, move, and rename files using the CLI. We’re going to assume that the readers are familiar with ls and cd commands. If you want to know about the most basic commands of the Linux CLI, visit this link.

Deleting files

Let us start this off by deleting the files!

Deleting files using the Terminal is simple, and generally wrapped up by one command: rm. You can expand rm as remove. In the CLI mode, the only attribute that the rm command requires is the name of the file. For example, if I need to delete a file named ‘test’ which is in my working directory, I have to write:

rm test

And that’s it. Now, some useful options that rm has.

rm -r

First one, the ‘-r’ option. The rm command doesn’t remove any directories that have files in them. The ‘r’ in any basic Linux command (generally) stands for recursive. What that means is that the command will act on any sub-directories or the files contained by a directory, assuming that you run the command on the directory.

So if you require to delete any directory, you have to use the ‘rm -r‘ option. For example, if I have a file test inside the directory testdir, a plain rm command won’t remove it, but with the -r option, it will.

rm -r test.
Deleting directory

rm -f

Next, the -f option. It is the force delete option. It means that the command line will never prompt you about any errors while deleting the files. So, all added up, if you want to delete some files, write the name of the files or directories after rm -rf in the terminal, and they will be deleted.

By default, when a file is created, the user who created it, and the user group of the user have permissions to read and write the file. Others, just to read. For the demonstration of rm -rf, I have created a file named test2 in the same testdir, and changed the permissions, so that no one has the permission to do anything to it.

It is the image for evidence, try to decipher the displayed permissions.

No permissions file.
No permissions file.

Now we delete it:

rm -rf
Force deleting files

Copying files

Next up, copying files. The command used is cp. The cp command requires two attributes. One, the location of the file that you want to copy, and next, the location where you want to copy. Now here, I will copy a file named test3 to the directory testdir.

cp simple command
Simple file copying.

As seen in the output, the file has been copied, and the ls command proves that it’s in the testdir directory. Now again an important option:

cp -r

Yes, the function of the -r is the same here. It copies the files in a directory recursively. If you use plain cp to copy a directory that has files, the cp command will simply omit the directory and move on. So, a -r option is necessary to copy a folder.

cp -r test
Copying directory.

cp -i

The next option is -i. The -i option is called the interactive mode. If you use this option, the CLI will prompt you before copying every file to the destination. If you want to copy, you enter ‘yes’ or just press enter. If you don’t want to copy, enter ‘no’.

For example, here I’ll copy all files in the working directory to the previous directory.

cp -i
Interactive copying

I have used the asterisk(*), which means everything. It is explained in more detail at the end of the article. The ‘..’ means the previous directory. In Linux CLI, the working directory is represented by ‘.’ and the previous directory by ‘..’

Moving and renaming files

Moving and renaming are in the same category because the Linux CLI uses the same command for both of them.


Moving files is similar to copying files. You need to use the command, then the location of the file you want to move, and the destination. The command, in this case, is mv, which naturally means move. But a piece of good news here. The mv command does not require the -r option even to move directories. Here’s an example of moving testdir2 to testdir.

mv command
Moving files

As seen in the image, the testdir2 directory isn’t in the home directory anymore and is in the testdir directory.


For renaming, as you know, the mv command is used as well. So if you notice, Linux doesn’t rename the same file, but moves the file to the same directory again, but with a new name. So it is necessarily the same contents of the file, but the file is new, with a new name.

Here’s an example of the mv command to rename. I will rename the file test as tested.

mv test
Renaming files

So as you can see, the file previously with the name test has now become tested (pun intended).

Terminal Trick

Now, this is a simple trick that can be used to make your tasks much easier and faster. The usage of the asterisk(*). In the Linux CLI, the asterisk means everything. Literally. So, if you want to remove all the files in the working directory, what do you do?

rm -rf *

You are done. All files deleted. It also comes in handy with other commands like cp, mv etc., where you want to apply the command on all files in the directory.

It can be used in another way, to operate on all files using a certain keyword. For example, I will copy all files that have the word ‘test‘ in their names, to the dir directory. The command is:

cp *test* dir

It means copy everything*test*everything to dir.

Usage of *
Using * to copy files.

So, that will be all for this article. Keep checking Terminal Tuts for more such tutorials. Cheers!

Pulkit Chandak
Pulkit Chandak is a Linux enthusiast and has been using and experimenting with open source software and hardware too since a long time. He is a huge admirer of open source software and wants to ventilate it to all around him. He is interested in reviewing and writing tutorials on Linux and its many distributions. He believes that freedom in software leads to freedom of the mind from the chains of limits.


Please enter your comment!
Please enter your name here




How to setup FTP Server on CentOS

You are allowed to use any one of the FTP servers as you like. However, in this tutorial, we will be installing and using vsftpd, short for Very Secure FTP Daemon. It is a fast, stable, and secure FTP server that will help you transfer files to and from a remote system in a jiffy.

CentOS Vs. Ubuntu Server : Everything You Need to Know

Choosing the perfect Linux distribution to set up your server can be confusing since Linux provides a limitless number of options. The main reason behind these many distributions is because Linux is an opensource platform. Anybody with the required skills can contribute to the development or build and release their distribution. Currently, there are more than 600 Linux Desktop and Server distributions in the market.

Top 10 Reasons to use Xfce as your Desktop Environment

There are many choices for desktop environments for Linux based operating systems. Mainly, you can install any DE of your choice on most of the Linux based distributions, even if they are not offered as a package officially. In our recent articles, we discussed the best of KDE and Cinnamon. In this article, we wish to present to you the top reasons why you should consider Xfce as your desktop environment.

The 10 Best Linux Network Monitoring Tools

Having total control over your network is essential to prevent programs from overusing your network resources and slowing down the overall performance. This is why you should install a network monitoring tool on your system, giving you a visual overview of everything that's happening on your network. Networking Tools are like swiss-knife for the system administrators for troubleshooting system issues.

How to install CouchPotato on Ubuntu

Downloading movies and copying them over to your home server can get frustrating, especially if you are doing it daily! What if you have an option to download videos automatically, quickly, and above all with excellent quality. CouchPotato allows you to download movies easily once they are available and released automatically.

Top 20 Rsync Examples in Linux

The Rsync (remote sync) command is a Linux/Unix utility used to synchronize and copy files and directories either locally or remotely. Most Linux geeks use Rsync to mirror, backup or migrate data across folders, across disks and networks. One notable feature with the Rsync command is that it uses the "delta transfer algorithm."


Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

10 Reasons to use Cinnamon as your Desktop Environment

With the release of Gnome 3 in 2011, there was quite a mixed reaction from users and developers. Most of them preferred the original Gnome that got forked, and one of those forks was Cinnamon. Since the release of Cinnamon 2.0, Cinnamon has evolved to become a desktop environment by itself.

What’s New in Ubuntu 20.04 LTS “Focal Fossa”

Ubuntu 20.04 LTS is out now! This is the successor to Ubuntu 18.04, which was released in April 2018 and still has three years of official support left. Code-named Focal Fossa, the new edition has all the bells and whistles included in it, making it one of the best Ubuntu releases yet. Let's find out more.

How to install Android Studio on Ubuntu

Android Studio, like the name suggests, is a full-featured cross-platform IDE that enables you to develop Android applications to run on any android device. Based on JetBrains' IntelliJ IDEA, Android Studio comes installed with all the necessary features needed for Android development.

5 Best Application Launchers for Ubuntu

Ubuntu is one of the most used Linux distributions worldwide. It is also the reason why it has the maximum number of available programs for itself. Today we are going to talk about one category of those programs, the application launchers.