Rename duplicate files created by GDrive

find . -name "*\(2\)*" -exec rename -s \ \(2\) '' -n {} +
Changes files like "temp (2).txt" to "temp.txt". Does not overwrite files that already exist.

By: buddacow
2017-06-30 04:33:50

These Might Interest You

  • This renames a pattern matched bunch of files by their last modified time. rename by timestamp rename by time created rename by time modified Show Sample Output

    for i in somefiles*.png ; do echo "$i" ; N=$(stat -c %Y $i); mv -i $i $N.png; done
    sufoo · 2010-06-01 19:28:05 0
  • The command renames all files in a certain directory. Renaming them to their date of creation using EXIF. If you're working with JPG that contains EXIF data (ie. from digital camera), then you can use following to get the creation date instead of stat. * Since not every file has exif data, we want to check that dst is valid before doing the rest of commands. * The output from exif has a space, which is a PITA for filenames. Use sed to replace with '-'. * Note that I use 'echo' before the mv to test out my scripts. When you're confident that it's doing the right thing, then you can remove the 'echo'... you don't want to end up like the guy that got all the files blown away. Credits: Show Sample Output

    for i in *.jpg; do dst=$(exif -t 0x9003 -m $i ) && dst_esc=$(echo $dst | sed 's/ /-/g' ) && echo mv $i $dst_esc.jpg ; done
    klisanor · 2012-05-02 07:23:38 1
  • rename command in my system -Fuduntu running 2.6.38 Linux Kernel- is an ELF 64-bit LSB executable, not a Perl script. man page for rename command shows syntax as "rename from to where" (or something like that), so I am doing just what I have been told... Show Sample Output

    rename foo bar directory/filename
    hexram · 2011-05-04 22:29:11 0
  • # Limited and very hacky wildcard rename # works for rename *.ext *.other # and for rename file.* other.* # but fails for rename file*ext other*other and many more # Might be good to merge this technique with mmv command... mv-helper() { argv="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //'`" files="`echo \"$argv\"|sed -e \"s/ .*//\"`" str="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //' | tr -d \*`" set -- $str for file in $files do echo mv $file `echo $file|sed -e "s/$1/$2/"` mv $file `echo $file|sed -e "s/$1/$2/"` done } alias rename='mv-helper #'

    rename *.JPG *.jpg
    gtoal · 2014-03-05 14:54:33 0

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: