发布网友 发布时间:2022-04-23 09:13
共2个回答
热心网友 时间:2022-06-26 05:00
简单的写了一次, 思路如下,
脚本需要放在 test文件夹下
主要是用变量赋值分割文件名, 按照-的前后来分割
#################################
#!/bin/bash
mkdir 'ralph'
mkdir 'bessie'
for name in *.bb
do
newName=${name#*-}
q=${name%-*}
newName=${newName%.bb} #加上这句话就把.bb 删了
if [ $q = "ralph" ]; then
mv $name "ralph/$newName"
else
mv $name "bessie/$newName"
fi
done
热心网友 时间:2022-06-26 05:01
#! /bin/bash
# need bash 3.1 0r above
path=TEST
newpath_1=/home/test/ralph
newpath_2=/home/test/bessie
if [ ! -d "$newpath_1 ] && [ ! -d "$newpath_2" ]
then
mkdir "$newpath_1" "$newpath_2"
fi
cd "$path" && echo "We are in $(pwd)"
for i in *
do
if [[ $i =~ (ralph-)([a-z]+.*) ]]
then
name=${BASH_REMATCH[2]}
mv "$i" "$name" ; ret=$?
if (( $ret == 0 )) ; then
mv "$name" "$newpath_1"
fi
else
mv "$i" "$newpath_2"
fi
done
exit 0