Linux Command Cheatsheet and Java Diagnostic Tools for System Operations
This article compiles essential Linux commands and a suite of Java diagnostic utilities—including tail, grep, awk, find, tsar, btrace, Greys, JProfiler, and others—providing concise examples and code snippets to help engineers troubleshoot and monitor production systems efficiently.
Preface
In daily work we often encounter difficult problems; this note records useful Linux commands and Java diagnostic tools as a personal reference and to share with colleagues.
Linux command collection
tail
Commonly used tail -300f shopbase.log to display the last 300 lines and follow the file.
grep
Examples of searching files and directories, including multi‑file search, recursive search, case‑insensitive, include/exclude patterns, and context options.
grep forest f.txt # file search
grep forest f.txt cpf.txt # multi‑file search
grep 'log' /home/admin -r -n # recursive search
cat f.txt | grep -i shopbase
grep 'shopbase' /home/admin -r -n --include *.{vm,java} # include extensions
grep 'shopbase' /home/admin -r -n --exclude *.{vm,java} # exclude
seq 10 | grep 5 -A 3 # after match
seq 10 | grep 5 -B 3 # before match
seq 10 | grep 5 -C 3 # context
cat f.txt | grep -c 'SHOPBASE'awk
Basic usage, pattern matching and built‑in variables (NR, FNR, NF) with examples.
awk '{print $4,$6}' f.txt
awk '{print NR,$0}' f.txt cpf.txt
awk '{print FNR,$0}' f.txt cpf.txt
awk '{print FNR,FILENAME,$0}' f.txt cpf.txt
awk '{print FILENAME,"NR="NR,"FNR="FNR,"$"NF"="$NF}' f.txt cpf.txt
echo 1:2:3:4 | awk -F: '{print $1,$2,$3,$4}'
# matching examples
awk '/ldb/ {print}' f.txt
awk '!/ldb/ {print}' f.txt
awk '/ldb/ && /LISTEN/ {print}' f.txt
awk '$5 ~ /ldb/ {print}' f.txtfind
Various find command usages for searching files by name, type, size, permissions, and time.
sudo -u admin find /home/admin /tmp /usr -name *.log
find . -iname *.txt
find . -type d
find /usr -type l
find /usr -type l -name "z*" -ls
find /home/admin -size +250000k
find /home/admin -perm 777 -exec ls -l {} ;
find /home/admin -atime -1
find /home/admin -ctime -1
find /home/admin -mtime -1
find /home/admin -amin -1
find /home/admin -cmin -1
find /home/admin -mmin -1pgm
Batch query logs for vm‑shopbase.
pgm -A -f vm-shopbase 'cat /home/admin/shopbase/logs/shopbase.log.2017-01-17|grep 2069861630'tsar
Company‑internal metric collection tool; examples to view recent day, live metrics, specific date, and individual metrics.
tsar # recent day metrics
tsar --live # live metrics, refresh every 5 seconds
tsar -d 20161218 # specific day (up to four months)
tsar --mem
tsar --load
tsar --cputop / ps
Use ps -ef | grep java and top -H -p pid to locate Java threads, then convert thread IDs for jstack analysis.
Other diagnostic tools
Includes btrace, Greys, javOSize, JProfiler, Eclipse MAT, zprofiler, jps, jstack, jinfo, jmap, jstat, jdb, CHLSDB, and various IntelliJ plugins. Typical commands are shown below.
# btrace example (monitor ArrayList.add when size>500)
# Greys sc -df xxx (class detail)
# jps -mlvV
sudo -u admin /opt/taobao/java/bin/jstack 2815
sudo -u admin /opt/taobao/java/bin/jstack -m 2815
sudo -u admin /opt/taobao/java/bin/jinfo -flags 2815
sudo -u admin /opt/taobao/java/bin/jmap -heap 2815
sudo -u admin /opt/taobao/java/bin/jmap -dump:live,format=b,file=/tmp/heap2.bin 2815
sudo -u admin /opt/taobao/java/bin/jmap -histo 2815 | head -10
sudo -u admin /opt/taobao/java/bin/jstat -gcutil 2815 1000
sudo -u admin /opt/taobao/java/bin/jdb -attach 8000Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
