0

I have couple of questions regarding Linux commands:

  1. I want to delete a directory and contents of that directory. My question is will the following command delete the work directory and contents of that directory, or it will delete only contents of that directory? I searched internet and went through some forums but its not clear whether it will delete that directory or not. If it deletes only the contents then what is the command to delete that directory?

    Command :rm -rf work

  2. Is the following command correct to delete all zip files inside test directory whose name starts with Project? I think -r is not required because it's a file. Please correct me if I am not wrong.

    Command : rm -f test\Project*.zip

  • 1
    Delete your question from StackOverflow - stackoverflow.com/questions/49548837/… – Inian Mar 29 '18 at 6:05
  • 2
    This is really a trivial one, for 1) doing rm -rf work should work as expected and for 2) the slash should be / as rm -f test/Project*.zip – Inian Mar 29 '18 at 6:08
  • @Inian Consider answering the question with the information in your comment. – Katu Mar 29 '18 at 8:08
  • @Katu: I think its too trivial to answer, to be helpful in the community. Feel free to add so if you wish. – Inian Mar 29 '18 at 8:09
  • @Inian That's OK, I respect your opinion. Relevant meta question meta.stackexchange.com/questions/209280/… – Katu Mar 29 '18 at 8:14
1
  1. The command rm -rf work will delete both the directory and all its contents. It does this by first deleting any files in the directory and if there are subdirectories, it recurses into them and deletes them in the same manner. The empty work directory is deleted last.

  2. The -r is not required. The pathname is slightly wrong though since it seems to be using \ as the path separator. On Unix systems, / is the path separator. To delete all files whose names start with Project and ends with .zip in the test directory, you do

    rm test/Project*.zip
    

    The -f is not needed either unless you have rm aliased to rm -i (which will make rm ask for confirmation before removing anything). In scripts, -f is often used to suppress error messages when deleting files that may not exist (rm -f will never fail even though the file may not exist). In interactive usage, -f is almost always used to override the -i flag.

0

1 - rm -rf work deletes the directory and its contents. You can do rm -rf work/* if you wish to keep the dir and empty the contents.

2 - You are not wrong.

Also, why did you post a question here instead of trying for yourself, which would probably be way easier? Just curious.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.