Hot answers tagged

4

History. There are two historical lines of a rename command, with the same basic purpose but completely different syntax and capabilities: The rename command in the util-linux package. It appeared in version 2.10e and the program is dated 2000-01-01. A perl script, which was distributed with Perl as an example program. The Debian changelog records it being ...


2

AFAIK, in this context the {} aren't really "shell curly braces" (in the sense of brace expansion for example), they're just textual placeholders for arguments. As such you could pass them into a shell command and use the shell's parameter substitution facility to modify the names, like sh -c 'for f; do somecommand "$f" "${f%.*}.al"; done' sh {} To ...


1

In zsh, use zmv. Run autoload -U zmv or put that in your ``/.zshrc`, then zmv '(*).*(.*)' '$1$2' or zmv -w '*.*.*' '$1.$3' Alternatively, if you have the prename command (Perl script that applies an expression to each file name): prename 's/\..*\././' *.*.* With only tools that are available on every POSIX system, use a shell loop, and parameter ...


1

Using the perl rename utility: prename 's/\.[^.]*\././' * prename allows you to rename files using perl expressions. On some systems, the same program is called rename rather than (or as well as) prename. There are other programs called rename which work very differently - check the rename man page on your system to be sure. e.g. by default, rename on ...


1

You can use the -printf function of find to construct your commands: find /tmp -name "*.ext" -printf "mv %p %h/new_name.ext" mv /tmp/foo.ext /tmp/new_name.ext When you surround the command with $(), the commands will be executed: $(find /tmp -name "*.ext" -printf "mv %p %h/new_name.ext") find /tmp -name "*.ext" /tmp/new_name.ext Update: The above ...


1

1 For your first step, in your command example, you do not need the * because that is not filtering any file. What you do need is to filter .git, as this: $ find . ! -name ".git" -type f That will reject (!) any file named .git. That removes the need of grep -v ".git". The sed could not be avoided, as it is editing the internals of a file, not something ...


1

This thread is out there for years and still ranks #1 on google so i wanted to add another method. How i usually do this: packing the subdir content into a tarball, moving the tarball up to the parent directory and then extract it with the default --overwrite behaviour. This does exactly what you're looking for. Afterwards you can remove your subdir. cd xyz ...


1

if [ -f XXX_001_014_max.jpg ] then SOURCE=XXX_001_014_max.jpg else SOURCE=XXX_001_024_max.jpg fi mv $SOURCE image.jpg


1

if [ -f XXX_001_014_max.jpg ] then mv XXX_001_014_max.jpg image.jpg else mv XXX_001_024_max.jpg image.jpg fi


1

Avoid the for i in $(cat squeeze) construct - it will fail if any of your directory names contains IFS characters... I would read the lines into an array and then simply rename the first file in each directory. Since you always have one or two files in each directory, that means renaming the first one in each directory should do the job - e.g. with bash: ...



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