How to Copy, Move and Delete Files in Linux?

Copying files from one place to another, moving files from one directory to another and deleting files from one place to another.

Sounds so simple for those who have a habit of using control+c, control+x and delete options.

However, in the Linux world, you need to know certain somethings.

Certain some things include knowing some directory commands for copying, moving and deleting files in Linux.

How to Copy, Move and Delete Files in Linux?

Now, my friend you are going to ask me, how is that even difficult?

Simple go to the graphical interface of Linux system and quickly copy, move or delete files.

Though, my friend, I ask you one question.

What would you if you have to copy multiple files, certain files to be precise with the similar end name?

For instance, you have to copy john_salary, neon_salary and juuso_salary at a time, what would you do?

Here is when I come in to help you out by letting you learn about the copy directory command, Linux mv directory and other necessary things that might help you big time in future.

Before starting out, take a paper and a pen and note these three general commands:

Copy: cp file_name <directory|file_name>;
Move: mv file_name <directory|file_name>;
Delete: rm file_name

Coming back to the point now, Linux is designed in a way to make each one of its command more productive and come of more use to you.

How? Have patience. At the end of this article, you’ll know every piece of knowledge that you should know.

Moving Files

Starting things out with moving, here you have to use the mv command that allows the user to move a file from one directory location to another.

Guess what? You can also rename the file without using any other special rename command!

Back to basics, like I asked you to note it down, the command is used in this general format:

 mv file_name <directory|file_name>

In the above case, say you have to move neon_salary to another directory.

Simple tweak the general format as:

 mv neon_salary

All you did was move all the content of neon_salary to neon1_salary using the move command. The location of the file stays same, however, the name is changed now.

Now, how can you tweak the mv command?

-f: Using the force command, you can override all the interactivity and in the end execute the mv instruction without expecting the return of any prompts.

-v: Using the verbose command, you can see the files being one by one to the directory of your choice.

-i: Using the interactive command, the system asks you if you are okay with overwriting an existing file before moving the file in contention.

Copying Files

Like moving a file, copying a file is a no big deal either. However, never forget the basics.

 cp file_name <directory|file_name>

Let us once again study the command with an example:

cp juuso_salary salary

In this case, you just copied the juuso_salary file to the salary directory.

Now, how can you tweak the cp command?

-i: Using the familiar interactive command, the system asks you to confirm if you are okay with over writing an existing file in the process. -v: Using the familiar verbose command, you can watch files being copied one by one. -r: Using the recursive command, you can copy every subdirectory and file in a specific directory preserving the tree structure during the process.

Deleting Files

Back to the basics, friend:

 rm file_name

Taking an example:

 rm john_salary

In this case, you just zapped out all the content from the file and deleted it. Not something John would cherish though.

For tweaking the command, you can use the -i, -r, -f and -v command. THey have the same use.

Now, back the initial question, how do you copy, move or delete files with the similar end name?

Simple, you cash in the wildcard!

The wildcard character “*” to perform the above-mentioned actions with ease. Don’t know how to use it? Don’t worry, you will.

For deleting:

 rm *_salary

For copying

 cp *_salary expense

For moving

 mv *_salary expense

There you go, as easy as ever. Using this commands is never going to be a headache for you by any means. Though, ensure that you should use these commands with caution. Especially the wildcard character, be cautious.

Also, beware of the -r command. Using it with the delete directory command can you have a very big headache.

 rm -r *

This command will delete every file from every directory of your system. Would you like that? Absolutely not. Thus, never forget to be cautious.

Have a fun time copying, moving and deleting files using these commands. Stay away from disasters. If you have any questions, feel free to contact us, we’ll revert to you as soon as we can and help you out.

Leave a Reply

Your email address will not be published. Required fields are marked *