`

Linux常用命令

阅读更多

================================================================================
free
http://linux.vbird.org/linux_basic/0440processcontrol.php#free
bash-3.2$ free -m
             total       used       free     shared    buffers     cached
Mem:         32185      31891        293          0        270      16845
-/+ buffers/cache:      14776      17409
Swap:         8189          0       8189
================================================================================
不删除文件,清空文件内容命令
true >log.txt
================================================================================
top 動態觀察程序的變化
http://linux.vbird.org/linux_basic/0440processcontrol.php#top

================================================================================
nohup java -jar something-2.0.jar [可配置参数]  > /指定某目录/logs/nohup.log &
s
nohup command url:http://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html
[摘要
Most of the time you login into remote server via ssh. If you start a shell script or command and you exit (abort remote connection), the process / command will get killed. Sometime job or command takes a long time. If you are not sure when the job will finish, then it is better to leave job running in background. However, if you logout the system, the job will be stopped. What do you do?

nohup command
Answer is simple, use nohup utility which allows to run command./process or shell script that can continue running in the background after you log out from a shell:

nohup Syntax:

nohup command-name &

Where,

command-name : is name of shell script or command name. You can pass argument to command or a shell script.
& : nohup does not automatically put the command it runs in the background; you must do that explicitly, by ending the command line with an & symbol.
]

http://hi.baidu.com/zhaolegend/blog/item/245ad226e860bdfed7cae2ed.html

先说一下linux重定向:
0、1和2分别表示标准输入、标准输出和标准错误信息输出,可以用来指定需要重定向的标准输入或输出。
在一般使用时,默认的是标准输出,既1.当我们需要特殊用途时,可以使用其他标号。例如,将某个程序的错误信息输出到log文件中:./program 2>log。这样标准输出还是在屏幕上,但是错误信息会输出到log文件中。
另外,也可以实现0,1,2之间的重定向。2>&1:将错误信息重定向到标准输出。
Linux下还有一个特殊的文件/dev/null,它就像一个无底洞,所有重定向到它的信息都会消失得无影无踪。这一点非常有用,当我们不需要回显程序的所有信息时,就可以将输出重定向到/dev/null。

如果想要正常输出和错误信息都不显示,则要把标准输出和标准错误都重定向到/dev/null, 例如:

# ls 1>/dev/null 2>/dev/null

还有一种做法是将错误重定向到标准输出,然后再重定向到 /dev/null,例如:

# ls >/dev/null 2>&1

注意:此处的顺序不能更改,否则达不到想要的效果,此时先将标准输出重定向到 /dev/null,然后将标准错误重定向到标准输出,由于标准输出已经重定向到了/dev/null,因此标准错误也会重定向到/dev/null,于是一切静悄悄:-)

 

由于使用nohup时,会自动将输出写入nohup.out文件中,如果文件很大的话,nohup.out就会不停的增大,这是我们不希望看到的,因此,可以利用/dev/null来解决这个问题。

nohup ./program >/dev/null 2>log &

如果错误信息也不想要的话:

nohup ./program >/dev/null 2>&1 &

================================================================================
sudo -u username bash
The -u (user) option causes sudo to run the specified command as a user other than root. To specify a uid instead of a username, use #uid.

================================================================================
查看主机名字
hostname

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics