The commands that permanently delete files and
directories on Linux, macOS, and other Unix-like operating systems are
obviously rm
and rmdir. They are absolutely similar to del & deltree commands in Windows and DOS. These
commands are very powerful and have quite a few options.
It is really important to note that files and directories permanently deleted using rm and rmdir do not get moved to the Trash. They are immediately and completely permanently deleted from your computer. 😂If you guys accidentally permanently delete any files using these commands, then there is no way in hell you guys can retrieve them back unless those are backed up. 👀
How to permanently delete
Files with rm The simplest answer for how to permanently delete a
single file in the current directory. Type the rm command, a <space>, and then the name of the file
you guys want to permanently delete. Now c’mon it looks like teaching real
basic stuff XD.
rm
file1.txt
💬If the file is not in the current working directory, then
fuckin’ provide a right path to the file’s location.->
rm ./path/to/the/file/file1.txt
💬you guys can permanently delete more than one file in rm. Doing so permanently
deletes all of the specified files. ->
rm file2.txt file3.txt
💬The * represents multiple characters and - ? represents a single character. 👇This command permanently
deletes all of the png images in the current directory.->
rm *.png
💬If a file is write-protected you guys will be prompted
before the file is permanently deleted. ✌you guys must respond with y or n and press “Enter.”👇
👀To reduce the risk of deleting stuff unexpectedly with rm use the -i (interactive) option. This makes you guys confirm the
deletion of each file.👇
rm -i *.dat
💬The -f (force) option is in contrast to -i option. 💢It will not prompt for
confirmation even if files are protected.
rm -f
file4.png
How
to permanently delete Directories with rm
rm -d
directory1
💬Providing more than one directory name fuckin’
permanently deletes all of the specified directories😀.
rm -d
directory1 directory2 /path/to/directory3
💬To permanently delete directories that are not empty, use
the -r (recursive) option. 👽To be
clear, this permanently deletes the directories and all files and
sub-directories contained within them.
rm -r
directory1 directory2 directory3
💬If a directory or a file is write-protected, you guys
will be prompted to confirm the deletion. To permanently delete non-empty and
to fuck these prompts, use the -r (recursive) and -f (force) options together.👇
rm -rf
directory
👀To gain an understanding of the directory structure and
the files that will be permanently deleted by the rm -rf command, use the tree command.👇
Use apt-get to install this tree package onto your system if you’re
using Ubuntu or another Debian-based distribution.
sudo
apt-get install tree
😄Running the tree command produces a simple diagram of the directory structure and files inside the directory from which it is run.👇
💬you guys can also add a path to the tree command to make it start the tree from another
directory.
tree
path/to/directory
👀The rm command also has --one-file-system, --no-preserve-root, --preserve-root options, but those are only
recommended for advanced users. If you guys get something wrong, you guys could
accidentally permanently delete all your system files.😂
How
to permanently delete Directories with rmdir
👇There is another command, called rmdir, that you guys can use to permanently delete directories.
The difference between rm and rmdir is that rmdir can only permanently delete directories that are empty.
It will never permanently delete files.
💬The simplest case is deleting a single empty directory. 👽As with rm, you guys can pass multiple
directory names to rmdir , or a path to a directory.
💬permanently delete a single directory in the current
directory by passing its name to rmdir :👇
rmdir
directory1
💬permanently delete multiple directories by passing a list
of names to rmdir :👇
rmdir
directory1 directory2 directory3
💬permanently delete a directory not in the current
directory by specifying the full path to that directory:👇
rmdir
/path/to/directory
If you guys try to permanently delete a folder that is not empty, rmdir will give you guys an error message. In the following example rmdir successfully, and silently, permanently deletes the clients directory but it refuses to permanently delete the projects directory because it contains files. The projects directory is left exactly as it was and the files in it are untouched.👀👇
In the following example two folders have been passed to rmdir, these are work/reports and work/quotes . The --ignore-fail-on-non-empty option has been included in
the command. The work/reports folder has files in it, so rmdir cannot permanently fuck it.
The --ignore-fail-on-non-empty option forces rmdir to ignore the error and move
on to the next folder it needs to process, which is work/quotes. This is an empty folder, and rmdir permanently deletes it.
rmdir --ignore-fail-on-non-empty
work/reports /work/quotes
💬you guys can use the
-p (parents) option to
permanently delete a directory and to permanently delete its parent directories
too. ✋This will work because rmdir starts with the target current directory and then
back-steps to the parent gradually. That directory will now be groped XD, so it
can be permanently deleted by rmdir, and the process repeats stepping back up the path that
was provided to rmdir.👀👇
Both the invoices and the work directories get permanently fucked XD.😂
😃No matter if you're using Bash or any other shell, Linux is flexible and powerful with commands for you guys to permanently delete directories and files straight from the terminal command line.✌✌😁