How to create copy move or delete files and directories? – quick & easy 3 mins guide!

You are currently viewing How to create copy move or delete files and directories? – quick & easy 3 mins guide!
Photo by Gabriel Heinzer on Unsplash
Share This Post, Help Others, And Earn My Heartfelt Appreciation! :)
4.8
(1072)

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

How to create copy move or delete files and directories?

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 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

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

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. 

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

Removing files and directories

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.

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

If you enjoyed this post please add the comment below and share this post on your Facebook, Twitter, LinkedIn or another social media webpage.
Thanks in advanced!

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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments