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

3
votes
1answer
55 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
192 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
8k 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
33 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
65 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 ...
17
votes
4answers
9k 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
74 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 ...
5
votes
6answers
919 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
34 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
60 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 ...
0
votes
1answer
21 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: ...
2
votes
3answers
810 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
39 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
5k 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
959 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’ -> ...
1
vote
3answers
56 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
60 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
62k 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 ...
7
votes
4answers
23k 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 ...
30
votes
7answers
131k 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
62 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
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
27 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
34 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 ...
53
votes
8answers
47k 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 ...
56
votes
9answers
145k 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
62 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
43 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
99 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 ...
0
votes
1answer
32 views

Minimum file permissions to rename file

I put a 64-bit ELF file in my unprivileged user's home directory. I wonder which permissions do I need to have only possiblity to rename this file being logged in as unprivileged user. From what I ...
0
votes
3answers
80 views

Remove all special characters recursively from filename [duplicate]

I have multiple files in directories and subdirectories that have special characters not supported by Microsoft file shares and SharePoint. The types of characters run the gamut from tildes to ...
0
votes
1answer
23 views

Output NamingVariable for Multiple Files in Bash Script

I have a script I've created that will pad a series of Jpgs, create a subdirectory in the working directory, move the padded Jpgs to the subdirectory, change to the subdirectory, and then use ...
1
vote
1answer
36 views

Rename hundreds of files

I'm using Elementary OS (still very new to any UNIX system) and have hundreds of text files on my old hard drive that I need to sort. All text files have a name such as; lua - eng1-6TH4eI8gtf3.txt ...
1
vote
1answer
578 views

rename files matching specific mtime value within directory

I use simple set of shell commands to in order to create mysqldumps daily. The script is called by cron daemon. It looks like: presentdate="`date +%d-%m-%Y_%H:%M.%S`" basedir="/var/db_my_backup" ...
0
votes
2answers
87 views

Move log file which is older than 2 days

I want to move log files which are older than two days to a new directory by date, like below. Source: 1) /Test1/Server.log 2) /Test1/Server17032016.log Destination: ...
2
votes
1answer
49 views

Convert order for find … -exec

I want to rename files and directories. Let's suppose that I want to convert every ä to a, and I have Järjestelmä/Säätimet. So I say something like find -exec rename 's/ä/a/g'. Now find will convert ...
0
votes
2answers
48 views

using sed to modify all files in a directory and name the outputs accordingly

I want the sed command to work on all files in a directory and output the result into a new file. If f is val1.txt, the name of the output file should be val1_ended.txt -this is what I am trying to do ...
9
votes
2answers
5k 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
1k views

Why did mv delete a file with mv id_rsa *.old? [duplicate]

I wanted to backup my ~/.ssh/id_rsa to id_rsa.old, and it looks like it got deleted! How is this possible? :) root@localhost:~/.ssh# ls -l total 16 -rw------- 1 root root 3326 Mar 12 11:22 id_rsa ...
1
vote
2answers
72 views

Rename files in a directory

I have the files names as below in a directory example1.1.timestamp(.1457644337) example1.2.timestamp example1.3.timestamp and so on about 100 files. I need to rename all the files by removing the ...
2
votes
4answers
61 views

move a file that matches a pattern in a shell script

I have very little experience in writing shell scripts and need advice on how I can accomplish the following task. I need to move the most recent file in a directory where the filename matches a ...
36
votes
5answers
13k 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 ...
22
votes
7answers
27k 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 ...
1
vote
1answer
69 views

Rename multiple files in multiple directories to the name of the directory plus 1

I have been attempting to rename a bunch of files to their directories. I have multiple directories with spaces and no spaces /The Dark Tower. In it are multiple titles with file names with spaces ...