Linux: How To Create Copy Move Or Delete Files And Directories? – Quick & Easy 3 Mins Guide!

How to create copy move or delete files and directories? - quick & easy 3 mins guide!
Photo by Gabriel Heinzer on Unsplash
Share this post and Earn Free Points!

In this post I will show you how to create copy move or delete files and folders at Ubuntu" operating system.

Introduction

Linux

Linux" is a free and open-source operating system that is based on the Unix kernel and is used on a variety of devices, including computers, servers, and smartphones. It is known for its stability, security, and flexibility, as users can customize and configure their systems to meet their specific needs.

Linux" is used in a range of environments, including enterprise settings, and it is developed and maintained by a global community of volunteers and companies.

There are many different distributions, or “flavors,” of Linux" available, such as Ubuntu", Fedora, CentOS", and Red Hat Enterprise Linux", which offer different features and user" experiences. In summary, Linux" is a widely-used and popular operating system that is known for its reliability, security, and versatility.

How To Create Copy Move Or Delete Files And Directories?

Create File

Usually files are created by specific programs, but if need create empty files you need use touch command and file name as a parameter:

touch file_name

You can also create a new file and open" it in a text editor at the same time by using the “nano” or “vi” command, followed by the file name. For example:

nano myfile.txt

This will open" a new, empty file called “myfile.txt” in the Nano text editor, where you can enter and edit the contents of the file.

You can also create a new file using the “echo” command, followed by the desired contents of the file and the “>” operator, followed by the file name. For example:

echo "This is the content of my file" > myfile.txt

This will create a new file called “myfile.txt” with the specified contents.

Overall, there are many ways to create a new file in Linux", depending on your specific needs and preferences.

Create Directory

You can create a directory using mkdir command with the directory name as a parameter:

mkdir directory_name

Remember that you cannot create two directories with same name at the same location. If you try do this, you get a following error message:

mkdir: cannot create directory 'directory_name': File exists

Let’s look at the some parameters for the mkdir command:

  • -m – this option allow us set the files mode e.g.permissions
  • -v, –verbose – information if directory was created
  • -p – allow us creating the parent folders

e.g.: creating directory with name folder1, permissions 111 (execute option for owner, group and others) and displaying information if directory was created

mkdir -m 111 -v folder1

Files Copy Command In Ubuntu

At Ubuntu operating system coping files and directories are run with the same command – cp. You need to put to the command the name of the file or folder and the destination directory. It also possible to copy files or folders with different name at the destination folder, e.g.:

cp file1 directory1/file2

The above command copies file1 to directory1 and changes the name of the file1 to file2 at the destination folder. 

Let’s look at the some parameters for the cp command:

  • -b, –backup – if you copy the file which exists at the destination directory, you can create a backup of the previous file
  • -f, –force,  – if you copy the file which exists at the destination directory, it will be overwritten without notice
  • -i, –interactive – if you copy the file which exists at the destination directory, system will ask you if you want to replace the existing file (y means yes)
  • -v, –verbose – the information if directory or files was copied

You can also copy multiple files at once by specifying the source files as a list, separated by a space. For example:

cp file1.txt file2.txt destination/

This will copy both “file1.txt” and “file2.txt” to the “destination” directory.

You can also use the “-r” option to copy directories and their contents recursively. For example:

cp -r source destination

This will copy the “source” directory and all of its contents to the “destination” directory.

Moving Files Or Directories In Ubuntu

For moving files or directories you also need know only one command – mv. This command also help you at changing files or directories name, e.g.:

mv file1 file2

The above command changes the name of file1 to file2. Remember that if file1 and file2 exists, you can lost the content of file2. 

For example, to move a file called “file.txt” from the current directory to a new directory called “destination”, you can use the following command:

mv file.txt destination/

This will move the file “file.txt” from the current directory to the “destination” directory.

You can also move multiple files at once by specifying the source files as a list, separated by a space. For example:

mv file1.txt file2.txt destination/

This will move both “file1.txt” and “file2.txt” to the “destination” directory.

You can also use the “-r” option to move directories and their contents recursively. For example:

mv -r source destination

This will move the “source” directory and all of its contents to the “destination” directory.

The parameters for the mv command are very similar like for cp command.

Removing Files And Directories In Ubuntu

For removing files, you need rm command, but for directories – rmdir. However, running rmdir command only allows you to delete empty directories. Deleting non-empty directories requires the use of the rm command with the -r parameter, which allow us for recursive removal. (create copy move or delete files)

In Ubuntu, you can use the “rm” command to remove files and directories, as described above. For example, to remove a file called “file.txt”, you can use the command:

rm file.txt

To remove a directory called “dir”, you can use the command:

rm -r dir

Let’s look at the below parameter for rmdir command:

  • –ignore-fail-on-non-empty – we won’t be informed of an attempt to remove a non-empty directory
  • –verbose – we will be informed about removing the directory or not if it was not empty

For the rm command we have the following parameters:

  • -r, -R, –recursive
  • -f, –force
  • -i, –interactive
  • -v, –verbose

Summary

Overall, there are many ways to create a new file in Linux", depending on your specific needs and preferences.

The “cp” command is a useful tool for copying files and directories in Ubuntu Linux", and it offers a range of options for specifying the source and destination of the copy operation.

This tutorial" coves topics:

  • create directory Linux"
  • create folder Linux"
  • Linux" create directory
  • delete file ubuntu
  • ubuntu delete file
  • ubuntu delete directory
  • copy file and create directory
  • remove directory ubuntu
  • delete directory ubuntu

That’s all about how to create copy move or delete files! Enjoy!

Could You Please Share This Post? 
I appreciate It And Thank YOU! :)
Have A Nice Day!

How useful was this post?

Click on a star to rate it!

Average rating 4.8 / 5. Vote count: 1072

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?