- Basic Linux tutorials for beginner
- Linux basic concepts, installation and troubleshooting
- Linux administration
- Linux commands
- Linux network tutorials
- Linux security tutorials
- Linux software configuration
- Linux desktop tutorials for beginner
- Collection of Linux tips
- Windows basic tutorials
- Introduction to windows
- Windows pre-installation
- Windows Installation
- Windows xp desktop
- Log on for the first time
- Windows XP control panel
- Managing Folders in Windows XP
- Outlook Express Setup
- How to import address book in Outlook Express
- Import Ms Exchange inbox file(.pst) into Ms Outlook 2003
- Import Outlook Express email messages into Ms Outlook 2003
- How to mount and unmount usb drive (thumb drive) in Windows
- House keeping - Keep your Windows clean and tidy
- Windows basic tutorials
Linux rm command - delete file and directory in Linux
Submitted by jinlusuh on Tue, 01/29/2008 - 09:50
Delete file and directory in Linux is regular whether you do server administration job or using Linux desktop as an end user. Linux is different from windows operating system, where permission and security is very important in Linux and a default part of the system. Root user has full power like administrator in windows operating system, where you can delete anything and everything in the system. Because root user is god in Linux, we were advised to do our normal job as a normal user. Being a normal user, we can only delete user file and directory and that does not affect the Linux system. That also means, we don't have privilege to remove other users' files as well. If your duty needed you to clean system files and directory, as well as user data, (such as maintain Linux ftp server) then switch to root user or gain root privilege only when you have to.
Linux rm command
The Linux rm command is used to delete file or directory in Linux. There is no delete or del command like DOS. Normally, to remove a directory in Linux, we would use the rmdir command. But that will only works if the directory is empty. Here's where the Linux rm command will come into part. It has lots of useful options too. Here's the synopsis and description from the Linux rm command's manual page which explains all about the command:
We can use Linux rm command to delete a normal file without using any option. While to delete a directory, we can use rm -r option. Let's see some examples.
Examples on how to delete files and directory using Linux rm command
First, make sure you login as a normal user.
Create a directory labi in user's home directory for this example.
Create a file named sejarah.txt in labi directory. Here's a tip to create a simple file in linux, use touch command:
Now use 'rm' to delete labi directory:
What's wrong? We can't delete labi directory with rm, ok. It's a directory, so use rmdir instead. But that's also failed, labi directory is not empty. Remember that rmdir only remove an empty directory? To remove a directory, the '-r' option is needed. So use rm -r option to delete a directory and all files in it.
What if we have a large directory with many child directories and files in it? Linux will prompt for a confirmation to delete every files. So the rm -r option seem inefficient this time. In this situation we use the -f option together with -r. Here's and example:
If we use the rm -rf option to remove a directory, Linux will remove the directory and its child without bothering us. The -f option means, just delete and don't ask for my permission. I know what I'm doing. Well, that's true. Only use the -f option if you know what you are doing. My advice is, never issue the rm -rf / command as a root because that will remove all your Linux system.
Back to Linux basic commands main page.