My Unix Linux Notes

How to extract/expand/explode file.tar.gz, or file.tgz:
gtar xzvf file.tar.gz # if gtar is available, otherwise,
gunzip < file.tgz | tar xvf -

Note the use of < (gunzip file.tgz | tar xvf - won't work). You can always run gunzip and tar in 2 steps, which creates an extra tar file:
gunzip file.tar.gz
tar xvf file.tar
How to find a port number (8080) in use:
netstat -an | grep 8080
How to kill all java processes:
killall java

How to list all background jobs:
jobs
[1] Running ./standalone.sh


How to kill the current background job:
kill %

How to list all java processes:
$JAVA_HOME/bin/jps
$JAVA_HOME/bin/jps -l
$JAVA_HOME/bin/jps -lv
ps -ef | grep java    # more reliable than jps


How to find a java (jboss) process with jps and kill it:
jps | grep jboss | awk '{print $1}' | xargs kill -9


How to find a jboss process with "ps -ef" and kill it:
ps -ef | grep -v grep | grep jboss | awk '{print $2}' | xargs kill -9


Note that in "ps -ef" output, the PID is the 2nd column, after UID. This is different from "ps" and "jps..." output, where PID is column 1.

How to find a file is opened by which program and user (takes a while to finish):
lsof | vim -


How to list all files in current directory in absolute path (for copying the path):
find $PWD


How to sort a list of items (e.g., file paths) and remove duplicates:
sort a.txt > b.txt
uniq b.txt > c.txt

Followers

Pageviews Last 7 Days