How to copy and rename files from the Linux terminal window

How to copy and rename files from the Linux terminal window

/>

X

Tech
Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process

‘ZDNET Recommends’: What exactly does it mean?

ZDNET’s recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET’s editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.

Close

How to copy and rename files from the Linux terminal window

Copying and renaming files on Linux is a task that can be done from within a GUI, but sometimes you just want the speed and simplicity of doing it from the terminal window. Here’s how.
Person using a laptop

PixelsEffect/Getty Images

When you first start using Linux, you’ll most likely be glued to the GUI. That’s not only totally understandable but acceptable. There is no shame in not using the command line. In fact, you could go your entire Linux life without ever touching the terminal window.

But for some tasks, the terminal is simply more efficient. The only difference to using the GUI is that you have to remember the commands to use. 

Also: How to replace Windows with Linux Mint on your PC

I want to help you with this process. In fact, my goal all along is to make Linux easy to understand for the masses. As part of that effort, I like to include the command line interface (CLI) because there’s so much you can do with it. 

With that in mind, let’s start with two very simple but handy commands for copying and renaming files.

Ready to type?

How to copy a file

What you’ll need: The only thing you’ll need for this process is a running instance of Linux. It won’t matter what distribution you use, as the two commands I’m going to show you are included with every version of Linux you’ll encounter.

1. Open a terminal window

The first thing to do is open a terminal window. To do this, open your desktop menu and either search for “terminal” or navigate through the default menu until you find the terminal listed. The name of this app will will depend on the desktop you’re using. 

Also: The best Linux distros for beginners

Fortunately, most desktops use fuzzy searching, so if you type terminal in the menu search field, it should appear (whether it’s Konsol, Terminal, Tilex, or any number of options). The good news is most Linux terminals work the same way.

2. Copy a file

Let’s say you have a file named zdnet_test.txt in your home directory and you want to copy it to your Documents directory. The command for that process would be:

cp ~/zdnet_test ~/Documents/

One thing to note is that ~/ is a shortcut for /home/USER (where USER is your username), so you don’t have to type as much. 

Also: How to choose the right Linux desktop distribution

If you were already in your home directory (which your terminal app should default to when you first open it), you could short the command to:

cp zdnet_test Documents

How to rename a file

Let’s now rename a file.

1. Renaming while copying

You can rename a file, while copying it. Let’s say you want to copy zdnet_test to Documents, but also rename it to zdnet.test. For that, the command would be:

cp zdnet_test Documents/zdnet.test

Remember, the above command would only work if you were already in your home directory, otherwise you’d need to add ~/ on both ends, like so:

cp ~/zdnet_test ~/Documents/zdnet.test

2. Renaming while moving

You can also rename a file when moving it. This process is almost the same as above, but you’re not copying a file to another directory, you’re moving it. 

Also: How to enable Linux on your Chromebook

This task is accomplished with the mv command. We’ll stick with our example. Say, you have zdnet_test in your home directory, and you want to move it to Documents and rename it to zdnet.test at the same time. The command for this process is:

mv zdnet_test Documents/zdnet.test

Remember, if you’re not already in your home directory, that command would be:

mv ~/zdnet_tst ~/Documents/zdnet.test

And that’s all there is to renaming a file in Linux. This is a very basic task that you can use to get accustomed to the Linux CLI…but only if you feel the need to start broadening your understanding of the open-source operating system. Otherwise, stick to the GUI.

Editorial standards

Add a Comment