06. rm_command - muneeb-mbytes/linux_course GitHub Wiki
rm command
The 'rm' means remove. This command is used to remove a file. The command line doesn't have a recycle bin or trash unlike other GUI's to recover the files. Hence, be very much careful while using this command. Once you have deleted a file, it is removed permanently.
The Figure.1. represents the remove command variation.
Figure.1. Representation of rm command variation
Cheat Sheet for remove command
S.No | Remove Commands | Description |
---|---|---|
1. | rmdir dir_name | Remove one files or directory at a time |
2. | rm -rf dir_name1 dir_name2 dir_name3 | Remove multiple directories |
3. | rm -f file_name | Remove the directory forcely |
4. | rm -d dir_name | Remove the empty directory |
rmdir dir_name
- "rmdir " stands for remove directory.
- with this command we can remove one directory at a time and make sure that it can't be undo.
Example: rmdir manipal_b6_dummy
The Figure.2. shows removing a directory or a file .
Figure.2. Usage of rmdir command .
The GIF-1 shows the whole process from sourcing scripting file till the output.
GIF-1: rmdir directory_name gif.
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/rm_commands/single_dir_rm.csh
rm -rf dir_name1 dir_name2 dir_name3
-
This command is use to delete the multiple directories .
Example: rm -rf manipal_b5_dummy manipal_b6_dummy Here, manipal_b5_dummy and manipal_b6_dummy directories are deleted.
The Figure.3. shows how to remove multiple directories .
Figure.3. Usage of rm -rf command
The GIF-2 shows the whole process from sourcing scripting file till the output.
GIF-2: rm -rf directory_names command gif
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/rm_commands/multiple_dir_rm.csh
rm -f file_name
- Flag "f" stands for force deletion
- If a file is write protected. The -f option overrides this minor protection and removes the file forcefully.
Note: -f option of rm command will not work for write-protect directories.
Example: rm -f myfile.txt yourfile.txt Here, files named myfile.txt and yourfile.txt both files will be deleted.
The Figure.4. shows how to remove multiple files .
Figure.4. Usage of rm -f command .
The GIF-3 shows the whole process from sourcing scripting file till the output.
GIF-3: rm -f file_names command gif
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/rm_commands/file_rm.csh
rm -d dir_name
- This command is used to delete the empty directories only.
and To remove non-empty directories and all the files within them recursively, use the -r (recursive) option
Example: rm -d linux_basics
The Figure.5. shows how to delete empty directories .
Figure.5. Usage of rm -d command .
The GIF-4 shows the whole process from sourcing scripting file till the output.
GIF-4: rm -d directory_names command gif
Github lab link: https://github.com/muneeb-mbytes/linux_course/blob/b7_Team_SiliconCrew/rm_commands/empty_dir_rm.csh
rm --help
This command gives the details of rm commands .It shows all options and use of each option .
To learn vim and gvim command : https://github.com/muneeb-mbytes/linux_course/wiki/07.-vim_gvim-commands