Thursday, February 12, 2015

Some useful linux commands

head: Used to get a part of a big file.

Example:

head -167970 input.txt | tail -7 

display 7 lines from line 167970.

head -167970 input.txt | tail -7 >> tmp.txt 

write 7 lines from line 167970 into file.

tail: Used to show end of file continuously.
Example:
tail -f catalina.out

ps: Used to show running processes.
Example:
ps -ef | grep java
Display processes of which name contains 'java'.

kill: Used to kill a process.
Example:
kill -9 123456 
kill the process of which id is 123456.

less: Used to view a file. 
After a file is opened by less: 
g: go to the beginning of the file
G: go to the end of the file
(For more information: http://linux.about.com/library/cmd/blcmdl1_less.htm)
Example:
less product.log 
view the file product.log.

sed: Used to view a specific part of a file.
Example:
sed -n '5,10p' input.txt
display the part of input.txt from line 5 to 10. 


top: Used to display running processes.


df -h: Used to display disk sizes.


ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNS: 
Used to display memory usage of processes.


cp -avr source_dir dest_dir: Used to copy directory.

rm -rf directory: Used to remove directory.

java -cp lib/catalina.jar org.apache.catalina.util.ServerInfo:
Used to display version of Tomcat, JVM and OS.

truncate a file: 
sudo truncate snort.log --size 0

change ip address:
ifconfig eth0 192.168.1.5


show open ports:
nmap -sT localhost





No comments:

Post a Comment