Operating System - HP-UX
1820277 Members
3202 Online
109622 Solutions
New Discussion юеВ

Re: HELP !!! Can not delete the huge logs ...

 
SOLVED
Go to solution
Rami Al-Lolah
Advisor

HELP !!! Can not delete the huge logs ...

Team,

I have an application directory full of a very huge number of log files. Whenever I am trying to list or delete the files; the UNIX replies with 'ksh: /usr/bin/ll: arg list too long'.

I have tried an external FTP application to access that directory and delete these logs but with no success also.

Do you have any healing potion for that desease? Any ideas ... scripts... HELP!!!!!!
It is not too late to start.
17 REPLIES 17
Eugeny Brychkov
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Rami,
if you know logs' file names try to refine ll/rm output, for example
rm a*
rm b*
....
I wonder why ll tells 'arg list too long'. Maybe you have corrupt file names in directory? Foy example, beginning with '-' (like arg)? Or you supplying ll with arg using pipe?
Eugeny
Raimo Lesonen_1
Advisor

Re: HELP !!! Can not delete the huge logs ...

When you get "list too long", use find instead, like:
Use find . -name '*.log' -exec rm {} \;


Regards,
Raimo
Clemens van Everdingen
Honored Contributor
Solution

Re: HELP !!! Can not delete the huge logs ...

Hi,

Find and delete all files 30 days and older:

find /tmp/* -atime +30 -exec rm {} \;

replace /tmp for anything you want.
replace rm for any command you like .

C.
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
Christian Gebhardt
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Hi

cd /dir
find . -name "*" -exec ls -l {} \;
find . -name "*" -exec rm {} \;

Chris
Rami Al-Lolah
Advisor

Re: HELP !!! Can not delete the huge logs ...

Clemens and others, thanks for the quick response, however, when I executed 'find pr.tr*.log -atime +30' just to view the files, it replies with 'ksh: /usr/bin/find: arg list too long' also ... I know that I have thousands of logs in that directory.
It is not too late to start.
Clemens van Everdingen
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Hi,

Try narrowing it down !
Just use 60 or 120 to make the list smaller.
I don't know how old the oldest file is ?
are they all from a recent date ?

Post the exact command you used to do the listing !

C.
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
Rami Al-Lolah
Advisor

Re: HELP !!! Can not delete the huge logs ...

Clemens and Christian, I have combined what you have told me in this command ???find . -name "pr.tr*.log" -atime +1 -exec rm {} \;???.

I have tried the first part of it to only display the files and I could do this successfully. Now, I have added the Clemens???s timing part, which I really liked. Is that command OK with you and safe to execute ?????
It is not too late to start.
Clemens van Everdingen
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Hi,

I would try this command first:

find . -name "pr.tr*.log" -atime +1 -exec ls -l {} \;???

Eventually it will come up with arg list too long.

Then replace the 1 for 5 or 10 to narrow down the list total.
If this works without arg list too long and the files you see are ok to delete then replace the ls -l for rm !

This just to be sure you delete the right files !!!!

C.
The computer is a great invention, there are as many mistakes as ever, but they are nobody's fault !
Simon Hargrave
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

The reason you're still getting the arg list to long error with the find command is if you use : -

find /tmp/* ... then this is passing a huge list to the find command. This is not required and is in fact bad practice.

You should always if possible give find a directory name, not a list of files as the above syntax does. eg always use find . or find /, rather than find * or any other wildcard. The wildcards should be in your -name parameter.
Rami Al-Lolah
Advisor

Re: HELP !!! Can not delete the huge logs ...

Any ideas how can I display log files that older than (i.e. 10 days). Note that these logs were not accessed, changed or modified ... Thanks
It is not too late to start.
Simon Hargrave
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

find /logfiledir -mtime +10 -exec ls -l {} \;
Rajeev  Shukla
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Hi try this..

find /logdirectory -atime +10 -exec ll {} \;


Rajeev
Khalid A. Al-Tayaran
Valued Contributor

Re: HELP !!! Can not delete the huge logs ...


Hi Rami,

Use the following:

find /path -mame fileName -mtime +1

or

ls /dir | more

or

ls /dir | grep fileName


Good luck.
Khalid A. Al-Tayaran
Valued Contributor

Re: HELP !!! Can not delete the huge logs ...


Hi,

Sorry, I made a typing mistake. the command should be like this:

# find /path -name filrname -mtime +1


or use the locate script if you know the names of those log files.

# locate fileName

or

# locate fileName | more

or

# locate fileName | grep string

where string is the name of the file


Script is attached and is also found in the scripts thread and update the the search databse frequently. Link: http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x836cc1c4ceddd61190050090279cd0f9,00.html


Good luck again...
V. Nyga
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Hi,

try to make a list off only a part of the files
or try:
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0xc5620fe6d0f7d61190050090279cd0f9,00.html
It's a problem of ls, rm and mv that the argument list could be too long.

Try mtime as big as possible.

Regards
Volkmar
*** Say 'Thanks' with Kudos ***
John Poff
Honored Contributor

Re: HELP !!! Can not delete the huge logs ...

Hi,

You mentioned that you were trying this:

'find pr.tr*.log -atime +30'

I think you may have a problem with the asterisk (*) getting expanded by the shell. Try it like this:

find -name 'pr.tr*.log' -atime +30

The single quotes will protect the * from the shell and keep it from getting expanded when the parameter is passed to the 'find' command.

JP
Rami Al-Lolah
Advisor

Re: HELP !!! Can not delete the huge logs ...

What I have did was obtaining an offline list of all the log files located under that directory, and directed the results of the 'find aiprod32 -name "pr.tr*.log" -print > ailogs.dat' command to the file 'ailogs.dat'

I executed a script which I have made to delete that log files found in 'ailogs.dat' one by one ...... This I found it more effecient than using 'find . -name "pr.tr*.log" -mtime +1 -exec rm {} \;'.

The script is as follow:

COUNT=0

cat ailogs.dat | while read currentLog
do
let COUNT=$COUNT+1
echo $COUNT $currentLog
rm $currentLog
done
It is not too late to start.