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

35
votes
6answers
64k views

How to overwrite target files with mv?

I have a ton of files and dirs in a subdirectory I want to move to the parent directory. There are already some files and dirs in the target directory which need to be overwritten. Files that are only ...
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?
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 ...
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 ...
21
votes
3answers
3k views

How to rename file to .. (dot dot)?

Apparently you can rename file to .... If I were insane, how would I rename file to .. or .? Is such a filename even allowed? Backslash doesn't seem to disable dot's special meaning: $ mv test \. ...
20
votes
3answers
7k views

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?
20
votes
1answer
606 views

How to move a directory, file by file? (instead of “copy then remove”)

My computer has one 500GB drive. I want to move 400GB of data from /unencrypted to /encrypted. Both directories are on the same partition, but /encrypted is handled by ecryptfs, so mv /uncrypted/* ...
19
votes
6answers
16k views

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 ...
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?
17
votes
2answers
1k views

What does mv do in case of errors?

I've just tried to move a big tree from one disk to another, which was too small. Now, I'm left with something I can't really understand - it looks like some files were indeed moved away from the ...
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: ...
14
votes
3answers
754 views

Move files and change ownership at the sametime

On Linux (Debian, Ubuntu Mint...), Is there any option command or something that I can use to transfer files to another user without having to do : sudo mv /home/poney/folderfulloffiles ...
14
votes
2answers
3k views

How do open files behave on linux systems?

I just renamed a log file to "foo.log.old", and assumed that the application will start writing a new logfile at "foo.log". I was surprised to discover that it tracked the logfile to its new name, and ...
13
votes
5answers
910 views

How to remove the (1) from filenames using the find command

I recently converted all of my FLAC files to a lower sampling rate of 44.1 kHz and bit depth of 24 bits (because iPhone/iPod don't support anything above that) using XLD on my Mac OS 10.7 (Lion). ...
13
votes
5answers
23k views

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.
12
votes
6answers
996 views

Subtract 1 from all file names (rename them) in a directory.

I have a directory which contains image files with names like image1.jpg image2.jpg image3.jpg ... Unfortunately, the image names must be zero based, so image1.jpg should be image0.jpg, ...
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 ...
11
votes
5answers
33k views

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?
10
votes
1answer
3k views

Best way to continue stopped move (mv) by merging directories?

I have moved (mv) a pretty large directory on my NAS (Linux based), but had to interrupt the procedure. Not being a regular Linux user, I though I could just continue and merge the rest later in. mv ...
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 ...
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?
10
votes
2answers
2k views

mv a file without breaking a symlink to that file

Is it possible to mv a file w/out breaking a symbolic link to that file? My initial response to this is no, and I'm working out a script based solution to change the links immediately following the ...
9
votes
7answers
7k views

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 ...
9
votes
3answers
919 views

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

Merging folders with mv?

If I move a folder with mv called "folder" to a directory that already contains "folder" will they merge or will it be replaced?
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 ...
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 ...
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 ...
9
votes
1answer
137 views

Strategies for maintaining a reference to a file after it was moved or renamed?

I've had a mac at work lately, and was amazed to see that Xcode would still find my latest project after I renamed its folder and moved it someplace else. Now I understand that this is the result of ...
8
votes
1answer
3k views

Command-line mv exclusion list

Is there a way to mv,cp, or any file operation such that I could specify all the files I don't want affected? For example, say I have a folder with the files file1, file2, and file3, and I want to ...
8
votes
3answers
3k views

How can I use ms-dos style wildcards with ls and mv?

I have the misfortune of coming from a MS-DOS background - but at least it makes me appreciate how much more powerful Linux is. I've been working on getting my Linux-Fu up to par, but there are a ...
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
3answers
664 views

cp or mv files to same directory they are already in when I am in another?

If I am in ~/blob and I have a file in ~/blob/a_long_directory_name/c/x.x I can type mv blob/a_long_directory_name/c/x.x blob/a_long_directory_name/even_more/y.y Is there any shortcut whereby I ...
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 ...
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 ...
7
votes
3answers
4k views

adding text to filename before extension

I would like to add text to the end of filename but before the extension. Right now I am trying, for f in *.shp; do echo $f_poly; done the output is, Quercus_acutifolia.shp_poly ...
7
votes
3answers
617 views

Generate new name for moved file to prevent overwriting?

How can I generate a new name for a file if there's an existing file With that same name? In a Desktop environment a new name is generated my appending a number to the end of the file name, but how ...
7
votes
5answers
16k views

How copy and rename files found in “find” function Linux?

I have a folder named /home/user/temps which has 487 folders. In each folder I have a file called thumb.png. I want to copy all files named thumb.png to a separate folder and rename them based on ...
7
votes
4answers
10k views

Copy/rename multiple files using regular expression (shell script)

I have a collection of files matching a pattern such as 'assignment02.cc', 'assignment02.h', 'assignment02.txt', etc. I would like to copy/rename these files into 'assignment03.cc', 'assignment03.h', ...
6
votes
8answers
6k views

Is there a way to make “mv” fail silently?

A command like mv foo* ~/bar/ produces this message in stderr if there are no files matching foo*. mv: cannot stat `foo*': No such file or directory However, in the script I'm working on that case ...
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
4answers
1k views

Delete spaces, hyphens, and underscores in filenames?

What is a good command to delete spaces, hyphens, and underscores from all files in a directory, or selected files? I use the following command with Thunar Custom Actions to slugify filenames: for ...
6
votes
3answers
14k views

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

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 to ...
6
votes
5answers
380 views

Renaming files with its path name

I have a .bdf file inside subfolders. All the .bdf have the same name: Loads.bdf Example: /home/user/folderxx/folderxxx/Load.bdf /home/user/folderxx/folderxxx/Load.bdf I need to find (and copy to ...
6
votes
5answers
287 views

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 ...
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 ...
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 ...
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 ...
6
votes
4answers
195 views

Strip Filenames and Rename

What rename command can I use which will delete the present filenames in a directory and replace them with alphanumeric filenames? Such as gg0001, gg0002, et cetera? And I'd like the command to work ...