Operating System - HP-UX
1833315 Members
2755 Online
110051 Solutions
New Discussion

delete file which do not end with ! character

 
SOLVED
Go to solution
kholikt
Super Advisor

delete file which do not end with ! character

Is there anyway I can delete the following file which don not end with a ! character
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.89!
-rw-rw-rw- 1 root sys 24 Apr 29 17:14 ifOutOctets.9
-rw-rw-rw- 1 root root 99 Mar 1 05:29 ifOutOctets.9!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.90
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.90!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.91
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.91!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.92
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.92!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.93
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.93!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.94
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.94!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.95
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.95!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.96
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.96!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.97
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.97!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.98
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.98!
-rw-rw-rw- 1 bin bin 0 Apr 28 19:04 ifOutOctets.99
-rw-rw-rw- 1 root sys 100 Oct 4 2002 ifOutOctets.99!
-rw-rw-rw- 1 root sys 86 Mar 2 21:02 ifOutUcastPkts.1!
-rw-rw-rw- 1 root sys 86 Mar 2 21:02 ifOutUcastPkts.2!
-rw-rw-rw- 1 root sys 83 Mar 2 20:02 memoryAvailableBytes.0!
abc
8 REPLIES 8
Volker Borowski
Honored Contributor
Solution

Re: delete file which do not end with ! character

Like this:

ls -1 | grep -v '!$' | awk '{ print "rm " $1 }'

Check if List suits you

Then

ls -1 | grep -v '!$' | awk '{ print "rm " $1 }' | sh

Volker
KapilRaj
Honored Contributor

Re: delete file which do not end with ! character

ls -1 |awk '{print $NF}'|grep -v \!$ |xargs rm

Regds,

Kaps
Nothing is impossible
Robert-Jan Goossens
Honored Contributor

Re: delete file which do not end with ! character

Hi,

# find . -type f | grep -v "!" | while read LINE
do
rm $LINE
done

Robert-Jan
KapilRaj
Honored Contributor

Re: delete file which do not end with ! character

God knows why I typed an awk

ls -1 |grep -v \!$ |xargs rm

This is enough

Kaps
Nothing is impossible
H.Merijn Brand (procura
Honored Contributor

Re: delete file which do not end with ! character

# perl -e'unlink grep!/!$/=><*>'

or more verbose

# perl -e'for(<*>){/!$/ or unlink$_}'

Enjoy, H.Merijn
Enjoy, Have FUN! H.Merijn
Elmar P. Kolkman
Honored Contributor

Re: delete file which do not end with ! character

If you accept the process also going into subdirectories, it can be done in a single command:
find . -type f ! -name '*!' -exec rm {} ';'
Every problem has at least one solution. Only some solutions are harder to find.
Thierry Poels_1
Honored Contributor

Re: delete file which do not end with ! character

hi,

how about:

rm !(*!)

regards,
Thierry Poels.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
generic_1
Respected Contributor

Re: delete file which do not end with ! character

rm -i * in the directory
Then confirm the correct ones to delete :).