How to Batch Rename Filesname

How to batch rename filesname

Rename a file

1
ls *.mp4| awk -F "TEXT_TO_DELETE" '{print "mv \""$0"\" \""$1$2"\""}'  | bash

Rename a folder

1
ls -d * | awk -F "TEXT_TO_DELETE"  '{print "mv \""$0"\" \""$1$2"\""}' | bash

Batch rename file

  • bash file
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/bash
for dir in `ls . | tr " " "?" `
do 
  new_dir=(`echo $dir  | tr "?" " "`)
  if [ -d  """$new_dir""" ]
  then
    echo $new_dir
    cd """$new_dir""" 
    ls | awk -F "【瑞客论坛 www.ruike1.com】" '{print "mv \""$0"\" \""$1""$2"\""}' |bash  
    cd .. 
  fi
done
  • one command line script
1
for dir in `ls . | tr " " "?" `;do new_dir=(`echo $dir  | tr "?" " "`)&& (if [ -d  """$new_dir""" ];then;echo $new_dir&&cd """$new_dir""" &&ls | awk -F "【瑞客论坛 www.ruike1.com】" '{print "mv \""$0"\" \""$1""$2"\""}' |bash  && cd .. ;fi);done
Licensed under CC BY-NC-SA 4.0
Last updated on Nov 08, 2024 12:49 UTC
Built with Hugo
Theme Stack designed by Jimmy