【发布时间】:2021-11-13 00:43:54
【问题描述】:
所以我整理了以下 bash 脚本,我想修改我抓取的文件路径目录
所以我的布局是这样的
/home/videos_test/categoryname/1/vid.mp4
/home/videos_test/categoryname/2/randomvid.mp4
我想修改它抓取的文件路径,使其看起来像这样
/home/videos_test/changed_folder/1/vid.mp4
/home/videos_test/changed_folder/2/randomvid.mp4
完整脚本
#!/bin/bash
echo "Type the category that you want, followed by [ENTER]:"
read category
export FILE_PATH="/home/videos_test"
export STAR="/*"
FILE_PATH=$FILE_PATH"/"$category;
echo $FILE_PATH;
minimumsize=1000
for dir in $FILE_PATH$STAR$STAR; do
[[ ! -f "${dir}" ]] && continue # if its NOT a file then skip
actualsize=$(du -k "$dir" | cut -f 1)
if [[ ! $actualsize -ge $minimumsize ]]; then #if file is less than 1mb delete it
echo $dir
echo size is under $minimumsize kilobytes
rm "$dir"
echo deleted
else #for files over 1mb in size convert with ffmpeg
full_file=$(basename $dir)
full_dir=$(dirname $dir)
echo $full_file
echo $full_dir
ffmpeg -i "$dir"
#ffmpeg output file directory needs to be mirrored but with a folder change
read -p "Press any key to resume ..."
fi
done
我想成为 ffmpeg 的文件夹输出
/home/videos_test/$category _new/1/vid.mp4
/home/videos_test/$category _new/2/randomvid.mp4
【问题讨论】:
-
有什么问题吗?脚本运行吗?它会产生错误吗(如果是,错误是什么)?脚本是否做“错误”的事情(如果是的话,它做“错误”的原因是什么)?提供了什么作为
$category变量的值...categoryname、change_folder或其他? -
读取类别是用户输入的内容,我只是希望 ffmpeg 输出文件类似于用户提供的类别名称,但修改后附加了 _new 之类的内容
-
抱歉,仍然不明白您在问什么...您是否正在寻求帮助修改
full_dir变量以包含_new后缀,或者如何重定向所有@987654330 @ 输出到不同的目录? -
我想通了并发布了我的解决方案作为答案,我试图将 $dir 变量修改为 ffmpeg 将文件输出到的新路径
-
好的,所以你只想添加
_new后缀...很容易进行参数替换(假设字符串$category只在$full_dir中出现一次)
标签: bash shell file directory script