How to empty the directory?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chez
    New Member
    • May 2011
    • 9

    How to empty the directory?

    how to empty the files in the directory without removing the directory itself?
    I want to have it force delete all the file in the dir
    so
    I tried using

    rm -fR [directory]

    but it delete my directory as well.

    pls advise.
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Have you tried

    rm -fR [directory]/*

    Comment

    • sicarie
      Recognized Expert Specialist
      • Nov 2006
      • 4677

      #3
      Alternatively, you can cd into the directory

      cd /path/to/dir; rm -rf *

      As you're currently in the dir with the above, it won't be able to remove the directory

      Comment

      • numberwhun
        Recognized Expert Moderator Specialist
        • May 2007
        • 3467

        #4
        Alternatively, you could do the following:

        rm -f directory/*

        That will remove everything in the directory, but leave the directory in tact.

        Regards,

        Jeff

        Comment

        • chez
          New Member
          • May 2011
          • 9

          #5
          thx all for the help
          It works with that.

          Comment

          Working...