rm: Remove files or directories
August 9th, 2024 9:02 AM Mr. Q Categories: Command
Command: rm
Used to remove files or directories. Be careful with this command! It permanently deletes files without sending them to the trash.
Sample Command and Output:
$ rm file1.txt
$ ls
Description:
rm file1.txt
: Removesfile1.txt
from the current directory.ls
: Lists the contents of the current directory to confirm thatfile1.txt
has been deleted.
Sample Command and Output:
$ rm -r folder1/
$ ls
Description:
rm -r folder1/
: Recursively removes the directoryfolder1
and all its contents. The-r
option allowsrm
to delete directories and their contents.ls
: Lists the contents of the current directory to confirm thatfolder1
has been deleted.
Additional Arguments:
-i
: Prompts before each removal.-f
: Forces the removal without prompting.-v
: Verbose mode, displays the files being removed.
Sample Command and Output:
$ rm -rf folder1/
Description:
rm -rf folder1/
: Forcefully and recursively removes the directoryfolder1
and all its contents without prompting. The-rf
combination is powerful and should be used with caution, as it can delete large amounts of data quickly and irreversibly.