计算程序运行时间 & 休眠
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