Index:
UPDATED ✅ Need to remove a directory or file from the GNU Linux system terminal? ⭐ ENTER HERE ⭐ and discover how to do it ✅ EASY and FAST ✅
directories are always present on our computer. His presence is unavoidable, because These are the ones that store the information. necessary for our team, such as location of files, type of files, number of files, date of modification 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.
this time we will show you how to delete these directories through the Linux terminal, using the appropriate commands to achieve this.
What is a Linux directory and why is it necessary to delete them?
We can say that the directoriesare the virtual containers that store us and group all the computer files and other subdirectories, that deal with the contents, all 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 one of the files that is in our computer: how they are, the attributes of the files or where the storage device can be physically located.
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 directories, to devices (in some cases names 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 top or highest level are the root directories.
the other files are below the root directoryto explain it in a more illustrative way, We can give the following as an example:
- “/home/jebediah/cheeses.odt” show 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 for its part is located in the root directory (/).
What directories are below 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 important 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 disk 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 – Personal directory of the root user (superuser); also called “slash-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 work of operating systems such as 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:
MR
The RM (Remove) command whose main function is to delete or delete filesdirectories or others as symbolic links.
In other words RM remove the references that are for each object within Linux, as they are, files with two names, and others, although by default this type of command does not remove the directories completely, so it is considered that if the files are deleted they can be recovered.
shredded
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 believe 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 writing to files if necessary.
- “N” – Used to specify the number of times, which defaults to 3.
- “OR” – This is used to directly delete files,
- “V” – Shows the progress of the operation.
- “Z” – It is used to hide the secure deletion of data.
sdmem
This command as its name indicates 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 partitionsdeleting 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 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 install some packages 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 mis-passwords.txt” – This is used to delete folders with everything and their contents.
- “stm –r folder-personal/” – It is a command that allows us to delete information, although it takes a long time to function, but it happens because it deletes a file several times. File, Archive.
sfill
We can use this command to delete the files permanentlyand leave free space 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 perform two random passes 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
Lastly, there is the Wipe tool whose command is used to securely delete files at a low level, just as the secure delete command needs 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 follow to learn how to use this command:
Let’s go to the directory
When we enter the terminal, let’s 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 address again
Yes with the previous step file deletion didn’t workwe will have to enter your route and address again.
We delete the files
Just 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 commands 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 which is not empty, we must resort to the -r (recursive) option, so that from it are eliminated all the files and subdirectories that are housed in the directory: rm –r directory.
- We verify that is deleting the directoryusing the parameter –d where we will receive a message telling us that the directory cannot be deleted because it is not empty, so we will use the command rm along with the parameter –r and so it will be removed.
- If we get a warning that our directory is write protectedwe must combine –r Y –f (force) to force the system to delete it. rm –rf directory.
- Delete directories by 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 for the directory structures to be displayed, where will show us in detail how the directory is organized:
Let’s use rmdir to remove the directories
Rmdir it is almost the same as the rm command only this time more focused on directories, for what it is known how to remove directory.
Follow our instructions:
- 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 we want them to be removed.
- 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 of removing the directories, we only execute the option –ignore-fai-on-non-empty that will allow us to omit the error that is being presented to us.
- Also we can use the option –p (parent) which will allow us to remove the selected directories and their parent directories. rmdir –p directory/thedirectory
How to delete directories permanently from Linux terminal?
With the previous command, what we achieve is to partially delete the file or directory. now we will teach you how to do it permanently:
with shred
We already presented this command to you earlier. What you need to do to apply it is to follow the steps below:
- We use the syntax to delete the files, as shown below: shred (options) file (…).
The options are:
- Force (f) – It allows us to modify all the permissions until we can delete all the files
- n– With it, we indicate the number of times the files should be deleted or overwritten.
- or – Delete the files after overwriting it.
- Y – With this option we can see the progress of the operation.
- z – Overwrite 0 to avoid leaving any trace of the file.
- -s, –size=N – Defines the uses of the bytes.
- -x, –exact – Does not round file sizes up to a full block.
- –help – It displays a help list for the command.
- –version – Indicates the current version of the command.
If we want to see the use of the command, we execute the following: shared –zvu –n (# of times) “File”.
Finally, we run the command process to finish. At our request, the file name can be renamed to zeros and deleted.
with sdmem
East it is a widely used command, although it does not have the breadth of many, its usefulness is of great importance. To be able to use it we need to execute the command as follows: sudo sdmen –f -v
With Swap
We already know that this command it helps us to clean the partitions or the files that are inside the partitions of our hard drive. In order to do so we need comply with the following sequence and command lines:
- cat /proc/swaps
- swapon
- sudo swapoff “partition”
- sudo sswap –V “partition”
With Secure-Delete
To be able to delete the files safely With Secure-Delete we must comply with the following steps:
We install the unit using the commands below:
- sudo apt-get install secure-delete (for systems like Debian and its derivatives)
- sudo yum install secure-delete (it’s the command for centOS and RHEL).
We continue executing it with the following command lines: srm –vz file/*.
To finish we use the options we want:
- -v –It allows us to enable the verbose mode of what is happening.
- -z –It removes every last write by adding zeros in random places.
- Although depending on what we have in mind we can also use the following options:
- -d –With the help of this option we ignore all characters and the command line.
- -F –We can enable the fast mode, although it is not highly recommended since the process is less secure and very little allows synchronization.
- -r –Enables recursive mode. Whose mode allows us to delete all the data inside the subdirectories.
- -l –This option allows us to execute two passes over the file.
with sfill
This is another very useful command that we can easily use from our Linux OS to delete directories permanently. What we must do is the following:
- We execute the command on the root partition, using the command with the –v modify option to see detailed mode: sudo sfill –v /home/directory/tmp.
- If we have created a partition separate from /home we will have to apply the command as follows: sudo sfill –v /home /user.
- We can use this command with the following parameters, according to what we want to do with the directories:
- -F -We enabled the fast mode, although this is less secure and does not allow the synchronization mode.
- -Yo – Used to erase all free space.
- -YO –We delete only the free space that is on the hard drive.
- -v We see the process in detail
If we want to see more information about the process, we execute the following command: man sfill
wipe
Remember that this must be installed, For this we follow the following steps:
- We install Wipe using the following commands:
- sudo apt-get install wipe (for Debian and all its derivatives)
- sudo yum install wipe (for CentOS and RHEL system)
- We execute the following syntax: wipe –rfi “file”/*.
- Lastly, we choose the options we want to be executed:
- -r –With this option we indicate that the subdirectors should be recursed.
- -F -Used to force the deletion of files.
- -Yo –We can see the process of deleting the files.
Operating systems