rm command silently

Posted on 2006-06-02
Last Modified: 2012-08-14
 In one of my scripts the command is to remove all the files in a directory. sometimes there will be files and sometimes not..but if the files are not there then this commad is generating error.
"* No such File or Directory"
the actual command is rm ./DIR/*
in some of the commands i know we have -s option which will supress the error. Is there anything like that here ?
Question by:koppcha
    LVL 23

    Accepted Solution

    use rm -f:

    rm -f ./DIR/*

    From the 'rm' man page [note the second sentence]:

         -f          Attempt to remove the files without prompting for confirma-
                     tion, regardless of the file's permissions.  If the file does
                     not exist, do not display a diagnostic message or modify the
                     exit status to reflect an error.  The -f option overrides any
                     previous -i options.
    LVL 8

    Author Comment

    I was knowing about -f that it would forcibly removes the files but not aware that it can do this alos...

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Suggested Solutions

    Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
    Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now