查看以及一级磁盘目录大小:
df -h
查看当前目录下文件的大小:
du -sh *
查找文件:
find / -name 文件名
查看进程:
ps -ef|grep 进程名
杀死进程:
kill -9 进程号
实时查看日志:
tail -f 日志文件路径
实时查看日志并检索关键字
tail -f 日志文件路径|grep 关键字
查看最近的100条日志记录并检索关键字
tail -f 日志文件路径|grep 关键字
上传/下载文件:
alt+p进入sftp窗口
put 本地文件的全路径
get 文件名(默认是sftp当前目录中文件), 默认下载到C:Users11275Documents中
nohup命令:
保证进程永久执行: nohup python jira.py &
nohup启动并指定日志所在位置: nohup java -jar opd.jar >/toll/logs/support.log &
windows编辑的shell脚本在linux下不识别' '的问题:
解决: linux下输入命令: sed -i 's/ //' opd.sh && bash opd.sh
linux项目启动shell脚本:
#!/bin/bash #这里可替换为你自己的执行程序的文件名 APP_NAME=opd #使用说明,用来提示输入参数 usage(){ echo "Usage: sh ${APP_NAME}.sh [start|stop|restart|status]" exit 1 } #检查程序是否在运行 is_exist(){ pid=`ps -ef|grep $APP_NAME.jar|grep -v grep|awk '{print $2}'` #如果不存在返回1,存在返回0 if [ -z "${pid}" ]; then return 1 else return 0 fi } #启动方法 start(){ is_exist if [ $? -eq 0 ]; then echo "${APP_NAME} is already running. pid=${pid}" else # 执行jar的命令,nohup表示永久运行。&表示后台运行 # ../server/${APP_NAME}.jar要根据自己的jar的位置 # --server.port=8001 设置端口 # ../serverlogs/${APP_NAME}.log日志想要输出的位置 # nohup java -jar ../server/${APP_NAME}.jar --server.port=8001 >> ../serverlogs/${APP_NAME}.log 2>&1 & nohup java -Xms1024M -Xmx2048M -jar ${APP_NAME}.jar > /dev/null 2>&1 & echo "${APP_NAME} start success" fi } #停止方法 stop(){ is_exist if [ $? -eq "0" ]; then kill -9 $pid echo "${APP_NAME} stop success" else echo "${APP_NAME} is not running" fi } #输出运行状态 status(){ is_exist if [ $? -eq "0" ]; then echo "${APP_NAME} is running. Pid is ${pid}" else echo "${APP_NAME} is not running." fi } #重启 restart(){ stop # 休眠1秒 sleep 1 start echo "${APP_NAME} restart success" } #根据输入参数,选择执行对应方法,不输入则执行使用说明 case "$1" in "start") start ;; "stop") stop ;; "status") status ;; "restart") restart ;; *) usage ;; esac
Linux 项目输出日志中文变问号
Step 1
$ vim /etc/locale.conf
LANG="zh_CN.UTF-8"
Step 2
$ vim ~/.bashrc # 追加 export LANG='UTF-8' export LC_ALL='zh_CN.UTF-8' export LC_CTYPE='zh_CN.UTF-8'
$ source ~/.bashrc
Step 3
重启项目
LINUX校对时间
首先使用 date 查看当前时间是否准确 校准时间命令 ntpdate cn.pool.ntp.org 如果没有权限: sudo -i 会出现输入密码,直接输入密码即可 再次执行校准时间操作命令 ntpdate cn.pool.ntp.org 操作完成之后,查看时间是否准确 date