Kill all processes listening on a particular port
Answer:
To kill all processes listening on a particular port, e.g. port 80
# kill -9 $( lsof -i:80 -t )
Replace 80 by the port you want.
Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.
Kill all processes listening on a particular port
Answer:
To kill all processes listening on a particular port, e.g. port 80
# kill -9 $( lsof -i:80 -t )
Replace 80 by the port you want.
How to check the startup time of a particular program
Answer:
E.g. To check the startup time of MySQL server:
# ps -eo pid,user,cmd,lstart | grep /sbin/mysqld
3546 mysql /usr/sbin/mysqld --basedir= Tue Mar 30 21:29:12 2010
9195 root grep /sbin/mysqld Tue Mar 30 22:43:33 2010
How to execute prorgam in the current directory
Answer:
1. Make sure the program is executable
# chmod a+x my_program
2. Run it by appending ./ in the front of file name
# ./my_program
./ is needed if the current directory is not in your current search path (PATH)
Count the number of matching lines from grep
Answer:
grep command is useful for searching file's content by a key string, e.g.
# grep foo text.txt
All the lines matching foo will be printed.
However, to only print the number of matching lines, you can use the -c flag
# grep -c foo text.txt
4
There are total 4 lines match the word foo.
Generate dummy file in Linux
Answer:
To generate random files of fixed size (e.g. 1GB) in Linux:
dd if=/dev/zero of=test.bin bs=1000000000 count=1
You can adjust the file size by setting the bs parameter (byte size).