我在尝试创建脚本以将目录中的所有文件重命名为.txt
Linux 上时遇到问题。
这是我到目前为止所拥有的。
#!/bin/bash
location_number=$(find /hw1/textarchive | wc -l)
org_path=/hw1/textarchive/!(*txt)
count=0
#for count in $location_number
#do
# rename $org_path .txt
#rename $org_path *.txt
# mv $org_path $org_path.txt
#done
for count in $location_path
do
rename $org_path .pro .txt *.pro <-----was trying to just rename .pro to .txt (no luck)
done
echo done
Run Code Online (Sandbox Code Playgroud)
我尝试使用mv
andrename
但没有任何结果。当mv $org_path $org_path.txt
我运行时,我会收到类似于 的错误(this file) is not a directory
。有了rename
它,运行时不会出现任何错误,但它不会将任何文件重命名为.txt
.
我有几个这样命名的文件: This is a test - AB12-1998.avi
(最后一个代码总是 2 个字母、2 个数字、破折号、4 位数字)
我想做的是像这样重命名它们: AB12-1998 - This is a test.avi
我很感激您可以使用 bash、重命名或任何其他方式为我提供的任何解决方案,只要它能完成工作。
例如,我有一个名为5.jpg
. 如何将其重命名为aaaaa.jpg
char a
5 次。
我试过了,rename -v 's/(\d{1,})/a{$1}/g' *
但这重命名5.jpg
为a{5}.jpg
,这不是我想要的。我知道函数的第二部分不是正则表达式,这只是一个尝试。
rename.ul
你能建议一下在Ubuntu 22.04下如何使用吗?非常感谢 !
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.10.102.1-microsoft-standard-WSL2 x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
/etc/update-motd.d/50-landscape-sysinfo: 17: cannot create /var/lib/landscape/landscape-sysinfo.cache: Permission denied
System information as of Thu Aug 11 14:43:22 CST 2022
System load: 0.0 Processes: 15
Usage of /: 15.8% of 250.98GB Users logged in: 0
Memory usage: 0% IPv4 address for eth0: 172.25.114.46
Swap usage: 0%
0 updates can be applied immediately.
This message is shown once a day. To disable it …
Run Code Online (Sandbox Code Playgroud)