05-jar
1. Log
1. nohup
no hang up
- Linux nohup 命令
默认情况下(非重定向时),会输出一个名叫 nohup.out
的文件到当前目录下,如果当前目录的 nohup.out
文件不可写,输出重定向到 $HOME/nohup.out
文件中
# nohup Command [ Arg … ] [ & ]
# 日志重定向覆盖到nohup.log
# nacos.nacos 为进程名称
nohup $JAVA ${JAVA_OPT} nacos.nacos >nohup.log 2>&1 &
# 日志重定向append到nohup.log
nohup $JAVA ${JAVA_OPT} nacos.nacos >>nohup.log 2>&1 &
2. 2>&1
名称 | 代码 | 操作符 | java中表示 | Linux 下文件描述符(Debian 为例) |
---|---|---|---|---|
standard input (stdin) | 0 | < 或 << | System.in | /proc/self/fd/0 -> /dev/pts/0 |
standard output (stdout) | 1 | >, >>, 1> 或 1>> | System.out | /dev/stdout -> /proc/self/fd/1 -> /dev/pts/0 |
standard error (stderr) | 2 | 2> 或 2>> | System.err | /dev/stderr -> /proc/self/fd/2 -> /dev/pts/0 |
echo "hello" > t.log
# 和上面等价,本质是标准输出到log
echo "hello" 1> t.log
3. tail
# 实时监视向日志文件增加的信息
# tail -f 等同于–follow=descriptor,根据文件描述符进行追踪,当文件改名或被删除,追踪停止
tail -f nohug.log
# 滚动显示最后100行
tail -f -n 10 nohug.log
# tail -F 等同于–follow=name --retry,根据文件名进行追踪,并保持重试,即该文件被删除或改名后,如果再次创建相同的文件名,会继续追踪
tail -F nohug.log
4. ps
# -ef 参数显示所有命令,连带启动时的命令行参数
ps -ef | grep yourCommand