Questions tagged [rename]

The rename tag refers to the action of giving a different name to either an existing file or to a copy of a file as part of some other operations (.e.g. remote copy, backup). Use this tag as well for questions related to the (perl) rename command.

Renaming is the action of giving a different name to an object (e.g. file, link or directory). It can also refer to the act of giving a new name to a copy of an object, while performing another operation such as uploading or remote copy.

The command renaming is mv, but this is very basic and doesn't support functionality like renaming the extensions of a bunch of files¹. To rename objects using some pattern, either requires the shell to do pattern matching and replacement and then invoking mv, or use of some other command like rename (implemented in Perl).

¹ DOS command prompt users are used to be able to do ren *.txt *.doc, something not built into mv.

1209 questions
34
votes
6 answers

how can I rename multiple files by removing a character or string?

As a follow-up to my previous question, if I have multiple files of the form sw.ras.001 sw.ras.002 sw.ras.003 … What command can I use to remove the ras. in the middle of all the files?
Paul
  • 9,423
27
votes
7 answers

How to rename multiple files by removing the extension?

I have a number of tiff files named: sw.001.tif sw.002.tif ... and I want to remove the .tif at the end of each of the files. How can I use the rename command to do this?
Paul
  • 9,423
26
votes
3 answers

How to decide that mv moves into a directory rather than replacing directory?

Say I have a directory /hello. Then I do mv /hello /hello2. Am I moving /hello into /hello2/hello? Or am I moving /hello to /hello2? It seems that when I do something like this, I get inconsistent results.
user4951
  • 10,519
13
votes
5 answers

Rename files to add leading zeros to numbers

I've tried a bunch of examples of the rename command but I can't figure out the syntax to do what I want. I have a bunch of files labeled something like File_Ex_1.jpg File_Ex_2.jpg File_Ex_3.jpg File_Ex_4.jpg ... File_Ex_10.jpg File_Ex_11.jpg etc.…
toombzie
  • 131
12
votes
6 answers

Rename files in directory

How to rename files in a directory such as the following file: PMC21375.pdf.txt, I need to be renamed to 21375.txt. i.e, I need to remove both PMC and pdf from each file name.
11
votes
3 answers

rename a list of files according to a text file

I have a list of files in a folder, which I will like to rename according to a textfile. For example: These are the 5 files in the folder. 101_T1.nii 107_T1.nii 109_T1.nii 118_T1.nii 120_T1.nii I will like to have them rename using a text file…
8
votes
4 answers

Change part of the filename on multiple files in a directory:

I once had a script that would do the following. It would rename part of a filename of multiple files in the current directory: For example: rename variable1 variable2 rename 456…
ivan
  • 411
7
votes
2 answers

Simplifying complicated music file names

I have a large directory of music files whose titles follow the below format: Title_stringOfNumbers - Artist.mp3 My goal is to remove the underscores followed by numbers and switch the artist's name with the title. For example, the original…
BeanieBarrow
  • 175
  • 5
7
votes
5 answers

Rename all the files within a folder with prefix “Unix_”

Rename all the files within a folder with prefix “Unix_” i.e. suppose a folder has two files a.txt and b.pdf than they both should be renamed from a single command to Unix_a.txt and Unix_b.pdf
6
votes
2 answers

renaming all files in all sub directories

How to rename all files in all sub directories, with the sub directories name and auto number. ex: parent -subdir --file.jpg --cat.jpg --dog.jpg rename to : parent -subdir --subdir_01.jpg --subdir_02.jpg --subdir_03.jpg I'm using this script but…
juicebyah
  • 379
  • 6
  • 14
6
votes
5 answers

rename files in batch

During importing my music files from backup (thanks to default naming scheme of rhythmbox), I have messed up the file names. Now the looks like: 00 - American Pie.ogg.ogg.ogg.ogg 00 - American Pie.ogg.ogg.ogg.ogg.ogg 00 - another brick in the…
BaRud
  • 1,639
  • 2
  • 17
  • 26
5
votes
2 answers

mv failed halfway through - is source directory intact

I ran mv a-folder /home/me on a machine and half way through the move the destination device filled up. a-folder was made up of folders and files in various subdirectories. Does mv leave the source folder intact until the move has successfully…
Rich
  • 4,529
5
votes
4 answers

Bulk renaming files from TitleCase -> Title Case (space separation)

I have a 38GB folder with 800 MP4 videos in it. After re-downloading it, the file name has no spacing, and all words are joined, but it's still TitleCase. So from TitleCase I need Title Case. What would be the most effective way of bulk renaming…
5
votes
3 answers

Bash Script to Rename Files Based on Size

I have a bash script that renames files in a folder according to input from a command prompt: echo "Please rename and press enter" read rename if [ -z "$rename" ]; then printf "no caption was selected, aborting!\n" exit 1 fi printf "rename…
whitewings
  • 2,457
5
votes
3 answers

Remove characters from file names recursively

I have hundreds of directories, some nested in other directories, with tens of thousands of files. The files need to have a date/time stamp removed from them. An example filename is Letter to Client 27May2016~20160531-162719.pdf and I would like…
1
2 3 4 5 6 7