-1

In Unix,How to remove files and directories from the directory named as parent. The parent directory is placed inside grandparent directory.i need to remove only the files and directories inside parent directory and not the parent directory What is the command used here Help is appreciated

  • Why not just move into the directory where you want to delete the files and just use rm or just rm -rf /the/directory/* to delete what you want? – Nasir Riley Feb 1 at 18:00
  • @NasirRiley rm can be used to delete an complete directory and files without deleting itself??? – Arun Sanga Feb 1 at 18:01
  • @NasirRiley what about rmdir? – Arun Sanga Feb 1 at 18:01
  • Ibug answer worked – Arun Sanga Feb 1 at 18:06
  • Yes, it can. rmdir only works if the directory is empty. – Nasir Riley Feb 1 at 18:06
0

Warning: Make sure to verify the glob results with echo before proceeding with rm -rf.

To delete all files within a directory (but not the directory itself):

rm -rf path/to/dir/*

In case there are "hidden files" (files whose names start with a dot), Bash's dotglob option will help:

# Run with Bash
shopt -s dotglob
rm -rf path/to/dir/*
| improve this answer | |
  • /* - deleting what is inside and not the directory itself ,right??? – Arun Sanga Feb 1 at 18:05
  • rf is recursive force delete ?? Right?? – Arun Sanga Feb 1 at 18:05
  • @Arun Both correct. – iBug Feb 1 at 18:16

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.