I have multiple files in a directory, example: linux_file1.mp4
, linux_file2.mp4
and so on. How do I move these files, using shell, so that the names are file1.mp4
, file2.mp4
and so on. I have about 30 files that I want to move to the new name.
相关问题
- How to get the return code of a shell script in lu
- JQ: Select when attribute value exists in a bash a
- Invoking Mirth Connect CLI with Powershell script
- Emacs shell: save commit message
- bash print whole line after splitting line with if
相关文章
- 使用2台跳板机的情况下如何使用scp传文件
- In IntelliJ IDEA, how can I create a key binding t
- Check if directory exists on remote machine with s
- shell中反引号 `` 赋值变量问题
- How get the time in milliseconds in FreeBSD?
- Reverse four length of letters with sed in unix
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
A simple native way to do it, with directory traversal:
Will rename every file in place adding extension .txt at the end.
And a more general cool way with parallelization:
I was able to achieve replace filenames within directories by combining @dtrckd and @Sorpigal answers.
I like mmv for this kind of thing
But you can also use
rename
. Be aware that there are commonly tworename
commands with very different syntax. One is written in Perl, the other is distributed with util-linux, so I distinguish them as "perl rename" and "util rename" below.With Perl rename:
As cweiske correctly pointed out.
With util rename:
How can you tell which rename you have? Try running
rename -V
; if your version is util rename it will print the version number and if it is perl rename it will harmlessly report and unknown option and show usage.If you don't have either
rename
ormmv
and don't want to or can't install them you can still accomplish this with plain old shell code:This syntax will work with any POSIX sh conforming to XPG4 or later, which is essentially all shells these days.