使用Bash脚本创建新目录



我想创建一个每小时运行一次的脚本(使用crontab(,用任何具有正确扩展名(减去扩展名(的文件的名称创建一个文件夹,并将该文件移动到其中。因此,最终结果是执行脚本,在/Directory中查找每个.mp4文件,并将文件移动到匹配的文件夹中。我可以理解不想免费为某人写东西,但如果你能给我指明正确的方向,我会非常感激

编辑:感谢@Barmar的帮助!

#!/bin/bash
cd "/home/kali/Videos"
for FILE in *;do
bn=$(basename $FILE .mp4)
mkdir /home/kali/Videos/$bn;done
mv $bn.mp4 /home/kali/Videos/$bn

您要查找的脚本如下:

#!/bin/bash
REPOSITORY="/home/kali/Videos"
cd "${REPOSITORY}"
### This approach is best for handling filenames that might have spaces or scpecial characters.
ls |
while [ true ]
do
read FILE
if [ -z "${FILE}" ] ; then break ; fi
if [ -f "${FILE}" ]
then
bn=`basename "${FILE}" ".mp4" `
mkdir "${REPOSITORY}/$bn"
mv "${FILE}" "${REPOSITORY}/$bn"
( cd "${REPOSITORY}/$bn" ; extract_images "./${FILE}" )
fi
done

最新更新