转载

常用命令归纳:Linux/Oracle/JVM/Git

经常用到一些命令,还总是忘掉的,就简单列在这里。总是现查也挺麻烦的。

Linux:

  • top mem consumer: sudo ps -aux | sort -k4nr | head -5 or top, then press M
  • connection number: netstat -an | grep ESTABLISHED | wc –l
  • process number: ps -ef | wc -l
  • threads of a process: ps uH p <pid> | wc -l
  • .tar: tar -xvf archive.tar and tar -cvf archive.tar file1
  • .tar.gz: tar -cvfz archive.tar.gz dir1 and tar -xvfz archive.tar.gz
  • .zip: zip -r archive.zip ./folder and unzip archive.zip -d ./
  • empty a file: sudo cat /dev/null
  • capture all the output and run in the background: bb > /tmp/a.txt 2>&1 &
  • list the latest changed files: ls -lht | head (log文件一大堆的时候用来找最新的)
  • check folder size: du -h –max-depth=1 ./ (磁盘空间不够的时候经常用来看谁是罪魁祸首)
  • search for 10M+ files: find . -size +10M
  • ssh -qTfnN -D 9999 username@hostname
  • ssh tunnel_host_name -L 60553:target_host_name:60553

Oracle:

  • SELECT CONVERT(DESCRIPTION, 'WE8ISO8859P1', 'UTF8') FROM TABLE_NAME;
  • TAB, ALL_TABLES, USER_TABLES
  • SELECT SEGMENT_NAME, BYTES FROM USER_SEGMENTS WHERE SEGMENT_TYPE = 'TABLE';
  • USER_USERS, USER_ROLE_PRIVS, SESSION_PRIVS;
  • ALL_INDEXES, USER_INDEXES
  • V$SESSION
  • 最大连接数:SELECT VALUE FROM V$PARAMETER WHERE NAME = 'PROCESSES';
  • 当前连接数:SELECT COUNT(1) FROM V$PROCESS;
  • 表空间:SELECT T.TABLESPACE_NAME, ROUND(SUM(BYTES/(1024*1024)),0) TS_SIZE FROM DBA_TABLESPACES T, DBA_DATA_FILES D WHERE T.TABLESPACE_NAME = D.TABLESPACE_NAME GROUP BY T.TABLESPACE_NAME;
  • 文件大小:SELECT TABLESPACE_NAME, FILE_ID, FILE_NAME, ROUND(BYTES/(1024*1024),0) TOTAL_SPACE FROM DBA_DATA_FILES ORDER BY TABLESPACE_NAME;
  • V$ROLLNAME, V$ROLLSTAT, V$UNDOSTAT, V$TRANSACTION

JVM:

  • Tomcat debug: -agentlib:jdwp=transport=dt_socket,address=8088,server=y,suspend=n
  • JProfiler: -agentpath:/opt/jprofiler7/bin/linux-x64/libjprofilerti.so=port=8080,nowait
  • JConsole: -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=3306 -Dcom.sun.management.jmxremote
  • Print default parameters: java -XX:+PrintFlagsFinal -version
  • jmap -histo <pid>
  • jmap -heap <pid>
  • jmap -permstat <pid>
  • jmap -dump:format=b,file=/xxx.hprof <pid>
  • jhat -baseline 1.hprof 2.hprof
  • jstack -l <pid>
  • jstat -gc <pid>
  • jstat -gccapacity <pid>
  • jstat -compiler <pid>
  • jstat -class <pid>
  • 另外,有一些JVM问题定位的工具,总结在这里

Git:

  • git clone <repo>
  • git config –list
  • git diff –staged
  • add后,commit前的撤销:git rm –cached
  • commit后的回滚:git reset –hard commit-id,比如:git reset –hard HEAD
正文到此结束
Loading...