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.

1187 questions
420
votes
18 answers

How do I change the extension of multiple files?

I would like to change a file extension from *.txt to *.text. I tried using the basename command, but I'm having trouble changing more than one file. Here's my code: files=`ls -1 *.txt` for x in $files do mv $x "`basename $files…
afbr1201
  • 4,529
  • 5
  • 22
  • 18
246
votes
16 answers

Merging folders with mv?

If I use mv to move a folder called "folder" to a directory that already contains "folder" will they merge or will it be replaced?
Dominique
  • 5,155
  • 8
  • 26
  • 29
215
votes
9 answers

Move folder content up one level

I have a directory that is unpacked, but is in a folder. How can I move the contents up one level? I am accessing CentOS via SSH.
whatshakin
198
votes
14 answers

Batch renaming files

I have a directory full of images: image0001.png image0002.png image0003.png ... And I would like a one-liner to rename them to (say). 0001.png 0002.png 0003.png ... How do I do this?
Internet man
  • 3,551
  • 3
  • 17
  • 9
198
votes
5 answers

How to choose directory name during untarring

Say I have file named ugly_name.tar, which when extracted, becomes ugly_name directory. What command can I use such that the resulting directory name is pretty_name instead?
tshepang
  • 64,472
  • 86
  • 223
  • 290
171
votes
7 answers

How to move all files and folders via mv command

How can I move all files and folders from one directory to another via mv command?
Luka
  • 2,067
  • 3
  • 10
  • 14
124
votes
11 answers

how to rename multiple files by replacing string in file name? this string contains a "#"

https://serverfault.com/questions/70939/how-to-replace-a-text-string-in-multiple-files-in-linux https://serverfault.com/questions/228733/how-to-rename-multiple-files-by-replacing-word-in-file-name https://serverfault.com/questions/212153/replace-stri…
Leon Francis Shelhamer
117
votes
7 answers

Flattening a nested directory

This is probably very simple, but I can't figure it out. I have a directory structure like this (dir2 is inside dir1): /dir1 /dir2 | --- file1 | --- file2 What is the best way to 'flatten' this directory structure…
turtle
  • 2,607
  • 5
  • 19
  • 16
77
votes
9 answers

Bulk rename, change prefix

How can I bulk replace the prefix for many files? I have a lot of files like TestSRConnectionContext.h TestSRConnectionContext.m I would like to change all them to CLConnectionContext.h CLConnectionContext.m How would I do this?
ErikTJ
  • 893
  • 1
  • 7
  • 6
71
votes
5 answers

Appending a current date from a variable to a filename

I'm trying to append the current date to the end of a file name like this: TheFile.log.2012-02-11 Here is what I have so far: set today = 'date +%Y' mkdir -p The_Logs & find . -name The_Logs -atime -1 -type d -exec mv \{} "The_Logs_+$today" \;…
I AM L
  • 873
  • 1
  • 10
  • 10
69
votes
8 answers

How to replace one char with another in all filenames of the current directories?

How do you rename all files/subdirs in the current folder? Lets say, I have many files and subdirs that are with spaces and I want to replace all the spaces with an underscore. File 1 File 2 File 3 Dir 1 Dir 3 should be renamed…
NobbZ
  • 807
  • 1
  • 8
  • 8
66
votes
3 answers

How to rename multiple files in single command or script in Unix?

I have the below list of files aro_tty-mIF-45875564pmo_opt aro_tty-mIF-45875664pmo_opt aro_tty-mIF-45875964pmo_opt aro_tty-mIF-45875514pmo_opt aro_tty-mIF-45875524pmo_opt that I need to rename…
Udhayakumar
  • 842
  • 1
  • 8
  • 8
60
votes
5 answers

How can I find files and then use xargs to move them?

I want to find some files and then move them. I can find the file with: $ find /tmp/ -ctime -1 -name x* I tried to move them to my ~/play directory with: $ find /tmp/ -ctime -1 -name x* | xargs mv ~/play/ but that didn't work. Obviously mv needs…
Michael Durrant
  • 41,213
  • 69
  • 165
  • 232
60
votes
6 answers

Quickest way to rename files, without retyping directory path

I know how to rename files in Unix: $ mv ~/folder/subfolder/file.txt ~/folder/subfolder/file.sh ^-------this part------^ ^------this part-------^ It takes too long time to repeat ~/folder/subfolder/file twice. Is there a quicker way?
Hamed Kamrava
  • 6,678
  • 12
  • 35
  • 47
45
votes
6 answers

Rename multiple files with mv to change the extension

I want to rename files to change their extension, effectively looking to accomplish mv *.txt *.tsv But when doing this I get : *.tsv is not a directory I find it somewhat strange that the first 10 google hits show mv should work like this.
Sander Van der Zeeuw
  • 1,501
  • 2
  • 13
  • 15
1
2 3
79 80