TechJunkie is a BOX20 Media Company

Home PC Windows How To Delete a Directory in Linux

How To Delete a Directory in Linux

How To Delete a Directory in Linux

Want to know how to delete a directory in Linux and learn a few other basic commands? This tutorial will help. As someone who has recently built a Linux computer to play around with, I have been at the bottom of that steep learning curve. I have done the searching and experimenting and put all that accumulated knowledge here so you don’t have to do all the hard work.

Linux is arguably the most flexible and secure computer operating system available. Yet it is also the most bewildering and complicated. If you’re moving from Windows or Mac OS, the basic UI may seem familiar, but as soon as you want to do anything interesting with your computer, the fun begins.

I use Mint Linux and though the desktop is user friendly, even the act of moving or deleting a folder or file becomes a trial if you do it the command line way. And you should use the command line, otherwise you may as well stick to Windows or Mac.

Finding your way around Linux

To truly learn Linux, you have to live in the terminal window. Sure you can drag and drop like in other OS but you will quickly find your options limited. Only by getting to grips with the command line will you truly bend the OS to your will.

To get to the directory in order to delete it, we use a few useful commands that any Linux newbie will need to know. Use them in Terminal to achieve the results you need.

Once you type the command, hit Enter to execute that command.

PWD

Type ‘pwd’ into Terminal to find out where you are. PWD gives you the absolute path which lists where you are currently while using root as the base. Root is the core of Linux and most files will be related to root.

For example, type ‘pwd’ and hit Enter. You should see something like ‘/home/USERNAME’. Where USERNAME is the name you entered when configuring a user account.

LS

Type ‘ls’ into Terminal and hit Enter to list the directory contents. This shows you exactly what is in any given directory. Type ‘ls -a’ to also display any hidden files within that directory.

CD

The ‘cd’ command may be familiar to some Windows users and is used to change directory. You can quickly move around the operating system with this command so is definitely one worth using.

Type ‘cd USERNAME’ to navigate from anywhere to your user folder. Type ‘cd Music’ to jump to the Music directory.

MKDIR

The ‘mkdir’ command creates a directory. As long as you have permission, you can create what you like where you like.

Type ‘mkdir Gamesaves’ and hit Enter to create a directory called Gamesaves. You can then navigate to your new folder by typing ‘cd Gamesaves’ and hitting Enter.

RMDIR and RM

RMDIR and RM are the commands you need to delete a directory in Linux. While I have somewhat buried the headline, I hope you understand that there is a logic to why I have put it here. Now you can navigate, jump to a directory and create one. Now it’s time to delete one.

Type ‘rmdir NAME’ will delete an empty directory. Type ‘rm NAME’ to delete a directory and its contents. If you type ‘rmdir NAME’ for a directory that contains files, it will present an error.

CP

Type ‘cp FILENAME’ to copy a file, folder or directory. To use this command, you need to tell Linux what you want to copy and where you want to copy it to.

For example, type ‘cp /home/user/Music FILENAME /home/user/Desktop’ and hit Enter. This will copy the file called FILNAME from the Music directory and place the copy in the Desktop directory.

MV

Type ‘mv’ to move a file or directory. You can drag and drop files using the UI but where’s the fun in that? Like the cp command, you need to tell Linux what you want to move and to where.

For example, type ‘mv /root/FILENAME /Music/’ and hit Enter. This will move FILENAME from the root directory to the Music directory.

Locate

Locate does exactly what you think it would. It’s like search in Windows and can locate files anywhere in the system.

Type ‘locate -i Track1’ and hit Enter. This will find the file called Track1. The ‘-i’ argument causes Linux to ignore the case. Linux is very case sensitive, so using ‘-i’ causes Linux to ignore case sensitivity.

Those are just some of the many, many basic Linux commands that can make your life with the operating system much more enjoyable.

Got any other basic Linux commands to share? Tell us about them below if you do!

32-bit Apps: What to Do If an App 'is Not Optimized for Your Mac'

Read Next 

Leave a Reply

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


Random

May 24, 2018

944 Articles Published

More