Operating System - HP-UX
1829829 Members
2007 Online
109993 Solutions
New Discussion

Re: How to delete files on HP-UX box?

 
redhat7012
Advisor

How to delete the Files in HP-UX Box ?

Hi,

 

# ls -lrt|more
-rw-r--r--    1 root     system       599751 Sep 12 12:32 1209121159_wsmncp01.log
-rw-r--r--    1 root     system       602065 Sep 12 18:29 1209121759_wsmncp01.log
-rw-r--r--    1 root     system       600927 Sep 13 00:24 1209122359_wsmncp01.log
-rw-r--r--    1 root     system       582738 Sep 13 01:15 1309120059_wsmncp01.log
-rw-r--r--    1 root     system       589388 Sep 13 06:18 1309120559_wsmncp01.log
-rw-r--r--    1 root     system       598967 Sep 13 12:30 1309121159_wsmncp01.log
-rw-r--r--    1 root     system       600927 Sep 13 18:24 1309121759_wsmncp01.log
-rw-r--r--    1 root     system       602457 Sep 14 00:34 1309122359_wsmncp01.log
-rw-r--r--    1 root     system       582883 Sep 14 01:18 1409120059_wsmncp01.log
-rw-r--r--    1 root     system       588851 Sep 14 06:20 1409120559_wsmncp01.log
-rw-r--r--    1 root     system       599359 Sep 14 12:30 1409121159_wsmncp01.log
-rw-r--r--    1 root     system       602065 Sep 14 18:27 1409121759_wsmncp01.log
-rw-r--r--    1 root     system       602457 Sep 15 00:31 1409122359_wsmncp01.log
-rw-r--r--    1 root     system       582738 Sep 15 01:12 1509120059_wsmncp01.log
-rw-r--r--    1 root     system       590027 Sep 15 06:35 1509120559_wsmncp01.log
-rw-r--r--    1 root     system       597791 Sep 15 12:43 1509121159_wsmncp01.log
-rw-r--r--    1 root     system       600143 Sep 15 18:30 1509121759_wsmncp01.log
-rw-r--r--    1 root     system       604930 Sep 16 01:29 1609120059_wsmncp01.log
-rw-r--r--    1 root     system       642983 Sep 17 00:44 1609122359_wsmncp01.log
-rw-r--r--    1 root     system       581954 Sep 17 01:20 1709120059_wsmncp01.log
-rw-r--r--    1 root     system       585361 Sep 17 06:20 1709120559_wsmncp01.log
-rw-r--r--    1 root     system       596261 Sep 17 12:36 1709121159_wsmncp01.log
-rw-r--r--    1 root     system       600535 Sep 17 18:25 1709121759_wsmncp01.log
-rw-r--r--    1 root     system       602065 Sep 18 00:28 1709122359_wsmncp01.log
-rw-r--r--    1 root     system       582738 Sep 18 01:16 1809120059_wsmncp01.log
-rw-r--r--    1 root     system       589780 Sep 18 06:23 1809120559_wsmncp01.log
-rw-r--r--    1 root     system       600143 Sep 18 12:48 1809121159_wsmncp01.log
-rw-r--r--    1 root     system       600927 Sep 18 18:32 1809121759_wsmncp01.log
-rw-r--r--    1 root     system       602065 Sep 19 00:36 1809122359_wsmncp01.log
-rw-r--r--    1 root     system       582346 Sep 19 01:22 1909120059_wsmncp01.log
-rw-r--r--    1 root     system       589243 Sep 19 06:40 1909120559_wsmncp01.log
-rw-r--r--    1 root     system       598967 Sep 19 12:43 1909121159_wsmncp01.log
-rw-r--r--    1 root     system       600535 Sep 19 18:27 1909121759_wsmncp01.log
-rw-r--r--    1 root     system       597461 Sep 20 00:18 1909122359_wsmncp01.log
-rw-r--r--    1 root     system       582099 Sep 20 01:14 2009120059_wsmncp01.log
-rw-r--r--    1 root     system       586145 Sep 20 06:22 2009120559_wsmncp01.log
-rw-r--r--    1 root     system       597544 Sep 20 12:28 2009121159_wsmncp01.log
-rw-r--r--    1 root     system       600927 Sep 20 18:25 2009121759_wsmncp01.log
-rw-r--r--    1 root     system       601072 Sep 21 00:26 2009122359_wsmncp01.log
-rw-r--r--    1 root     system       582738 Sep 21 01:30 2109120059_wsmncp01.log
-rw-r--r--    1 root     system       589388 Sep 21 06:22 2109120559_wsmncp01.log
-rw-r--r--    1 root     system       599359 Sep 21 12:53 2109121159_wsmncp01.log
-rw-r--r--    1 root     system       600143 Sep 21 18:31 2109121759_wsmncp01.log

 

I want to delete files belong to Sept 12 2012.

 

How can delete Only those files in One shot ?

 

 

Regards,

Aparna.

 

 

P.S. This thread has been moved from HP-UX > System Administration to HP-UX > languages - HP Forums Moderator

5 REPLIES 5
Steven E. Protter
Exalted Contributor

Re: How to delete the Files in HP-UX Box ?

ll | grep "Sep 12" | awk '{ print $NF}' | while read -r fn
do
echo "about to remove file $fn"
rm -f $fn
done

This assumes there are no files from a year ago in the directory

recommend not running my code which is provided with no warranty with the rm the first time you try it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
redhat7012
Advisor

Re: How to delete the Files in HP-UX Box ?

But i want to remove files related to Sep 12th 2012.

 

But if the files contain Sep 12th 2011, Then How ?

 

 

Steven E. Protter
Exalted Contributor

Re: How to delete the Files in HP-UX Box ?

Use

ls -larte

 

for a full listing including year. My code will need to be altered. Let me know if you need help with that.

 

SEP

Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: How to delete files on HP-UX box?

>But if the files contain Sep 12th 2011, Then how?

 

Look for a ":" to indicate a time vs year:

ll | grep "Sep 12 ..:" | awk '{ print $NF}' | while read -r fn; do

Patrick Wallek
Honored Contributor

Re: How to delete files on HP-UX box?

Why are we getting so complicated?

-rw-r--r--    1 root     system       599751 Sep 12 12:32 1209121159_wsmncp01.log
-rw-r--r--    1 root     system       602065 Sep 12 18:29 1209121759_wsmncp01.log
-rw-r--r--    1 root     system       600927 Sep 13 00:24 1209122359_wsmncp01.log
-rw-r--r--    1 root     system       582738 Sep 13 01:15 1309120059_wsmncp01.log
-rw-r--r--    1 root     system       589388 Sep 13 06:18 1309120559_wsmncp01.log
-rw-r--r--    1 root     system       598967 Sep 13 12:30 1309121159_wsmncp01.log
-rw-r--r--    1 root     system       600927 Sep 13 18:24 1309121759_wsmncp01.log
-rw-r--r--    1 root     system       602457 Sep 14 00:34 1309122359_wsmncp01.log

According to the file listing the files appear to have the date and time as part of the file name.  The format appears to me to be DAY MONTH YEAR (2 digit) HOUR MINUTE _wsmncp01.log.

 

So, if you want the files from Sep 12, 2012 then you should look for:

 

120912*_wsmncp01.log