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

0
votes
3answers
33 views

Pad number within string and rename file [duplicate]

I have some filenames as such. a2.txt.gz d12.txt.gz k5.txt.gz m4.txt.gz ... one character followed by 1 or 2 numbers followed by .txt.gz. I would like to add single numbers with a zero before the ...
-1
votes
1answer
48 views

Recursively move files with different names and different extensions [duplicate]

How can I recursively find all audio and video files in a directory and move them elsewhere in a single operation?
0
votes
1answer
43 views

Rename file (Prefix) with full path?

I'd to Prefix my files (.dat) like this : CLY_BIZ_COM_PERD.dat -> 20160622CLY_BIZ_COM_PERD.dat I have tried the following: key=`date "+%Y%m%d"` for i in $(ls /Path/*.dat); do mv ${i} "${key}${i}...
1
vote
5answers
53 views

How can I use the rename command to fix these file names?

I'm trying to change files that look like 01 Track name.mp3 into 01 - Track name.mp3 So far my futile attempts were rename '0. ' '$&- ' *.mp3 rename 's/0. /$&- /' *.mp3 rename '/0. /' '/$&...
1
vote
2answers
92 views

BASH file mass rename with counter

I want to rename all the files in a folder with PREFIX+COUNTER+FILENAME for ex. input: england.txt canada.txt france.txt output: CO_01_england.txt CO_02_canada.txt CO_03_france.txt ...
1
vote
3answers
45 views

Move files by reading their file names to different directories

I need to move files by reading their names. I have to move system generated files and the names include a time stamp. I need to move the files by reading the file name by month. If the file name ...
1
vote
1answer
29 views

How to convert GBK to UTF-8 in a mixed encoding directory?

Background : You can skip this section, if you are not interested in. I usually backup my MicroSD card of my cell phone, with command sudo dd if=/dev/sdc1 of=~/Document/Cell\ Phone\ Files/...
0
votes
1answer
24 views

Cannot find the right regex for rename

I have some TV shows stored on my Ubuntu server and I could rename them all, so Kodi can recognise them, exept one: First Episode, first Season: Name - S01E001 - Title part1 Name - S01E001 - Title ...
3
votes
4answers
9k views

Move huge number of files into date structured directory order

I have about 1 million files in this directory: /home/username/images/ Each of the files are called something like: 012345678910(Place)_0_20120414185957_28841.jpg with the timestamp part of the ...
0
votes
1answer
34 views

Bulk file rename with a list of rules

Is there a way to rename multiple files, using some template written for example in the txt file? I need to replace some specific words with some other words in the bunch of files. I've got, say 1000+ ...
1
vote
1answer
35 views

How to batch rename files by exchanging substrings in the filenames?

I have files like ABC_asd_f.txt, DEF_qwe_r.txt, ... How can I exchange the uppercases before the first underscore with the lowercases after? So ABC_asd_f.txt becomes asd_f_ABC.txt, DEF_qwe_r.txt ...
1
vote
2answers
69 views

Rename all spaces in image file names inside html php files

Inside different htm.gz, html.gz and php.gz web files I have images and the ones in .jpg format have name with space instead of "-", but in /images/ directory where all images are located they have "-"...
1
vote
1answer
327 views

Copying wallpaper images into a single folder

In my ubuntu 12.04 set-up, there are lots of wallpaper images in the directory /usr/share/wallpapers. For example, one might be usr/share/wallpapers/Leafs_Labyrinth/contents/images/1600x1200.jpg ...
4
votes
3answers
15k views

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

How to replace a text string in multiple files in Linux How to rename multiple files by replacing word in file name? Replace string in files with certain file extension Searching a number of files ...
4
votes
2answers
67 views

Rename Multiple files gzips them and delete older than 10 days

I'm new to Linux/Unix and slowly learning it step by step. Unfortunately on today’s job interview was surprised by a task to do (which of course I didn’t know). I was asked to prepare a bash script ...
1
vote
1answer
32 views

Renaming folder using a txt file [closed]

I'm working in my terminal using bash trying to rename the folders: 1 2 3 4 5 I'd like to rename them according to a.txt file: a 2 c 3 d 5 e 1 b 4 The order in the .txt file is completely ...
2
votes
1answer
41 views

How to change name of “~” directory? Debian 8 [duplicate]

I was providing an install directory for SteamCMD to install a server to, but it created a "~" directory as the parent directory for the directory I wanted. Example: /home/steam/SteamCMD/~/...
3
votes
1answer
63 views

Rename files based on JSON content

I have two sets of files; file1.txt file1.json file2.txt file2.json file3.txt file3.json ... fileN.txt fileN.json json files contain the following format: {"ago": "59 sec ago", "...
3
votes
3answers
199 views

Atomic removal of directory

Because rename(2) is called by mv, is it safe to assume the following would be atomic? $ mv /home/me/someDir /tmp/toBeDeleted $ rm -rf /tmp/toBeDeleted
11
votes
5answers
9k 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 ...
3
votes
2answers
47 views

Using 'rename' & regex to edit filenames

I'm new to regular expression, and am trying to use regex to rename some files. I am using rename (this one) to rename said files. Below is an example command. $ rename -n 's/\(feat.//' *.mp3 (-n ...
1
vote
7answers
72 views

Rename files add dashes after fourth and sixth characters

I have some files such as: 20150716_something-here 20150716_something-heretoo 20150716_something-hereaswell They need to be renamed as 2015-07-16_something-here 2015-07-16_something-heretoo 2015-...
17
votes
4answers
10k 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: ...
7
votes
4answers
16k views

Rename files in the local folder adding a prefix or suffix

I have many files in a folder and I want to add either prefix or a suffix (not both) to them. I checked here and found out I can use for filename in *.jpg; do mv "$filename" "prefix_$filename"; done; ...
1
vote
4answers
85 views

Bash script to fix file names

I have hundreds of folders with thousands subdirectories and files inside of them. The file names are currently in the format sf{number}-{number} - {text} and I need everything deleted until {text}....
5
votes
6answers
949 views

Flatten Directory but Preserve Directory Names in New Filename

How can I flatten a directory in the following format? Before: ./aaa/bbb/ccc.png After: ./aaa-bbb-ccc.png
1
vote
1answer
39 views

renaming files in a folder

In one directory I have many files which look like this: Galaxy100-[0025-CL3.single.bed].bed and I would like to change it to: 0025-CL3.single.bed I tried this rename 's/Galaxy[0-9] - \[//' *, ...
0
votes
1answer
64 views

inserting modified date into filename - 2 cases

I believe I'll ask two separate questions, but the context is the same, so I hope it's alright. I have an output of few processes as presented below (which I can't modify). 25978.csv 26044.csv 26865....
0
votes
1answer
23 views

Why find is not finding some folders with spaces?

find -name "* *" -type d | rename 's/ /_/g' For instance, 'Paired End' folder name on this path is not being replaced with spaces: /home/bernardo/Raw_data/Raw_data_M6_and_V2_UIC_April_2014/...
2
votes
3answers
825 views

Rename files with random characters from sha1sum. Will the names be unique?

I'm using this command to rename files with random characters from sha1sum and move all files from subdirectories to the current directory: for fname in `find . -type f`; do mv "$fname" $(echo "$...
1
vote
4answers
41 views

rename the 10 most-recently modified files on AIX

I have some .xls files in a defined directory (say in /A/B). I want to rename top 10 latest files and append "-bkp" in their names. I tried, not working ls -lt *.xls | head -1 | awk '{print "mv " $9 ...
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: ...
2
votes
2answers
1k views

Is there a --parents option for mv like for cp?

cp has a useful feature --parents that allows a file's directory structure to be copied to another directory: $ cp -v --parents source/directory/from target/ ‘source/directory/from’ -> ‘target/...
1
vote
3answers
82 views

How can I recursively replace a string in file and directory names?

I have a git clone of etckeeper, and I'm trying to rename all files and directories with etckeeper in the name to usrkeeper. For example, ./foo-etckeeper-bar should be renamed to ./foo-usrkeeper-bar. ...
0
votes
3answers
62 views

How to batch rename files using loop combination in bash?

I have 2 folder structure like this: SOURCE_FOLDER_W_GOOD_NAMES ├── A_some_name.png ├── B_another_different_name.png ├── C_just_another_too.png └── D_this_one_stop_this_example.png Another folder: ...
15
votes
5answers
64k 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 -...
9
votes
4answers
26k views

rename multiple files with mv

I want to rename a couple of files in the same directory. When you start to google this there is plenty of help available. What I saw the most if you only want to change the extension is mv *.txt *....
31
votes
7answers
137k 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?
1
vote
2answers
51 views

How to rename certain directories if the parent has a particular name?

I have to do some global renaming in an Eclipse plugin project, although the fact that the code is Java and it's an Eclipse plugin is irrelevant. Basically, the steps I need to perform are the ...
1
vote
1answer
31 views

Ubuntu shell curly brace expansion - confusion with sox command

I'd like to search through multiple subdirectories and convert all .mp3 files to .al files. Here's how I do it: find . -name '*.mp3' -type f -print0 | xargs -0 -t -r -I {} sox {} -r 8000 -c1 -e a-law ...
1
vote
2answers
39 views

Rename all the files with a specific extension in all the subdirectory [duplicate]

I have a lot of directories. Each one of these has a file with a specific extension .ext. I want to rename these files. Example: // Note: The names are random, can have spaces and special ...
59
votes
8answers
50k 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?
1
vote
3answers
40 views

Rename all the files in a folder such that it removes the text between two same characters

I have huge number of files in folders whose names are as following: abc.test.txt edf.main.txt num2.tb.doc file3.map.csv file4.test.csv I would like these files to be renamed such a way that the ...
13
votes
3answers
2k 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 ...
60
votes
9answers
151k 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 ...
0
votes
1answer
67 views

Why is the rename utility on Debian/Ubuntu different than the one on other distributions, like CentOS?

On CentOS, the rename command uses two simple strings, from and to. rename from to file... while on Debian/Ubuntu it uses a perl-style regular expression. rename [ -v ] [ -n ] [ -f ] perlexpr [ ...
1
vote
3answers
51 views

Rename only one file in each directory, based on condition

I have 100 folders inside every folder I have one or two files named as the following: XXX_001_014_max.jpg XXX_001_024_max.jpg I saved the folders names in a file "list.txt" I ran the following ...
1
vote
0answers
22 views

How to remove a single quote from a file name? [duplicate]

I have some podcasts on my radio server which contain a timestamp when they should be played. I noticed one of them is put into single quotes 'filename.mp3', and I'm unable to remove them. Check this: ...
1
vote
2answers
143 views

rename multiple files in multiple directories using Bash scripting

I want to rename multiple files in multiple directories using Bash scripting. I have 772 such directories i.e from Nishi_001 to Nishi_772. Each directory has different number of files in it but in ...
0
votes
0answers
24 views

shortening a mv command to loop through multiple files [duplicate]

I used the following command to rename multiple files in different subdirectories. They all initially had a common name sample....., and I wanted to replace the word sample with a specific name for ...