英文:
How do I delete the first delimiter of file names in linux?
问题
我想删除Linux中文件名的第一个分隔符。
例如,
$ ls my_directory
a.b.c.txt a.b.d.txt a.b.e.txt
我希望它变成:
$ ls my_directory
ab.c.txt ab.d.txt ab.e.txt
我尝试过:
$ mv a.b* ab*
,但不幸的是这不起作用。
我该怎么做?
谢谢提前。
英文:
I want to delete the first delimiter of file names in linux.
For example,
$ ls my_directory
a.b.c.txt a.b.d.txt a.b.e.txt
I want it to be like:
$ ls my_directory
ab.c.txt ab.d.txt ab.e.txt
I tried:
$ mv a.b* ab*
, but unfortunately this doesn't work.
What should I do?
Thank you in advance.
答案1
得分: 2
Use a replace once parameter expansion method if you're using Bash:
for f in a.b*; do
mv -i -- "$f" "${f/.}"
done
See Shell Parameter Expansion.
If you're using a POSIX shell, you can use ${f%%.*}${f#*.}
or in the case of a known prefix like a.b
, simply ab${f#a.b}
.
英文:
Use a replace once parameter expansion method if you're using Bash:
for f in a.b*; do
mv -i -- "$f" "${f/.}"
done
See Shell Parameter Expansion.
If you're using a POSIX shell, you can use ${f%%.*}${f#*.}
or in the case of a known prefix like a.b
, , simply ab${f#a.b}
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论