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.

learn more… | top users | synonyms

29
votes
10answers
10k views

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?
26
votes
4answers
2k views

Quick way to include a directory path when calling mv? [duplicate]

Often I will work out of the root of a rails directory where I find my self navigating the same path twice every time I would like to move a file: mv app/views/layouts/application.html.erb ...
6
votes
6answers
1k views

How to clean up file extensions?

I have a directories with .MP3 files which I'd like to change the extensions to .mp3. What's the easiest way to do this? I'm think something along the lines of: find /RootPath -type f -iname "*.mp3" ...
6
votes
2answers
3k views

How can I rename a lot of files using a regex?

I want to rename a lot of files on Mac OS X (10.7.2).. I don't have the perl package for the rename command. My files have names like "T452-102456-0.png" and I want to delete the "-0" part. I know I ...
4
votes
6answers
18k views

Changing extension to multiple files

I would like to change file extension from *.txt file to *.text file, tried using the basename command, but I am having trouble on changing more than 1 file, I am getting a basename: too many ...
3
votes
1answer
2k views

Rename All Files with a Certain Name

I'm trying to find certain files with the name "stringx" and replace the name (but not the extension) with "stringy". So basically for stringx.txt and stingx.cs, I'd want stringy.txt and stringy.cs. ...
5
votes
5answers
4k views

Recursive rename files and directories

I'm using below command for fname in *; do mv "$fname" $(echo "$fname" | sha1sum | cut -f1 -d' ') done ..but it only rename in current directory. Lets say I have many directories, and each ...
1
vote
2answers
9k views

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?
17
votes
3answers
6k views

bulk rename (or correctly display) files with special characters

I have a bunch of directories and subdirectories that contain files with special characters, like this file: robbie@phil:~$ ls test�sktest.txt test?sktest.txt Find reveals an escape sequence: ...
10
votes
3answers
9k views

How can I move files by type recursively from a directory and its sub-directories to another directory?

What would be a good way to move a file type from a directory and all of its sub-directories? Like "move all *.ogg in /thisdir recursively to /somedir". I tried a couple of things; my best effort was ...
17
votes
5answers
3k views

What does `mv ./*` without specifying destination do?

I accidentally forgot to specify destination before hitting the Return key. Where does mv ./* without specifying destination move the files and directories under current directory to?
10
votes
3answers
1k views

Lowercasing all directories under a directory

I want to lowercase every directories' name under a directory. With which commands can I do that?
6
votes
4answers
5k views

Renaming a bunch of files with date modified timestamp at the end of the filename?

So, say, I have a directory with a bunch of files like g.txt, where g.txt was last modified on, say, June 20, 2012. How would I batch-rename all of the files (like g.txt) with the last modified date ...
3
votes
3answers
1k views

how can I rename multiple files by inserting a character?

I have many files of the form sw001 sw002 sw003 ... I want to insert a period between the sw's and the number values. How can I accomplish this?
2
votes
3answers
9k views

Rename files by incrementing a number within the filename

I have a directory which contains numbered image files, something like this: 01.png 02.png 03.png 03.svg 04.png 05.png 06.jpg 07.png 08.png 09.png 09.svg 10.png Sometimes there may be multiple ...
5
votes
1answer
973 views

Renaming files to have lower case extensions with 'rename'

I'm trying to currently rename a large set of files and have been using quite kludgy methods to do so, such as: rename 's:(.*)\.MOV:$1.mov:g' *.MOV rename 's:(.*)\.JPG:$1.jpg:g' *.JPG What I'd ...
27
votes
5answers
3k views

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-------^ I think it takes too long time to repeat ...
27
votes
3answers
12k views

Why unix mv program doesn't need -R (recursive) option for directories but cp does need it?

This is a kind of "wtf?" question, so I'm sorry if I will disturb someone's vision of how things should be or if I will just annoy you with the "stupid" question. I always get messed up when need to ...
9
votes
1answer
3k views

Why can't I have a folder and a file with the same name?

I've never had this problem before, but for some reason, I can't rename my folder to packages/. This is the structure: root - packages_old/ - packages When I try to rename the folder with ...
6
votes
3answers
359 views

“mkdir foo; svn mv * foo”

I often want to do some variant of this idiom: $ mkdir 2010 $ svn mv * 2010 Of course, I get an error because the glob matches 2010 as well: svn: Cannot copy path '2010' into its own child ...
3
votes
2answers
6k views

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?
3
votes
6answers
4k views

Renaming multiple files based on their contents

How can I rename all files within a folder with the first word of their content? For example if a.txt contains “Unix is an OS” in its first line then a.txt should be renamed to Unix.txt
3
votes
5answers
4k views

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
3
votes
2answers
677 views

How to copy multiple files but keep their extensions the same?

I am looping through a number of files, and $file represents the current file. How can I make copies or renames and keep the extension the same for this current file? e.g. if $file = x.jpg How to ...
3
votes
1answer
955 views

Can't rename a directory that I own

I have a directory with a big load of sub directories. I own all of them, and the permissions are all 777. pascal@azazel /box $ ls -al total 147872 drwxr-xr-x 293 root root 12288 aoû 22 19:44 ...
1
vote
4answers
566 views

renaming multiple files increment order

I have the following files SSt12.precip.374.sub.climatology.ctl SSt12.precip.2874.sub.climatology.ctl SSt12.precip.3764.sub.climatology.ctl SSt12.precip.6774.sub.climatology.ctl I want to rename ...
1
vote
1answer
348 views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
1
vote
4answers
494 views

Recursively rename e-mail files from .txt to .eml

Directory "$d" contains a few thousand e-mail files with the .txt extension. To open them in my e-mail client, I need to rename them to .eml Will this command rename them correctly: find "${d}" ...
12
votes
3answers
3k views

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 ...
9
votes
7answers
6k views

How do you bulk move files up one directory safely?

How can I move files up a directory where there might be hundreds or thousands of files in the directory, and you might not be sure about whether there are dupes in ... What method would you use? How ...
7
votes
3answers
13k views

How can you move (or copy) all files of a certain type to a directory in Unix?

I'm not very familiar with all the tricks of grep/find/awk/xargs quite yet. I have some files matching a particular pattern, say *.xxx. These files are in random places throughout a certain ...
3
votes
3answers
484 views

Rename multiple directories decrementing sequence number?

I have a directory which contains a number of subdirectories with names on the format dir.##. The prefix is always the same, and the suffix is 1-3 digits in a strictly incrementing sequence. Thus, ...
9
votes
3answers
6k views

How can I rename photos, given the EXIF data?

Let's say I have a bunch of photos, all with correct EXIF information, and the photos are randomly named (because of a problem I had). I have a little program called jhead which gives me the below ...
5
votes
4answers
307 views

How to rename to fixed length

I have files named as 0-n.jpg for n from 1 to 500, for example. The problem is that some guy using Windows didn't use leading zeros so when I do ls I obtain 0-100.jpg 0-101.jpg ... 0-10.jpg ... ...
3
votes
7answers
529 views

Batch renaming of files [duplicate]

I have a directory full of images: DSCN4749.JPG DSCN4750.JPG DSCN4892.JPG ... And I would like a one-liner to rename them to (say). dscn4749.jpg dscn4750.jpg dscn4892.jpg ... How do I do this? ...
8
votes
2answers
841 views

the slash (/) after a directory name on shell commands

I have a little question here. If I have two files, say filea and fileb, mv filea fileb would delete fileb rename filea to fileb Then if I have two directories, say dira and dirb, mv dira dirb ...
7
votes
4answers
777 views

mv * folder (avoiding 'cannot move' error) [duplicate]

Anytime I want to move thousands of files to a new folder, I always encounter the same problem. > mkdir my_folder > mv * my_folder mv: cannot move 'my_folder to a subdirectory of itself ...
4
votes
5answers
2k views

Padding a number in a filename to a fixed length

I have a directory of files such as: file.1.png file.2.png … file.10.png … file.1000.png file.1001.png … How can I pad the number to 4 digits? It should end up like this: file.0001.png ...
4
votes
1answer
1k views

How to pipe the result of 'date' command to 'mv' command

I want to rename my file to the current timestamp.I know how to get the current timestamp("date +%s") but how can I pipe it to 'mv' command?
2
votes
3answers
6k views

Batch renaming files with pattern

I have some files named like these: 63018933.mp4?token=1325697436_b0c3e70c6e339380b4a484c576a8c287 63808488.mp4?token=1325697401_4ae5f7a68d93873c8881b303e7655e14 How do I rename all them to, for ...
6
votes
2answers
721 views

renaming images to include creation date in name

When I look at the properties of an image, I can see the date the photo was taken in "Date Taken". When I edit the images (proprietary program) this data gets lost. How can I rename the image files ...
5
votes
5answers
3k views

Replace dots with underscores in filenames, leaving extension intact

I have a bash script which I'm trying to get to replace dots in filenames and replace them with underscores, leaving the extension intact (I'm on Centos 6 btw). As you can see from the output below, ...
5
votes
1answer
3k views

mv file without write permission to the source file

I just realised that I can move a file that I do not own and don't have write permissions on. I have write permissions to the directory, so I am guessing that is why I could move it, but in this ...
4
votes
4answers
101 views

Renaming multiple files with rename

I need help renaming files in batch--the other questions I browsed don't exactly address my problem. The names of my files are generated non-deterministically, so I can't predict what they will be ...
3
votes
2answers
116 views

zmv command to rename file after matching pattern

I was trying to figure out a solution for this question using zmv. I am unable to find an exact solution using zmv. This is what I could come up with so far. From here, I could rename all files like ...
2
votes
5answers
429 views

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.
2
votes
1answer
1k views

Move a remote file at an FTP prompt

I don't think it's possible but still I would like to ask if there is any command to transfer a remote file from one directory to other at an FTP prompt. In more detail: I run ftp to a remote ...
2
votes
1answer
273 views

Unable to preserve ownership in a copy but able with a move?

I have noticed that I am unable to preserve ownership if I rsync -o files. However, I am when I move them. This is all without admin privileges. What is the rationale of this? Several threads e.g. ...
1
vote
2answers
127 views

Rename a file dynamically containing spaces [duplicate]

I want to rename a file dynamically based on data which contains spaces Name="Abc DEF" Name1="GHI JKL" mv /sample/pdf/noriginalName.pdf /sample/outputPdf/${NAME}${Name1}".pdf" But it gives me an ...
1
vote
2answers
3k views

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