The majority of PC users will have either Windows or Mac as their operating system. The third one, Linux, is preferred by only the programmers and coders. Working in Linux is like using Command Prompt on Windows. It will help if you write a bunch of codes to do anything. For instance, to delete a directory or a Linux file, you need to write a line of code in the Terminal Window. You can’t right-click the file and delete it just like in Windows.

Working in Linux is fun when you know the tips and tricks. This article will instruct you on how to delete a directory on Linux with different codes. With the codes, you can delete or remove a file or a whole folder from your PC.

Delete a Directory in Linux

How to Delete a Directory in Linux (Files)?

The simple way to delete a file in Linux is by executing the below command,

rm linux.txt

This command will delete the file named “linux” if the file is in the working folder. If you want, you can also delete a file from a different folder by providing the path of the file.

rm ./techplip./linux.txt

This command will delete the file named “linux” in techplip folder. You can also delete multiple files at a time by providing more than one file name.

rm linux.txt mypage.txt

This command will delete two files named “linux” “mypage” at once. If you want Linux to provide a warning before deleting a file, you can use the -i (interactive). For instance,

rm -i linux.txt

This will prompt yes or no before deleting the file. You can reply with y for Yes and n for No.

If the file you are going to delete is write-protected, you will be asked for confirmation even without the -i command. In that case, you can reply with y. If you don’t want to have the confirmation, you can use the -f (force) command.

rm -f linux.txt

This will delete the file without asking for any confirmation even though the file is write-protected.

How to Delete a Directory in Linux (Folders)?

If you want to delete an entire folder, you can use the code with -d (directory) command

rm -d linux

This will delete the linux folder. You can also use the interactive (-i) on the folder.

rmdir linux

You can also use the command rmdir. The rmdir command will delete the folder Linux but not the files in the folder. rm will delete both the files and the folder at once. You can use all the commands like -i and -f in the directories too. If you want to delete more than one folder, provide the folder’s names that you want to remove, just you did it for multiple files.

Related: Best Text Editor for Ubuntu Linux

These are the commands and codes you need to know to delete a file or a directory in Linux. Use these commands on the Terminal Windows to delete files and manage your directories. If you want to know any other commands in Linux, let us know in the comments below.