rm (short-name for remove) is a command used to remove objects such as files, directories, device nodes, symbolic links etc from the file-system.
rm also remove the reference of objects. It works on Linux as well on Unix.
In Actual, rm does not remove any object (file, directories and nodes etc), It just unlink the object from filesystem. That's why file system space may still contain leftover data from the removed file.
Following are rm commands with example.
Delete a single file.
Delete all files [USE WITH EXTENSIVE CARE].
Delete all files which have .txt extension.
Delete all files which start with "data" text.
Delete a folder (folder must be empty).
Delete all recursively. (d-directory, r-recursive).
Delete a file forcefully and will not prompt.
Delete the files with prompt (d-directory, r-recursive, i-Prompt before every removal).
Delete the files without prompt (d-directory, r-recursive, f-without prompt).
Delete the files with without prompt (d-directory, r-recursive, f-without prompt)
Delete the files with single prompt (d-directory, r-recursive, I-single prompt)
Delete the files with details (d-directory, r-recursive, v-explaination)
Delete a file which exist in another folder.
When we are using multiple options in command, see following:
1) We can exchange the position of option (Make no difference)
2) We can also give "-" again each option parameter.
3) To Delete a directory recusively, Following commands are valid and are same.
In Actual, rm does not remove any object (file, directories and nodes etc), It just unlink the object from filesystem. That's why file system space may still contain leftover data from the removed file.
Following are rm commands with example.
Delete a single file.
rm filename
Delete all files [USE WITH EXTENSIVE CARE].
rm *
Delete all files which have .txt extension.
rm *.txt
Delete all files which start with "data" text.
rm data*
Delete a folder (folder must be empty).
rm -d foldername
Delete all recursively. (d-directory, r-recursive).
rm -dr foldername
Delete a file forcefully and will not prompt.
rm -f filename
Delete the files with prompt (d-directory, r-recursive, i-Prompt before every removal).
rm -dri foldername
Delete the files without prompt (d-directory, r-recursive, f-without prompt).
rm -drf foldername
Delete the files with without prompt (d-directory, r-recursive, f-without prompt)
rm -drf foldername
Delete the files with single prompt (d-directory, r-recursive, I-single prompt)
rm -drI foldername
Delete the files with details (d-directory, r-recursive, v-explaination)
rm -drv foldername
Delete a file which exist in another folder.
rm /mnt/data/home/project1/public_html/filename.txt
When we are using multiple options in command, see following:
1) We can exchange the position of option (Make no difference)
2) We can also give "-" again each option parameter.
3) To Delete a directory recusively, Following commands are valid and are same.
rm -dr foldername rm -rd foldername rm -d -r foldername rm -r -d foldername