LINUX-Frequently used commands
| rm command Delete file. |
| Syntax |
| rm [Option] [file-name] |
| The rm command deletes the specified file.. Basically, you cannot remove directories, but you can by adding the option "-r". It also deletes the entire tree below the directory, so be careful with it. |
| Frequently used options |
| -f Do not display a message if you specify a file to which you do not have access rights or which does not exist -i Check before deleting a file -r Removes all trees under the specified directory. |
| Example: Delete a file. |
| $ rm data.dat ←Delete the data.dat file |
| Example: Delete files for which you do not have write access. |
| $ rm temp.txt rm: remove write-protected normal empty file\`temp.txt\'? y temp.txt You will get a confirmation message because you do not have permission to write the file (y=delete n=cancel) |
| Example: Force deletion of files for which you do not have write access. |
| $ rm -f temp.txt ← Option "-f" to force removal. |
| Example: Removing a directory. |
| $ rm -r dir1 ← Delete the directory "dir1" with the option "-r" The rmdir command for directory removal can only be executed if the directory to be removed is empty, but the rm command option '-r' removes files even if they are stored inside. |
