shell脚本&Linux笔记

计算程序运行时间 & 休眠

starttime=`date +'%Y-%m-%d %H:%M:%S'`
#执行程序
sleep 10
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
echo "本次运行时间: "$((end_seconds-start_seconds))"s"

快捷键

Linux系统下Shell重复执行上条命令的 4 种方法:

  • 使用上方向键,并回车执行
  • 按 !! 并回车执行
  • 输入 !-1 并回车执行
  • 按 Ctrl+P 并回车执行

通过文件名获取全路径

# 方法1
readlink -f note.txt
# 方法2
ls $PWD/note.txt
# 输出
# /home/users/note.txt

判断文件是否存在

if [ -f "./the_file.sh" ]; then
  rm ./the_file.sh
  else
  echo "the file doesn't exit"
fi

Ubuntu查看系统版本号

lsb_release  -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.2 LTS
Release:        20.04
Codename:       focal

Ubuntu更新命令

sudo apt-get install dpkg
posted @ 2020-12-06 13:36  illmatic  阅读(65)  评论(0编辑  收藏  举报