New answers tagged

0

Use sed for file in */*.ext; do ext2=`echo $file | sed 's/.ext/.ext2/'` mv $file $ext2 done


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


0

You can rename file with time stamp appended to it mv TheFile.log TheFile.log.`date +"%d-%m-%Y`


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

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

This should take care of it for file in $(find ./) do newname=$(echo ${file} | sed -e 's/\.\(.*\)\././') mv ${file} ${newname} done


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


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


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


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

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


3

You need to iterate over your map file, reading the directory and name pattern into two variables, and using them in the mv command: sed 's/"//g' map.txt | while IFS="=" read dir name; do for file in "$dir"/*; do mv "$file" "${file/sample/$name}" done done Explanation sed 's/"//g' map.txt : remove the quotes ...



Top 50 recent answers are included