删除Linux中文件名的第一个分隔符如何操作?

huangapple go评论63阅读模式
英文:

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}.

huangapple
  • 本文由 发表于 2023年2月6日 13:53:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75357761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定