Skip to content

Replace all str in a dir

Linux:

1
sed -i “s/zhangsan/lisi/g” grep zhangsan -rl /modules

Mac:

1
grep -rl 'aaaModule' ./  | xargs sed -i "" "s/aaaModule/bbbName/g"

Rename files in dir

rename:

1
2
3
4
5
6
7
8
9
[alvin@VM_0_16_centos exp3]$ ls
atb_mod_01.cpp  atb_mod_02.cpp  atb_mod_03.cpp  atb_mod_04.cpp
[alvin@VM_0_16_centos exp3]$ rename mod adb *
[alvin@VM_0_16_centos exp3]$ ls
atb_adb_01.cpp  atb_adb_02.cpp  atb_adb_03.cpp  atb_adb_04.cpp

// perl
rename 's/(.*)$/new.$1/' original.filename
rename -n 's/\.DAT/\.dat/' * # not act

mv:

1
2
3
4
5
6
#!/bin/bash

for name in `ls *.txt`
do
    mv $name ${name%.txt}.cpp
done

Switch Jdk version

1
export JAVA_HOME="$(/usr/libexec/java_home -v 11)"