Linux rm Command Tutorial With Examles

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-rm-command-tutorial-with-examles/
PINTEREST
PINTEREST
INSTAGRAM

Linux is a file based operating system and actually everything is a file. Sometimes we need to clear our server from some of files. How can we achieve that? There are alternative ways to delete files but the most popular command is rm .

Remove File

rm command definition is remove files or directories. By default rm command do not remove directories. In this example we will remove file named test

Remove Recursively

We may need to remove files in the current working directory and subdirectories. In this situations we can use -r option in order to remove all current and sub directories files. But keep in mind that this will not remove directories and hidden files.

Remove All Files

We can delete all files by using bash glob feature. Glob means all files and folders in this or specified directory

As we see we deleted files but can not deleted directories.

Delete Specific Extension

We can specify specific extension to delete. We will provide the file name by using glob * and file extension. In this example we will remove files with txt extension.

Delete Specific Extension

Delete Specific Extension

Delete Multiple Files

Multiple files can be deleted by specifying them one by one. In this example we will remove two files but more files can be added. We will delete files named httpd-2.4.23.tar.bz2 and httpd-2.4.23.tar.bz2.asc .

Delete Multiple Files

Delete Multiple Files

Remove and Delete Forcefully or Delete Directories

If there are some protection about files we want to delete we can specify forcefully parameter with recursive parameter.This option will also remove directories too.

LEARN MORE  Linux Print History Command Without Line Numbers

Remove and Delete Forcefully

Remove and Delete Forcefully

Delete Empty Directory

Normally rm command do not deletes directories. But id the directory is empty we can delete this directory by using -d option. In this example we will delete the empty directory named folder .

Ask Before Delete

It can be set to ask before delete operation. So we can specify which files will be deleted which will not one by one.

Ask Before Delete

Ask Before Delete

Verbose Removal

While removing files and folders we can print detailed information about removal. We will use verbose -v option in order to provide detailed output.

Verbose Removal

Verbose Removal

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-rm-command-tutorial-with-examles/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)