是否有一个脚本(bash)在每个文件和目录名称的开头添加一个“_”?
谢谢你的帮助。
关于什么:
for f in *
do
mv "$f" _"$f"
done
ls -1 | while read i; do mv "$i" "_$i"; done
如果目录是递归的,你需要一些更复杂的东西:
#!/bin/bash
#Requires BASH and a find with -print0
#The source
SRC=/tmp/writ
unset a i
#Read in the file names
while IFS= read -r -d '' file; do
# Get the file name, rip off the directory name
fname=$(basename "$file")
# Get the directory name, without the file name
dname=$(dirname "$file")
#I used 'cp' instead of 'mv' for testing reasons
# Note how I put the underscore in.
cp "$file" "${dname}/_${fname}"
# This just finds files. You can repeat the loop with
# type -d for directories.
done < <(find $SRC -type f -print0)