7

How to remove more than one directory using single command? Is it possible to do it in one liner? If yes, Please help on this.

/osmf/mgmt/scheduler>ls -lrt
total 22
drwx------   2 root     root     12288 Mar 26  2009 lost+found
drwxr-xr-x   4 ctmagent controlm  1024 May 24  2010 ctmagent
drwxrwxrwx   3 edwprod  edw       1024 Dec  1 09:53 edi
drwxrwxrwx 120 edwprod  edw       5120 Dec 27 09:37 edw
/osmf/mgmt/scheduler>

Can I delete edi and edw using a single command?

thiton
  • 35,651
  • 4
  • 70
  • 100
AruM
  • 242
  • 1
  • 3
  • 9
  • Is there any characteristics to your directories? Do they all have three letters? Do they all start by e? Do... Do... Do... ? – fge Dec 28 '11 at 11:35

5 Answers5

9

rm -r edi edw

rm can take an arbitrary number of arguments, and the -r flag makes it delete directories recursively. Refer to man rm for more details.

Reading manual pages are the best way to get information for your questions.

BcK
  • 2,548
  • 1
  • 13
  • 27
thiton
  • 35,651
  • 4
  • 70
  • 100
3
rmdir edi edw

if the directories are both empty, otherwise

rm -r edi edw

or

rm -r ed[iw]
Fred Foo
  • 355,277
  • 75
  • 744
  • 836
2

Specifically for your case:

rmdir -r ed[iw]

It basically removes any directory with the name of ed followed by either i or w

stefanB
  • 77,323
  • 27
  • 116
  • 141
1
rm -r ed*

-r means delete directories. ed* make match edi and edw. if there is another directory name start with ed,please be careful!

Tom van der Woerdt
  • 29,532
  • 7
  • 72
  • 105
TonySu
  • 11
  • 2
0

rmdir ed* if they are empty (shell will expand ed* to match edi and edw, * is a wildcard character meaning "any string of characters").

rm -r ed* if they are not empty.

Neither of these commands will move your dirs to the trash bin so when using them always make sure that you don't need the dirs or their content.

Mischa Arefiev
  • 5,227
  • 4
  • 26
  • 34