在复制mp3的歌词文件的时候,多复制了许多,用手动删除那些多余的文件很麻烦,也很慢,就写了一个脚本
#!/bin/bash
ls -l *.lrc | cut -b 46- | awk -F '.lrc' '{print $1}' > file0
ls -l *.mp3 | cut -b 51- > file1
ls -l *.wma | cut -b 49- > file2
while read -r line
do
name1=$line".mp3"
name2=$line".wma"
while read -r line1
do
if [ "$name1" = "$line1" ]
then
echo $name1
else
if [ -f "$name1" ] ; then
rm $name1
echo "$name1 rm"
fi
fi
done < file1
while read -r line2
do
if [ "$name2" = "$line2" ]
then
echo $name2
else
if [ -f "$name2" ] ; then
rm $name2
echo "$name2 rm"
fi
fi
done < file2
done < file0
rm file0
rm file1
rm file2
|
具体的实现可能还有一些小问题,没有考虑周全。
阅读(1501) | 评论(0) | 转发(0) |