directories they are always present on our computer. His presence is inevitable, because are these the ones that store the information necessary for our team, such as file location, file type, number of files, modification date and others.
Like all operating systemsLinux has directories. Many people prefer to delete these, because they store a lot of information and others because they occupy hard drive space. Whatever your case, today we will teach you how to remove them.
on this occasion we’ll show you how to delete these directories through the Linux terminal, using the appropriate commands to achieve it.
What is a Linux directory and why is it necessary to delete them?
We can say that the directoriesare the virtual containers that store and group all the computer files and other sub-directors, who attend to the contents, all of this depends on purpose or criteria that we as users determine.
Specifically, the job of the directory is to store all the information of each of the files that is on our computer: how they are, the attributes of the files or where they can be physically found on the storage device.
How are the directories in Linux?
linux is one of the operating systems, which sorts directories in simpler ways. However, many people may be confused by your organization.
for linux almost everything is filesfrom the directories, to the devices (in some cases names the devices as nodes, but they are still files). This operating system organizes Linux file systems in a hierarchical structure similar to that of a tree, where the upper level or the highest are the root directories.
the other files are below the root directoryto explain it to you in a more illustrative way, We can give the following as an example:
- “/home/jebediah/cheeses.odt” shows us the full path of the file “cheeses.odt” which is located in the directory “jebediah”. At the same time it is under the home directory, which in turn is located in the root directory (/).
What directories are under the root directory?
We can find under the root directory, different directories. Next we will show you a small list of the most common directories under the root directory (/):
- /bin – Applies to major binary applications.
- /boot – It shows us all the boot configuration files, kernels and other files necessary to boot the computer.
- /dev – Directory of device files
- /etc – They are the configuration files, startup scripts, etc.
- /home – With this option we can see the personal directories (home).
- /initrd – We can see this option or directory when creating a custom initrd boot process.
- /lib – It is used to show the system libraries (libraries).
- /lost+found – Provides a “lost+found” system for files that exist under the root directory (/).
- /half – Automatically mounted (loaded) partitions on the hard drive and removable media (media) such as CDs, digital cameras, etc.
- /mnt – Manually mounted file systems on the hard drive.
- /opt – Provides a location to install optional (third party) applications.
- /proc – Special dynamic directory that maintains information about the state of the system, including the processes currently running.
- /root – Home directory of the root user (superuser); also called “bar-root”.
- /sbin – Important system binaries.
- /srv – May contain files that are served to other systems.
- /sys – System files (system).
- /tmp – Temporary files.
- /usr – Applications and files that can be accessed by most users.
- /var – Variable files such as log files and databases.
What are all the commands to delete files and folders from the Linux terminal?
The main job of operating systems like Linux consists of commands that execute, programs, activities or some actions. So that it is very important to understand how and why to use them.
Next, we will show you the commands that we can use to delete the files and folders from the Linux terminal:
MRI
The RM (Remove) Command whose main function is to delete or delete filesdirectories or others as symbolic links.
In other words RM removes references to each object within Linux, as they are, files with two names, and others, although by default this type of command does not remove directories completely, so it is considered that if the files are deleted they can be recovered.
Shred
The shared command is used to completely delete the filesbecause as we saw in the previous command, directories are not completely removedwhile this one does. Many experts consider that what this command does is overwrite files to hide their contents and addresses.
This command has different options such as:
- “F” – To change all permissions and allow a write to the files if necessary.
- “N” – Used to specify the number of times, which by default is 3.
- “OR” – This is used to directly delete the files,
- “V” – Shows the progress of the operation.
- “Z” – It is used to hide the secure deletion of data.
sdmem
This command as indicated by its name it is a safe memory cleanerwhose main function is to delete the active data directly of the RAM memory permanently, guaranteeing an impossible recovery.
swap
This command (Secure Swap Wipe) allows us to clean the disk partitionserasing the data during the exchange of information (swap).
To be able to use it you need to run the swap command first in order to exchange the partitions that have active data, and to be able to delete those files that we want to no longer be on our hard drive.
secure-delete
This command allows us to delete all files that we need to delete safely and permanently. Although to use it you will need to some packages are installed and then be able to use it.
Oddly enough, this is one of the most insistent commands when deletingand this is considered so, because it eliminates a file or object as many times as necessary in the same space until 80 or 90% of it disappears.
This command has two options, which are:
- ”srm my-passwords.txt” – This is used to delete the folders with everything and their contents.
- “stm –r personal-folder/” – It is a command that allows us to delete information, although it takes a long time in its function, but it happens because it deletes a file several times.
sfill
We can use this command to delete the files permanentlyand leave free spaces on the disk, in a way that guarantees that the deleted information cannot be recovered.
This command has the following options:
- “YO” – It is used to make two passes randomly and another with zeros.
- “V” – It shows us the progress of the operation.
- “Z” – It is used to hide the secure deletion of all data.
wipe
Finally, there is the Wipe tool whose command is used to securely delete files at a low level, just as the secure delete command requires an installation package to be able to use it.
Steps to use the rm command to remove a directory from the Linux terminal
The most commonly used command to remove files from the Linux terminal is rm (remove). In this section We are going to show you the steps that we must comply with To learn how to use this command:
We go to the directory
When we enter the terminal, we go to the directory or path that indicates the exact location of the file that we want to delete. rm “File”
We use the is command
We will now use the Is command to view a list of filesthen we delete the selected files and use Is again to confirm that they have been deleted.
We indicate the direction again
Yes with the previous step file deletion did not workwe will have to enter your route and address again.
We delete the files
As we have been doing, we can simultaneously delete several filesso we must select files and we execute the commands:
- rm file6 file7 file8
We delete directories with the rm command
We had already commented at the beginning that this type of command does not remove directoriesdefault just delete filesbut this does not mean that it is impossible to remove the directories with this command.
Follow the steps:
- To delete the empty directories we execute the command as follows: rm –d directory.
- We make a list of the directories to be able to delete all the data, in order to verify that everything has been deleted.
- When we indicate more than one name in the directories, all those that we have selected will be automatically eliminated. If our case is that we want to remove more than one directory that is not empty, we must resort to the –r (recussive) option, so that from it they are eliminated all files and subdirectories that are hosted in the directory: rm –r directory.
- We verify that you are deleting the directoryusing the parameter –d where we will receive a message telling us that the directory cannot be removed since it is not empty, so we will use the command rm along with the parameter –r and so it will be removed.
- If it comes out, a notice that our directory is write protectedwe must combine –r Y –f (force) to force the system to delete it. rm –rf directory.
- Delete directories via command It is very simple, so if we want to remove it we will also have to understand its structure. For this we can use the tree commandthat we must install it using the following: sudo apt install tree.
- already installed, we execute tree to display the directory structures, where will show us in detail how the directory is organized:
Let’s use rmdir to remove the directories
rmdir it’s almost the same as the rm command only this time more focused on directories, for which it is known how to remove directory.
Follow our directions:
- We execute the command inside the terminal, to be able to remove all directories What we want. rmdir directory. if we want delete multiple directorieswe do as in the previous cases, we enter the directory names, according to the order that we want them to be eliminated.
- When we try to delete a directory or a folder that is not empty rmdir will display a messagewhere it tells us that it cannot be deleted, because the directory it’s not empty.
- If we are shown many errors in the process to delete the directories, we just run the –ignore-fai-on-non-empty option that will allow us to omit the error that is being presented to us.
- Also we can use the –p (parent) option what is going to us…