Categories: Tech

How to Remove Directory Linux with Unix Delete File syntax

How to remove file and directory in Linux / Unix Operating system?

Perform Delete Operations in Linux and Unix via Command prompt

If you have ever encountered the a Linux and UNIX system while working with any database like I did, So you must remember some of the quick commands to perform short tasks. One of them is ‘rm’ to perform delete or remove operation.

How to use “rm” syntax?

“rm” is the short form of remove that frequently utilizes in Unix to delete file. Whereas ‘rmdir’ is the remove directory Linux syntax.You can not remove objects until your OS user has appropriate rights for that particular file or directory.You can not remove objects until your OS user has appropriate rights for that particular file or directory.

rm -r object.txt

Here ,
Object.txt is indicating any OS file.
-r = Remove the file (objct.txt) from this directory or mount point recursively.
You can still have an option to remove a file forcefully without getting any prompt. You can do it by adding “-f” with Unix delete file command.

Example:

rm –f –r Object.txt

Remove Empty Directory In Linux

In order to remove an empty directory from any mount point you can use ‘rmdir ’ instead of ‘rm’ command. For Example:

rmdir empty_dir

where rmdir is the syntax to delete null directory.
empty_dir is the name of that directory.
If it is not empty, then Linux shell command prompt you with an error.

Related Post

Error Message: 

rmdir: empty_dir: Directory not empty

Note: Please use next tip to remove such directory.

Remove All Files & Directories / Subdirectories

If you need to delete all directories and archives in any particular directory at once, then you can use following Linux command.

rm –rf {directoryName}

Remove All Files In Linux/Unix Directory

Let say your directory name is ‘mydir’ and you wanted to delete all files within this directory. So, we can use shell operator “*” with remove syntax. For example:

rm -r mydir/*

Delete / Remove All Files Have Same Extension

Unlike deleting dozens of files one by one in a single directory, you can remove all files at once that have the same extension.
Like I have five objects in mydir_1 such as:

1-    Abcd.avi
2-    Abcd2.avi
3-    Abcd3.txt
4-    Abcd4.avi
5-    Abcd5.ora

From them I just want to remove files that have ‘.avi’ extension. This activity will save my time and effort.

Cd mydir_1
rm –rf  *.avi

Caution:
Beware while executing some of the following delete operations with command prompt as this will lead to a disastrous impact.
Do not try to execute mentioned below command from the root or any user, because these commands will delete all your data.

rm –rf /
rm –rf *



  • Tags: Linux
    Rameez

    Recent Posts

    Heart Attack Causes and its Solution

    What is the Main Cause of a Heart Attack? What is its Solution? A heart attack is the blockage of… Read More

    11 months ago

    Understanding the Debt Ceiling: Its Impact, Importance, and Implications

    In the vast economic arena, one term that often takes center stage, inciting extensive debates and discussions, is the "debt… Read More

    1 year ago

    De-Dollarization: The New World Order of Currency and Its Global Impact

    De-Dollarization: The Changing Face of Global Finance The financial landscape is in a state of flux, with an intriguing economic… Read More

    1 year ago

    Unstoppable Bayern Munich: The Story Behind Their 11th Consecutive Bundesliga Title

    The curtains closed on a dramatic Bundesliga season with Bayern Munich standing tall once again, clinching their 11th straight title.… Read More

    1 year ago

    Celine Dion Cancels Concert Tour Due to Deteriorating Stiff-Person Syndrome

    The Unfolding Story of Celine Dion's Health In recent news that has left fans across the globe stunned, iconic singer… Read More

    1 year ago

    Navigating the Crossroads: LeBron James, Anthony Davis, and the LA Lakers’ Uncertain Future

    As the echoes of the recent NBA season start to fade, the attention of enthusiasts is firmly glued to one… Read More

    1 year ago