Remove command in linux
- Remove command Syntax.
- # rm [option] file
- # rmdir [option] directory
- Frequently Asked Questions in Remove Command
- 1. How to remove a file?
- Syntax
- # rm [option] file
- Example:
- # rm tmp.txt
- The above command will delete the "tmp.txt". Before that it will ask you to confirm for deletion.
- # rm -f tmp.txt
- The above command will forcely delete the "tmp.txt" file
- 2. How to remove a directory?
- Syntax
- # rmdir [option] directory
- Example:
- # rmdir /temp/test
- The above command will delete the "test" directory if there is no content in it.
- If there is any content in this directory, it will throw error: "rmdir: /temp/test: Directory not empty".
- # rmdir -p /temp/test
- The above command removes directory and its ancestors.
- 3. How to remove a directory including its subdirectories?
- Example:
- # rm -r /temp/test
- The above command will delete the "test" directory and its sub subdirectories and files.
- # rm -rf /temp/test
- The above command deletes all the files and subdirectories without asking confirmation. If you run this command by mistake, thats all. So very carefull when you execute this command.