Showing posts with label linux commands. Show all posts
Showing posts with label linux commands. Show all posts

Sunday, August 24, 2008

Linux: "Argument list too long" error when trying to use '/bin/rm' command

This error is not very common but this is something that you will see for sure in your daily routine if you are a Linux user. Lets say you are working with Apache webserver and there comes a situation where you have to delete log files for Apache.

[root @ guest logs]# pwd
/u01/app/oracle/product/j2ee/Apache/Apache/logs
[root @ guest logs]# ls -l | grep log | wc -l
5195
Try issuing the "rm" command to delete those long list of files
[root @ guest logs] # rm *log*
/bin/rm: Argument list too long.
If that returns an error message regarding "Argument list too long" then there are
alternatives to remove the files. It seems that the rm command can't deal with such
number of arguments. Fortunately there are some workarounds for this problem.

You can combine rm with find:

find . | xargs rm -f

Or if you want to delete all the files in the directory with a single stroke issue the following code:

ls | xargs rm -f

Sunday, August 17, 2008

Kill -9: How to kill running process if everything fails in linux

I bet you came across a situation when you tried to kill a process in Linux but it will be never killed.

kill -9 does the trick

I don't recommend you to use kill -9 all the time.

So that your important applications may close themselves, it is very important you follow this procedure when killing them:

kill pid (sends a TERM, wait 5 seconds)
kill pid (yes, try again, wait 5 seconds)
kill -INT pid (wait for it)
kill -INT pid (damn, still not dead?)
kill -KILL pid (same thing as -9)
kill -KILL pid (something is wrong)

If the process is still running, then stop sending it signals. It's either stuck in I/O wait or it's Defunct. 'ps auxw | grep processname', if you see it's in state D, then kill its parent process (the 3rd column of 'ps -ef' is the parent pid). If it's in I/O wait, then you have a deeper system problem. Most home users will never have this problem.