Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 860
  • Last Modified:

rm command silently

 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 ?
1 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.
koppchaAuthor Commented:
I was knowing about -f that it would forcibly removes the files but not aware that it can do this alos...

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now