Bash 将u添加到文件夹中的每个文件/目录

Bash 将u添加到文件夹中的每个文件/目录,bash,Bash,是否有一个脚本(bash)在每个文件和目录名的开头添加一个“\ux” 谢谢你的帮助。关于: for f in * do mv "$f" _"$f" 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;

是否有一个脚本(bash)在每个文件和目录名的开头添加一个“\ux”

谢谢你的帮助。

关于:

for f in *
do
  mv "$f" _"$f"
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)
#/bin/bash
#需要BASH和带有-print0的find
#源头
SRC=/tmp/write
取消一个i
#读入文件名
而IFS=read-r-d“”文件;做
#获取文件名,删除目录名
fname=$(basename“$file”)
#获取目录名,但不获取文件名
dname=$(目录名“$文件”)
#出于测试原因,我使用了“cp”而不是“mv”
#注意我是如何把下划线放进去的。
cp“$file”“${dname}/{fname}”
#这只是查找文件。你可以重复这个循环
#为目录键入-d。
完成<
#!/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)