Removing files and folders

It is no secret that with a terminal client you can get many things done very easily. One thing in particular that is done easily via terminal is removing files and folders. Sure, you could use a Gui for file and folder removing but then again it is just as easy – or perhaps even easier when done via terminal client.

First, you should navigate to the folder structure, which contains the files or folders you want to remove. You do this by using cd:

cd /home/username/some_folder

OR

cd some_folder

Usually, you only use the above way. You you might use the first method and supply an absolute path as well. The first way becomes de facto way of doing things when you navigate to remove something that is out of your local user’s folders (like /home/username)

The actual removal commands are like below. #Are comments.

rm some_file  #With this you remove some_file

rm -r some_file or some_folder #This is the recursive way of doing the removal. You can remove one file or folders containing files. This is probably the most useful removal command.

Tip. you can also remove multiple files or folders. Just, add them together like this: rm -r file1 file2 file3

rm -rf some_file or some_folder  #Here you use the force together with the recursive removal. Be careful with the force – so you do not end up removing anything you do not want to.

With the above commands you should be well on your way. There is however one scenario we will look into before this post ends.

Let’s assume you have used a tool (like Simple Mount on PostX Gnu/Linux) that has mounted your usb stick. You can browse the files and folders just fine. Then you decide that you will want to remove something and you do rm -r some_file within a terminal. You end up getting: Permission denied. What this means is that the media was mounted with sudo or root priviledges and you need to be a sudo or a root to maniplate the files or folders(meaning: to remove or add stuff).

The easy way of doing this is just adding sudo in front of the commands.
For example: sudo rm -r some_file (This applies to PostX Gnu/Linux)
Same as root:

su root (press return) –> give root password –> rm -r some_file

The need to remove and add things as a sudo or a root can increase security – since adding something sinister to a portable media comes essentially harder. However, some users do get scared of terminal clients. The easy way out from the terminal and into the familiar Gui is just one command away:

sudo some_filemanager

For example: sudo clfm (on PostX Gnu/Linux)
sudo pcmanfm
sudo nautilus
etc.

Do keep in mind that sudo and root usage of programs should be avoided when possible and used with caution. So, whatever you do always think before you do it.