Linux 系统命令

1、ctrl+z 让正在运行的任务暂停运行, 然后可用 bg %jobId使之后台运行,相当于: 命令 &

2、 jobs -l 查看任务

3、 echo $$ 查看当前进程

4、nohup 或者 setpid 是 执行的程序进程脱离当前 shell

5、 unzip -o xxx.zip -d direcotry

6、 crontab -l 、 crontab -e

7、 du -sh 查看当前目录下文件总大小、 du -h --max-depth=1 查看当前目录下最上层个子目录的大小 

8、 top 监控进程cpu 和内存

9、 free 查看内存使用

10、 whereis 文件名, 查找文件路径, 如: whereis java, which 

  which       查看可执行文件的位置 
  whereis    查看文件的位置 
  locate       配 合数据库查看文件位置 
  find          实际搜寻硬盘查询文件名称 

11、 uname -a、cat /proc/version、cat /etc/issue 查看系统信息

12、 让正在运行的运行的任务忽略hup信号,不再因为当前shell关闭而退出运行。disown -h %{jobid} 或 disown -ah | disown -rh。而单独 disown 命令会删除任务,千万别这么做~

 disown [-ar] [-h] [jobspec ...] Without options, each jobspec is removed from the table of active jobs. If the -h option is given, each jobspec is not removed from the table, but is marked so that SIGHUP is not sent to the job if the shell receives a SIGHUP. If no jobspec is present, and neither the -a nor the -r option is supplied, the current job is used. If no jobspec is supplied, the -a option means to remove or mark all jobs; the -r option without a jobspec argument restricts operation to running jobs. The return value is 0 unless a jobspec does not specify a valid job. 

  • disown -h jobspec 来使某个作业忽略HUP信号。
  • disown -ah 来使所有的作业都忽略HUP信号。
  • disown -rh 来使正在运行的作业忽略HUP信号。

13、 lsof 查看系统打开的文件, 还能用来恢复误删除的文件, 可参考 linux lsof详解 

  

lsof 4.86
latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
[-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Defaults in parentheses; comma-separated set (s) items; dash-separated ranges.
-?|-h list help -a AND selections (OR) -b avoid kernel blocks
-c c cmd c ^c /c/[bix] +c w COMMAND width (9) +d s dir s files
-d s select by FD set +D D dir D tree *SLOW?* +|-e s exempt s *RISKY*
-i select IPv[46] files -K list tasKs -l list UID numbers
-n no host names -N select NFS files -o list file offset
-O no overhead *RISKY* -P no port names -R list paRent PID
-s list file size -t terse listing -T disable TCP/TPI info
-U select Unix socket -v list version info -V verbose search
+|-w Warnings (+) -X skip TCP&UDP* files -- end option scan
+f|-f +filesystem or -file names +|-f[gG] flaGs
-F [f] select fields; -F? for help
+|-L [l] list (+) suppress (-) link counts < l (0 = all; default = 0)
+m [m] use|create mount supplement
+|-M portMap registration (-) -o o o 0t offset digits (8)
-p s exclude(^)|select PIDs -S [t] t second stat timeout (15)
-T qs TCP/TPI Q,St (s) info
-g [s] exclude(^)|select and print process group IDs
-i i select by IPv[46] address: [46][proto][@host|addr][:svc_list|port_list]
+|-r [t[m<fmt>]] repeat every t seconds (15); + until no files, - forever.
An optional suffix to t is m<fmt>; m must separate t from <fmt> and
<fmt> is an strftime(3) format for the marker line.
-s p:s exclude(^)|select protocol (p = TCP|UDP) states by name(s).
-u s exclude(^)|select login|UID set s
-x [fl] cross over +d|+D File systems or symbolic Links
names select named files or files on named file systems
Anyone can list all files; /dev warnings disabled; kernel ID check disabled.

lsof filename

lsof -p {pid}

lsof -i :port

lsof /proc/{pid}/fd/{fid}

 

 找回被删除文件:

ps -ef|grep `pwd`
lsof -p 93584|grep dlog*0.0.1.jar
cat /proc/93584/fd/4 > /tmp/dlog_pizza-0.0.1.jar.bak
sz /tmp/dlog_pizza-0.0.1.jar.bak

 

 

 

参考资料:

1、 http://blog.sina.com.cn/s/blog_605f5b4f0100x2bq.html 让Linux终端中执行的程序在后台运行 从前台变到后台

2、 http://os.51cto.com/art/201312/425014.htm 十个鲜为人知的 Linux 命令 - Part 4

3、http://www.cnblogs.com/peida/archive/2012/11/09/2761928.html 每天一个linux命令(17):whereis 命令

4、Linux下which、whereis、locate、find 命令的区别 

5、http://heylinux.com/archives/1282.html  Linux运行与控制后台进程的方法:nohup, setsid, &, disown, screen

6、Linux 技巧:让进程在后台可靠运行的几种方法  https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/

7、http://blog.csdn.net/bytxl/article/details/24018015  linux进程后台运行的几种方法 - nohup/setsid/&/disown/screen

8、linux lsof详解

 

posted @ 2016-11-09 20:50  xunux  阅读(253)  评论(0编辑  收藏  举报