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

-2
votes
1answer
65 views

Find part of filename

Please help with my task: I have a folder with three sub-folders containing six files each. There are two files in each sub-folder with :nopm in their file names. I need to create a shell script ...
0
votes
1answer
42 views

Replace some characters in a certain part of a filename

On Solaris, I've got a script that succesfully do that: USER,REPORT_NAME,DD:MM:HH24.pdf -> USER,REPORT_NAME,DD_MM_HH24.pdf The one-liner is this: for f in *:*; do mv "$f" $(echo "$f" | tr ':' '...
1
vote
1answer
29 views

How to recursively add zeroes to a file name [duplicate]

I have a folder with these files: 03.jpg 04.jpg 05.jpg 99.jpg I want to rename these files to 003.jpg 004.jpg 005.jpg 099.jpg by using a bash script. How can I do this?
4
votes
2answers
77 views

bulk renaming files to their folders name

I have a folder structure like that: 'Pictures/2015/2015-01-02/random_name.jpg' and I want to rename the files to '2015-01-02 001.jpg', '2015-01-02 002.jpg' etc. I'm not really familiar with bash ...
3
votes
3answers
633 views

How to rename multiple files to their contents' MD5 sum?

I would like to rename some files to their contents' MD5 sum; for example, if file foo is empty, it should be renamed to d41d8cd98f00b204e9800998ecf8427e. Does it have to be script or can I use ...
5
votes
5answers
227 views

Renaming files using list

I have files available in a directory as: filename15_1 filename15_2 filename15_3 filename15_4 And so on. I have another file that contains mapping information for how I want to rename the files. ...
10
votes
1answer
300 views

What's with all the renames?

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 ...
1
vote
2answers
54 views

Why doesn't the rename command work as expected?

I have some files like: 1_suffix.txt 2_suffix.txt 3_suffix.txt I want to remove the _suffix.txt in them. I found a command called rename and use it as: First I tried: rename -v 's/*_suffix.txt$/\....
0
votes
2answers
101 views

rename multiple directories by adding one character [duplicate]

I have multiple folders named as follow: Name1 Name2 ... Name9 Name10 Name11 ... I need to rename them using mv command into: Name01 Name02 ... Name09 Name10 Name11 .....
3
votes
5answers
61 views

How do I exchange names for a large amount of files in a folder?

I want to randomize the names for about 350 files in a folder, but I want to have all the names that the files had originally. What I mean is I want All of the names in my folder randomized from the ...
0
votes
2answers
41 views

mv files into folders based on numbering in names

I have 30 folders: s-01 s-02 ... s-30 And, I have 30 files: txtFile-001 txtFile-002 ... txtFile-030 How can I perform the following operation in one shot mv txtFile-001 s-01/txtFile mv txtFile-...
0
votes
1answer
43 views

Bulk rename files - remove space

I have hundreds of files in a folder named transactions 1.csv, transactions 2.csv, transactions 3.csv etc How do i remove the space in the file names, so they become transactions1.csv,transactions2....
1
vote
1answer
55 views

Rename file names extracting pattern from them

I have a list of file names abc1.doc, abc2.doc and so on. Always in the form text[number].doc. I want them renames to [number].text.doc. How can I do this?
0
votes
3answers
67 views

Rename files in directory according to name of directory

I am trying to rename a bunch of files according to the names of their directory in Linux, SSH. I have a directory called XYZ01smith. In it are four files called smith_5*.I need to add prefix XYZ01 ...
1
vote
1answer
115 views

Batch renaming of files with ascending number

I have a batch of files: $ ls Li1Fe1O2_11 Li1Fe2O3_8 Li1Fe3O4_2 Li1Fe3O4_5 Li2Fe1O3_16 Li2Fe2O4_12 Li3Fe1O4_19 Li3Fe1O4_22 Li1Fe1O2_14 Li1Fe2O3_9 Li1Fe3O4_3 Li1Fe3O4_6 Li2Fe1O3_17 Li2Fe2O4_13 ...
1
vote
1answer
37 views

Using rename in the terminal to remove not accepted Windows characters

I have a folder full of files. Some of these files contain characters in their name that are not allowed by Windows. How can I use the command rename to find, and eventually remove all these ...
0
votes
2answers
86 views

Bash script that removes part of a filename in every file under a directory

I have several files under a directory whose names are of the form *.foo.bar. I would like to write a bash script to rename each of these files by removing the .foo part. For example, suppose that ...
1
vote
3answers
259 views

Copy filenames, and add path prefix, in a directory, recursively

I have a working directory: /home/myusername/projectdir The working directory contains files and sub-directories. The depth of sub-directories is not known. I want to put all the *.log files into the ...
2
votes
2answers
245 views

Batch rename according to number of pages in pdf file

I have a lot of papers in pdf files (and also other type of files in the same folder). I'd like to rename them using the pattern <current file name>[<number of pages>].pdf But after ...
0
votes
2answers
71 views

Rename the bunch of files with a specific pattern

I have number of files with following name details.. 2007-07-22-2300-11S.NAN___024_ABI___HH_E_SAC Where: 2007-07-22 is date. 2300-11S is hhmm-sec. NAN___024 is network same for each file (not ...
4
votes
3answers
245 views

How to remove space in all sub directories in shell script?

I tried following shell script to remove all spaces with underscores: find $1 -depth -name "* *" -print0 | \ while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done If I have a directory /home/user/...
8
votes
2answers
4k 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 files for xml_file in $(find $1 -name "* .xml" -type f); do echo "removing spaces from XML file:" $xml_file mv "$xml_file" "${...
0
votes
1answer
128 views

How to append extension to files with certain filename format

I have several files generated by a script but I neglected to have the script append a file extension. Each filename contains the substring k120 and no other file in the directory contains that ...
-1
votes
1answer
815 views

renaming files in SFTP session

This is part of a SFTP file transfer. Here are the steps: Check files with .csv extension and get them to the local directory. After that, move them to the another folder in the remote connection. ...
-2
votes
1answer
110 views

Undo a mass rename of files in a directory?

So I tried to use this script to get rid of a username in a bunch of files #!/bin/bash ls | while read -r FILE do mv -v "$FILE" `echo $FILE | tr '[DarkDream]' '.' ` done Instead, all of the ...
0
votes
2answers
67 views

Rename specific level of sub folders

I have list of sub folders inside a parent folder as follow: Parent folder folder1 foldera folder2 folderb folder3 folderc I want to rename the subfolders only in ...
2
votes
5answers
117 views

Change strings in multiple files to current subdirectory name

I have several directories each containing a file containing this line: ../a_a_q1.out ../a_a_q2.out ../a_a_q3.out I would like to loop through all the subdirectories, and change the a_a part to the ...
5
votes
4answers
138 views

Renaming: How to attach a word or rename multiple files [duplicate]

I have multiple files in my directory. for example: eventDataLog.txt.2015-04-23-22 eventDataLog.txt.2015-04-23-23 eventDataLog.txt.2015-04-24-01 eventDataLog.txt.2015-04-24-02 eventDataLog.txt.2015-...
0
votes
3answers
569 views

How to rename all files with special characters and spaces in a directory?

How can i rename all the files in a specific directory where the files contains blanks spaces and special characters ($ and @) in their names? I tried the rename command as follows to replace all the ...
0
votes
1answer
167 views

Renaming Duplicate Files with Flatten Folders Command

This command will move the contents of one or more folders to the parent folder. But if there are identical file names with the same extension then there will be files that are overwritten during the ...
1
vote
4answers
238 views

change last 10 characters of the base (not extension) of multiple files

I have many files of different lengths but the same extension and I have tried many commands to rename all of them at once. Is it possible to change only the last 10 characters of the base of all ...
1
vote
2answers
72 views

Make a Scheduled job for Renaming the files in a folder and send an updated alert email

I am writing a shell script, which can rename all the files in the folder, We need to search for a particular pattern of files every 30 seconds. Files in the below format need to be selected, ...
3
votes
2answers
275 views

remove whitespace from all items in a directory and sub directory

I have a directory which contains files and sub directories, some of which have whitespace in their names. Further more each of these sub directories contains files with whitespace in their names. Is ...
2
votes
2answers
189 views

Rename a set of files with pattern <name>.1.gz.html to <name>.html

I tried to use the command: mv *.1.gz.html *.html But, I got the response: <filename> is not a directory. How can I get this working? I tried the rename command as well, but, I couldn't ...
3
votes
2answers
216 views

Recursive copy files with rename

If I have input folder files_input that has subfilders like 01-2015, 02-2015, 03-2015 etc and all these subfolders have other subfolders. Each subfolder has only one file called index.html. How can ...
0
votes
1answer
165 views

Rename command not working as expected

I might be overlooking something really basic here but I have a bunch of files like fi-le_00.nc2 fi-le_01.nc2 fi-le_02.nc2 ... fi-le_24.nc2 and I want to rename them to fi-le_00:00:00 fi-le_01:00:...
5
votes
2answers
876 views

Why does renaming a file with mv command alter an inode's “change” date & time?

A file hello.c is renamed to hi.c. As the output of stat command shows, [change] time stamp has been changed. usually it is changed when inode of file got modified. Why renaming with mv command ...
1
vote
2answers
60 views

How to add some characters to filename via 'rename'?

For example I have a file named 5.jpg. How can I rename it to aaaaa.jpg with char a 5 times. I tried rename -v 's/(\d{1,})/a{$1}/g' * but this renames 5.jpg to a{5}.jpg, which is not what I want. I ...
1
vote
4answers
562 views

Remove all brackets in filename

I've been trying to remove all brackets in my filename(s). Can anyone help me create a bash script to do that? This bash script below work flawlessly for non-bracket filename(s), but if there are any ...
1
vote
3answers
189 views

Script to move one filetype and create a subfolder, if it exists?

I'm trying to find a script that would basically look recusively at a directory, and if the script finds file that are .flac files, it will create a subfolder called FLAC in that same folder, and move ...
3
votes
3answers
193 views

How to change suffix of the files

In a directory structure which has multiple subfolders and files in it. Some of the file names have the suffix _create (e.g. java1_create) and some of them with _bak (java2_bak). I need to rename ...
3
votes
3answers
436 views

Add extension for multiple files, based on their types

I know that there are many questions about adding extension to a multiple files. But none of them could get my job done. I have a huge list of images without extension, most of them are png, but ...
5
votes
5answers
6k views

How can I copy a file in a bash script and rename it while copying and place it in the same directory

How would I copy a file "file.doc" and rename it while copying to "file_copy.doc" and place it in the same directory ? And this only by calling the script and adding the file name in the argument: ...
0
votes
5answers
189 views

same file name in multiple directories: how to assign them with different names at the same time with only one command?

I think the title is self-explanatory, but my problem is: I have 23 different directories and in each one of them I have a file called accepted_hits.bam so I need to generate a unique name in each ...
1
vote
2answers
422 views

Remove string from file name to leave variable?

I have the following list of files: Dorn_Triatomine_A5201_sequence_1_unmappedforTdim_tdim.alleles.tsv Dorn_Triatomine_A5201_sequence_1_unmappedforTdim_tdim.matches.tsv ...
0
votes
3answers
59 views

Remove trailing ~ from files [closed]

I have a list of files ending with ~ I find them with find /var/www/vhosts/domain.com/httpdocs/ -type f -name "*.*~" How can I eliminate that ~
3
votes
7answers
336 views

find files based on name and moving them with renaming simultaneously

Consider I've directories named according to years and containing pdf files according to subject-code. ls output is: $ ls -l total 32 drwxrwxrwx 1 root root 4096 Apr 8 08:52 May-June-2011 ...
1
vote
3answers
99 views

Rename files (delete some characters that are not always the same)

I have some files named like this : DA1_ATGCATG_L001_R1.fastq.gz Oeu43_TCATGAC_L004_R2.fastq.gz I want to delete the part after the first "_" but keep the end of the names from "_R" to obtain this :...
1
vote
1answer
321 views

How to change configuration of detox (dash instead underscore)?

I found, best to this moment, a solution when changing all those annoying filenames in large quantities, making them readable and easier to manipulate with in command-line. So I found, among many ...
5
votes
2answers
606 views

cannot rename files with `[ ]` on its name?

I'd been trying to use the rename function in my debian, I searched here at unix.stackexchange but it seems the solution is not the same in my scenario which files contains [] [800p]-[WOLU-H]-test1....