Tag Info

Hot answers tagged

6

[ and ] have a special meaning in bash and also in regular expressions, so you have to escape them as \[ and \]. Something like this should work: rename 's/\[800p\]-\[WOLU-H\]/\[WOLU-H\]/' \[800p\]-* Example: $ touch [800p]-[WOLU-H]-test1.mkv [800p]-[WOLU-H]-test2.mkv $ ls [800p]-[WOLU-H]-test1.mkv [800p]-[WOLU-H]-test2.mkv $ rename ...


2

Here is something using find to rename *.png.png -> *.png: find ./ -name '*.png.png' -type f \ -exec sh -c 'mv {} ./$(basename -s .png.png {}).png' \; It isn't really gerenic, so you have to customize it for the other file extensions.


2

Although mikesrv solution is much better and safer I think this can be done also with rename: find Music/ -type f -name '*_000' -print0 | xargs -r0 rename -v '_000' '' But there are still potential problems as mentioned, for example album_00020_000 will be renamed to album20 which obviously is not the desired behaviour. I think on debian distribution was ...


2

cd Music/.. && mkdir Music2 && pax -'rwls|\([^/]\)_000$|\1|p' Music Music2 If run from Music's parent directory, the above commands will create a directory called Music2 then mirror Music's path structure in Music2 w/ hardlinks while removing any occurrence of _000 found at the tail of any filename therein. Afterward you'll have ...


1

Use the find command to enumerate files in a directory and its subdirectories recursively. There are several ways to rename files. You can use the Linux rename command: find Music -depth -name '*_000' -exec rename _000 '' {} \; This removes the first occurrence of _000 in each file name. Beware that if you had files whose name contains _000 in the middle, ...


1

Here is a shell-only solution for the three cases you have in your question: for f in *.png.png ; do mv -i "${f}" "${f%.png}" ; done for f in *.jpeg.jpg ; do mv -i "${f}" "${f%.jpeg.jpg}.jpg" ; done for f in *.JPEG ; do mv -i "${f}" "${f%.JPEG}.jpg" ; done Type it in the directory where the files are to be renamed. If you like to generalize this type ...


1

On Linux, you can use cp --backup=numbered to obtain files called foofile.log, foofile.log.~1~, foofile.log.~2~, etc. find /location -name '*file.log' -exec cp --backup=numbered {} /location \; If you want to include the original directory as part of the target file name, you can replace the slashes by some other string. However, there are a couple of ...



Only top voted, non community-wiki answers of a minimum length are eligible