970_90

Monday, 15 June 2015

Linux and Unix rm command help and examples

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.


Linux and Unix rm command help and examples

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




No comments:

Post a Comment