linux - Linux mv 命令然后关机
问题描述
我有这个在 Ubuntu 16.04 上运行的小 bash 脚本(简化):
tar zxvf fileNameHere.tgz <-- Untar tgz file in $SRC_DIR
files=$(ls $SRC_DIR)
echo "Extracting $files" >> $APP_LOG_DIR/update.log
mv $SRC_DIR/* $OUTPUT_DIR
shutdown -r now
我注意到,重新启动后,只有有时文件没有移动到目标,我想知道该关闭命令是否可能是一个问题。关机前是否需要调用“同步”?
解决方案
修复了带有注释的脚本:
#!/usr/bin/env bash
# Test if SRC_DIR and OUTPUT_DIR are actual directories
if [ -d "$SRC_DIR" ] && [ -d "$OUTPUT_DIR" ]; then
# Populates the arguments array with the content
# of SRC_DIR rather than parsing the output of ls
set -- "$SRC_DIR/"*
# Prints joined file entries of the arguments array
# while stripping their leading directory path
printf 'Extracting %s\n' "${*#*/}" >> "$APP_LOG_DIR/update.log"
# Moves all the arguments array's entries (the actual
# content of the SRC_DIR) into OUTPUT_DIR
mv -- "$@" "$OUTPUT_DIR/"
shutdown -r now
fi
推荐阅读
- c# - 从 1 项中查找元组列表的索引
- python - 如何在 Python 中为用户定义的函数添加计数器?
- docker - 在 CI/CD 管道中推送图像的目的是什么?
- ios - 另一个集合视图中集合视图单元格的约束
- javascript - TypeError: expect(...).to.startsWith 不是函数 - chai 和 chakram
- c# - 当玩家与物体碰撞时,我们如何显示图像?
- service - 是否可以同时运行两个 apk 并使它们通过 Windows 服务进行通信?
- swift - 快速解析 XML 失败并出现 nil 错误
- c - 分配指向列表中下一个节点的指针
- css - CSS - 根据同一 Div 内的图像颜色更改 Div 背景颜色