Operating System - HP-UX
1833771 Members
2148 Online
110063 Solutions
New Discussion

Re: delete a specific user file

 
peterchu
Super Advisor

delete a specific user file

If I want to delete all the files that belongs to a specify user ( eg. userA) , in the below case , i want to delete the file ed.log , could suggest what can I do ?thx

ll /tmp

-rw-rw-rw- 1 userB edp 1830 Jun 9 16:25 abc.log
-rw-rw-rw- 1 userA edp 1864 Jun 9 16:25 ed.log
-rw-rw-rw- 1 edp1 sys 2546 Jun 9 16:04 gou.log
-rw-r--r-- 1 root root 27004 Jun 9 16:00 12203.1
-rw-r--r-- 1 root root 14683 Jun 9 16:00 12203.2
6 REPLIES 6
Paul_481
Respected Contributor

Re: delete a specific user file

Hi Peter,

use find.

#find -user -exec rm {} \;

where is the directory of the files and
is the owner of the files that you want to delete.

Regards,
Paul
jpcast_real
Regular Advisor

Re: delete a specific user file

Whith a simple scritp:

ll | grep -i mad | awk '{ print $NF }'

Gives you all the files which a user owns.

Dartanan:/tmp> ll | grep -i mad | awk '{ print $NF }' | while read line
> do
> rm $line
> done

With this simple scritp you can delete all of them
Here rests one who was not what he wanted and didn't want what he was
Eknath
Trusted Contributor

Re: delete a specific user file

Hi,

try following command
#find / -user abc -exec rm {} \;

replace abc with the username. Also replace / with the absolute path if you want to delete only from certain directory..
/ will delete all files owned by abc on the system.

Cheers !!!

eknath
Muthukumar_5
Honored Contributor

Re: delete a specific user file

You can all files owned by specic user with find -u option as,


find -u -type f -exec rm -f {} \;

To delete userA file under /tmp structure then,

find /tmp -u userA -type f -exec rm -f {} \;

or

find /tmp -u userA -type f | xargs rm -f

hth.
Easy to suggest when don't know about the problem!
Enrico P.
Honored Contributor

Re: delete a specific user file

Hi,

ll |grep ^- | awk '{ if ( $3 == "username" ) {print $9} }'|xargs rm

for delete username' s ordinary file in the currently directory.

Enrico
Mobeen_1
Esteemed Contributor

Re: delete a specific user file

Peter,
While i concur with the suggestions put forth in the previous posts, i would like to urge you to make doubly sure on the "User" and "Directory" while following the suggestions :)

regards
Mobeen