How to Remove Directory in Linux by command and GUI Guide for beginners

Vijay Kumar
3 min readJul 29, 2020

Are you a new user of Linux OR You are trying to delete a directory in Linux, and getting error “Directory is not empty”

Don’t worry anymore. This article will help learn “ How to remove directory in Linux step by step by using a command-line interface and graphical interface both.

Content

How to remove Directory in Linux

Reading this article is showing your interest to learn new thing, After completing this section you will learn how to remove an empty directory in Linux by using commands.

rmdir command is used to remove an empty directory. Syntax is very simple as follow

$rmdir /dirctory_path

If the directory is not empty, rmdir command will not remove it. you will get the error “Directory is not empty”. In the next section, you will learn how to remove the directory with its content.

rm is another command to use remove file and directory, but you must tell to rm you are removing a directory. Syntax is:

$rm -d /Directory_path

You don’t need to give the path if you are removing directory from the current directory.

See Examples:

How to remove Directory with its content

By now you can easily remove an empty directory. I have directory name old_data is not empty. You have seen in the last section.

Use -r option with rm command.

$rm or /Directory_Path

You should not go through mistakes

Using -r option is not enough to remove the directory with its content. I will remove everything forgiven directory without your confirmation. If you run this command by mistake you will repent only.

Use -ir option with rm command, it will better for you. If you are working as a system administrator and have much responsibility.

[email protected]:~/Documents $rm -ir old_data/ rm: descend into directory 'old_data/'? y rm: remove regular empty file 'old_data/file5.doc'? y rm: remove regular empty file 'old_data/file1.doc'? y rm: remove regular empty file 'old_data/file4.doc'?

How to remove multiple directories at the same time

If you want to remove multiple directories at the same time then you can use rm command respectively followed by -r/-ir option as per your requirements.

The syntax is simple:

$rm -ir First_Directory Second_directory Third_Directory

If you want to remove multiple directories have a different locations. You should not worry anymore.

Go through the following example.

[email protected]:~/Documents $rm -ir /home/vijay/Downloads/dir_2/ /home/vijay/Videos/dir_1/ rm: remove directory '/home/vijay/Downloads/dir_2/'? y rm: remove directory '/home/vijay/Videos/dir_1/'? y[email protected]:~/Documents $

How to remove directory by using GUI

Most computer users love the graphical interface. It is easy to learn and easy to use.

Delete option is not available in Linux, Here is another option to delete directory called a move to trash.

Video: How to remove directory in Linux in Hindi Langugage

Conclusion

By now you are an expert to remove the directory and have good knowledge of using rm and rmdir commands.

The important thing, you should remove the directory safely by using the command line.

If you have any questions, please write in the comment box. For any specific discussion please Join our Group HERE

Originally published at https://www.cyberpratibha.com on July 29, 2020.

--

--