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.
1,207
questions
440
votes
18
answers
650k
views
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 $...
253
votes
16
answers
317k
views
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?
221
votes
9
answers
461k
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.
202
votes
14
answers
248k
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?
202
votes
5
answers
175k
views
How to choose directory name during untarring
Say I have a file named ugly_name.tar, which when extracted, becomes ugly_name directory. What command can I use so that the resulting directory name is pretty_name instead?
175
votes
7
answers
819k
views
How to move all files and folders via mv command [duplicate]
How can I move all files and folders from one directory to another via mv command?
130
votes
12
answers
374k
views
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
...
119
votes
7
answers
82k
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 ...
80
votes
9
answers
123k
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
...
71
votes
5
answers
301k
views
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 -...
69
votes
8
answers
146k
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
...
66
votes
3
answers
246k
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
...
64
votes
5
answers
84k
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 mv ...
60
votes
6
answers
41k
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-------^
It takes too long time to repeat ~/folder/...
46
votes
6
answers
157k
views
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 ...
42
votes
6
answers
79k
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
Quercus_agrifolia....
36
votes
12
answers
59k
views
Preserve directory structure when moving files using find
I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly.
#!/bin/bash
echo "Enter Your Source Directory"
read ...
36
votes
4
answers
5k
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 app/views/...
36
votes
4
answers
65k
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 ...
36
votes
2
answers
143k
views
How to move files in sftp server?
How can I move a file in sftp server on a different directory? I connect to this server using sftp and then try to move a file using
mv myfile.csv /my/dir/myfile.csv
but this generates an error. How ...
36
votes
2
answers
274k
views
mv: cannot stat No such file or directory in shell script
I wrote a script to move some files form one folder to another folder
but I got the following error, I checked 2 folders and notice for 1 folder there are such files and another there is no such files,...
34
votes
6
answers
123k
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?
33
votes
2
answers
28k
views
Remove prefixes from filenames
I have a bunch of files as follows:
04602635_b0294.DAT20120807164534
04602637_b0297.DAT20120807164713
04602638_b0296.DAT20120807164637
04602639_b0299.DAT20120807164819
04602640_b0298....
33
votes
1
answer
4k
views
What's with all the renames: prename, rename, file-rename?
On my Debian system (well, my LMDE system, but close enough), I have at least 3 different rename programs:
/usr/local/bin/rename : This is a Perl script, written by Tom Christiansen. Oddly enough, I ...
32
votes
4
answers
64k
views
How to replace spaces in all file names with underscore in Linux using shell script?
I tried following shell script which should replace spaces from all xml filenames
for xml_file in $(find $1 -name "* .xml" -type f);
do
echo "removing spaces from XML file:" $xml_file
mv "$xml_file"...
32
votes
3
answers
71k
views
Copy files with renaming
I have a huge file tree. Some files have same name but in different case, e.g., some_code.c and Some_Code.c.
So when I'm trying to copy it to an NTFS/FAT filesystem, it asks me about whether I want ...
31
votes
5
answers
30k
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?
31
votes
3
answers
27k
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 /home/...
31
votes
3
answers
11k
views
Renaming the current directory from a shell - possible?
Is it possible to rename the current working directory from within a shell (Bash in my particular case)? If I attempt to do this the straightforward way, I end up with an error:
nathan@nathan-desktop:...
31
votes
1
answer
14k
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 /...
29
votes
6
answers
156k
views
Rename multiples files using Bash scripting
I want to rename multiple files in the same directory using Bash scripting. Names of the files are as follows:
file2602201409853.p
file0901201437404.p
file0901201438761.p
file1003201410069.p
...
29
votes
2
answers
29k
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 ...
28
votes
1
answer
10k
views
zmv for zsh: Dry runs and man pages
I've heard great things about zmv in zsh, and would love to really learn to use it. However, I am still relatively unexperienced in zsh, and have some basic questions:
Is there is a man page for zmv ...
27
votes
3
answers
10k
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 \.
...
27
votes
7
answers
64k
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?
27
votes
7
answers
70k
views
Remove a specific extension from all the files in a directory [duplicate]
I have a couple of files with ".old" extension.
How can I remove the ".old" extension without remove the file?
I can do it manually but with more work:
mv file1.key.old file1.key
mv file2.pub....
26
votes
3
answers
15k
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 ...
26
votes
2
answers
27k
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 ...
24
votes
8
answers
70k
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 ...
23
votes
4
answers
64k
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 directory....
21
votes
4
answers
30k
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 ...
21
votes
4
answers
15k
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:
...
21
votes
3
answers
54k
views
How to force overwrite non-empty directories using `mv`
I am wanting to move (not just copy) a group of files/directories to a different directory some of which have name clashes with files/directories in the target directory. My main objective is to move ...
20
votes
6
answers
9k
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, image2....
20
votes
5
answers
62k
views
move file by list in file (with leading whitespace)
I have a file that contains file names. For example:
/tmp/list.txt (it is with the spaces at the start of each line):
/tmp/file.log
/app/nir/home.txt
/etc/config.cust
I want, using one line, ...
20
votes
4
answers
21k
views
What's the difference between 'rename' and 'mv'?
It's not completely clear to me, but what is the difference between mv and rename (from util-linux-ng 2.17.2 as /usr/bin/rename)? Are there advantages of one over the other beyond rename accepting ...
20
votes
2
answers
5k
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 ...
20
votes
1
answer
833
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
5
answers
46k
views
What is the most efficient way to move a large number of files that reside in a single directory?
CentOS 5.x
I apologize if this is a repeat question. I've seen a lot of similar questions (regarding deleting files) but not exactly the same scenario.
I have a directory containing hundreds of ...
19
votes
6
answers
38k
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 ...