0

please how to delete all files and folders where is special group contoso?

drwxr-x---   2 root     contoso      850 Apr 20 10:07 jasteps
-rwxr-x---   1 root     contoso   394870 Mar 23 18:52 kedb.3.xml
drwx------   2 root     root         117 Apr 19 10:43 trweT
drwx------   2 root     root         117 Apr 18 15:16 tmewLQrt
drwxr-xr-x   2 beswbm   sapsys       117 May  5 09:40 hswdata_bpqadm
drwxr-xr-x   2 estsdm   sapsys       117 Apr 28 12:04 hspewwata_eptadm
drwxr-xr-x   2 oracle   dba          117 May  5 10:01 hfeta_oracle
Bellerofont
  • 1,081
  • 18
  • 17
  • 16
Jan Blaha
  • 5
  • 1
  • 2

1 Answers1

-1
cd /

find . -group contoso > files.txt

for i in `cat files.txt`; do
    rm -rf $i;
    done

But be careful using the command, because rm -rf will delete files and folders all along without asking for confirmation.

Baha Baghdadi
  • 29
  • 1
  • 1
  • 11
  • Downvoted for the use of `cat files.txt` in a for loop. Please read [BashFAQ](http://mywiki.wooledge.org/BashFAQ/001) and [Looping through the content of a file in Bash?](http://stackoverflow.com/questions/1521462/looping-through-the-content-of-a-file-in-bash) – dawg May 06 '17 at 00:28
  • `rm -rf $i` -- you need to quote `$i` like so: `rm -rf "$i"` – dawg May 06 '17 at 00:30
  • The whole thing is better done this way: `find . [primaries] print0 | xargs -0 [do what you need to do with each]`. – dawg May 06 '17 at 00:34
  • If you write `cat` and are doing something other than *concatenating* files, that's probably not the correct way to do it -- and you are committing a **UUOC** (Unnecessary Use Of `cat`) – David C. Rankin May 06 '17 at 00:36
  • Please try to see why you need double quotes: `touch file{1..20} "file*"; ls file*>files.txt` and then run your loop. All files starting with `file` would be deleted because the unquoted `*` glob expands to all files with the prefix `file`. If that were `rm -rf file*` -- OOPS! – dawg May 06 '17 at 01:02