The command rm is used to delete/remove a file from the filesystem. To delete a folder/directory from the filesystem, use a command rmdir. In this follwing post, you will learn how to delete/remove a file/folder in linux systems.
1. Following are the examples for rm and rmdir command.
rm <filename>
rmdir <directoryname>
2. To remove only empty directory from the file system use below command
rm –d dir{1,2,3}
You can’t use “-df” option with rm command to force remove the directory and you can only able to remove using –rf option.
-r or –R – To recursively delete/remove all the files/folders within a folder.
3. To remove all the files and folders recursively within a folder, use below command.
rm –rf *
4. To nullify the file with zero space without changing the file permissions or ownerships, one can follow below command there by the same file can be re-used again in future. This will be helpful in log files as it continually changes, copying it into other location and nullifying the file space helps in not creating file again with same permissions or ownership.
cp /dev/null <filename>
Note : There is no recycle bin in linux systems to restore files or folders which was deleted, so be careful before delete/remove a file/folder in linux systems.
To know, how to create a file in linux, Click Here!!
How do you feel about this post or want to suggest a new post? Drop your comments below..