I have a few directories and sub-directories containing files with no file extension. I want to add .jpg
to all the files contained within these directories. I've seen bash scripts for changing the file extension but not for just adding one. It also needs to be recursive, can someone help please?
相关问题
- How to get the return code of a shell script in lu
- What is the best way to do a search in a large fil
- JQ: Select when attribute value exists in a bash a
- Spring Integration - Inbound file endpoint. How to
- Invoking Mirth Connect CLI with Powershell script
相关文章
- 使用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?
- What is the correct way to declare and use a FILE
- Making new files automatically executable?
- Reverse four length of letters with sed in unix
rename
not sure that it can rename files without extensions (I'm on windows 7 right now)
Alternative command without an explicit loop (
man find
):Explanation: this recursively finds all files (
-type f
) starting from the current directory (.
) and applies the move command (mv
) to each of them. Note also the quotes around{}
, so that filenames with spaces (and even newlines...) are properly handled.For renaming all files with no extension in Windows basic you can do
ren * *.jpg
Since the file as no extension, just use the *, or if you want to change png to jpg useren *.png *.jpg
like this,
I am not expecting you have space separated file names,
If you do, the names will need to be processed a bit.
If you want to execute the command from some other directory,
you can replace the
find .
withfind /target/directory
.this will find files without extension and add your .jpg
This is a little late, but I thought I would add that a better solution (although maybe less readable) than the ones so far might be:
Using the
find | xargs
pattern generally results in more efficient execution, as you don't have to fork a new process for each file.Note that this requires the version of rename found in Debian-flavored distros (aka prename), rather than the traditional rename. It's just a tiny perl script, though, so it would be easy enough to use the command above on any system.