How to rename a files in a directoryHow to find the total number of occurrences of text and files with find commandHow can I rename all files in the current directory having a particular extension to another extension?How to rename files with sed and csvBatch renaming of filesHow do I copy multiple files by wildcard?Rename files depending on their parent directoryHow to zip files in a loop and move them to different directories?Rename files but retain files original time stamp in nameCommand to find and combine files matching a complex name patternUse scp to copy files of specific extension from directory
Can only the master initiate communication in SPI whereas in I2C the slave can also initiate the communication?
How about space ziplines
Generate ladder of integers using the least number of unique characters (in C++)
Why are BJTs common in output stages of power amplifiers?
Is it wrong to omit object pronouns in these sentences?
Tube from Heathrow to King's Cross
Why can't I share a one use code with anyone else?
What is this old US Air Force plane?
Should I communicate in my applications that I'm unemployed out of choice rather than because nobody will have me?
Why do the lights go out when someone enters the dining room on this ship?
Promotion comes with unexpected 24/7/365 on-call
Substring join or additional table, which is faster?
Was this seat-belt sign activation standard procedure?
Should generated documentation be stored in a Git repository?
Is there an academic word that means "to split hairs over"?
The meaning of the Middle English word “king”
Show solution to recurrence is never a square
How to redirect stdout to a file, and stdout+stderr to another one?
Do Grothendieck universes matter for an algebraic geometer?
How might a landlocked lake become a complete ecosystem?
What was the ring Varys took off?
Why was my Canon Speedlite 600EX triggering other flashes?
Single word that parallels "Recent" when discussing the near future
"The van's really booking"
How to rename a files in a directory
How to find the total number of occurrences of text and files with find commandHow can I rename all files in the current directory having a particular extension to another extension?How to rename files with sed and csvBatch renaming of filesHow do I copy multiple files by wildcard?Rename files depending on their parent directoryHow to zip files in a loop and move them to different directories?Rename files but retain files original time stamp in nameCommand to find and combine files matching a complex name patternUse scp to copy files of specific extension from directory
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have directory say /var/tmp/abc which has 4 files as -
12345-ram-3e3r5-io9490-89adu9.csv
45434-dam-qwe35-to9490-43adu9.csv
11234-cam-yy3r5-ro9490-85adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
bash shell ksh
add a comment |
I have directory say /var/tmp/abc which has 4 files as -
12345-ram-3e3r5-io9490-89adu9.csv
45434-dam-qwe35-to9490-43adu9.csv
11234-cam-yy3r5-ro9490-85adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
bash shell ksh
add a comment |
I have directory say /var/tmp/abc which has 4 files as -
12345-ram-3e3r5-io9490-89adu9.csv
45434-dam-qwe35-to9490-43adu9.csv
11234-cam-yy3r5-ro9490-85adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
bash shell ksh
I have directory say /var/tmp/abc which has 4 files as -
12345-ram-3e3r5-io9490-89adu9.csv
45434-dam-qwe35-to9490-43adu9.csv
11234-cam-yy3r5-ro9490-85adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
I want to rename all the csv files (find all the files & rename them) in shortest possible(probably one liner) way that,
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
bash shell ksh
bash shell ksh
edited 5 hours ago
Rocky86
asked 5 hours ago
Rocky86Rocky86
8919
8919
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Try:
for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
How it works:
for f in *.csv; do
This starts a loop over all
*.csv
files.mv -i -- "$f" "XXXXX-$f#*-"
This renames the files as you want, asking interactively before overwriting any file.
done
This marks the end of the loop.
Example:
$ ls -1
11234-cam-yy3r5-ro9490-85adu9.csv
12345-ram-3e3r5-io9490-89adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
45434-dam-qwe35-to9490-43adu9.csv
$ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
$ ls -1
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
add a comment |
rename -n 's/(w+)/XXXXX/' *.csv
remove the -n
when happy.
New contributor
add a comment |
I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".
Below, the files before the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
Below, the one liner command.
for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;
Below, the files after the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv
Is that what you're looking for? :)
References:
Looping through command output in bash
Substrings in bash
New contributor
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f518800%2fhow-to-rename-a-files-in-a-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try:
for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
How it works:
for f in *.csv; do
This starts a loop over all
*.csv
files.mv -i -- "$f" "XXXXX-$f#*-"
This renames the files as you want, asking interactively before overwriting any file.
done
This marks the end of the loop.
Example:
$ ls -1
11234-cam-yy3r5-ro9490-85adu9.csv
12345-ram-3e3r5-io9490-89adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
45434-dam-qwe35-to9490-43adu9.csv
$ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
$ ls -1
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
add a comment |
Try:
for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
How it works:
for f in *.csv; do
This starts a loop over all
*.csv
files.mv -i -- "$f" "XXXXX-$f#*-"
This renames the files as you want, asking interactively before overwriting any file.
done
This marks the end of the loop.
Example:
$ ls -1
11234-cam-yy3r5-ro9490-85adu9.csv
12345-ram-3e3r5-io9490-89adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
45434-dam-qwe35-to9490-43adu9.csv
$ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
$ ls -1
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
add a comment |
Try:
for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
How it works:
for f in *.csv; do
This starts a loop over all
*.csv
files.mv -i -- "$f" "XXXXX-$f#*-"
This renames the files as you want, asking interactively before overwriting any file.
done
This marks the end of the loop.
Example:
$ ls -1
11234-cam-yy3r5-ro9490-85adu9.csv
12345-ram-3e3r5-io9490-89adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
45434-dam-qwe35-to9490-43adu9.csv
$ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
$ ls -1
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
Try:
for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
How it works:
for f in *.csv; do
This starts a loop over all
*.csv
files.mv -i -- "$f" "XXXXX-$f#*-"
This renames the files as you want, asking interactively before overwriting any file.
done
This marks the end of the loop.
Example:
$ ls -1
11234-cam-yy3r5-ro9490-85adu9.csv
12345-ram-3e3r5-io9490-89adu9.csv
14423-sam-hh3r5-uo9490-869du9.csv
45434-dam-qwe35-to9490-43adu9.csv
$ for f in *.csv; do mv -i -- "$f" "XXXXX-$f#*-"; done
$ ls -1
XXXXX-cam-yy3r5-ro9490-85adu9.csv
XXXXX-dam-qwe35-to9490-43adu9.csv
XXXXX-ram-3e3r5-io9490-89adu9.csv
XXXXX-sam-hh3r5-uo9490-869du9.csv
answered 4 hours ago
John1024John1024
49.4k5114129
49.4k5114129
add a comment |
add a comment |
rename -n 's/(w+)/XXXXX/' *.csv
remove the -n
when happy.
New contributor
add a comment |
rename -n 's/(w+)/XXXXX/' *.csv
remove the -n
when happy.
New contributor
add a comment |
rename -n 's/(w+)/XXXXX/' *.csv
remove the -n
when happy.
New contributor
rename -n 's/(w+)/XXXXX/' *.csv
remove the -n
when happy.
New contributor
New contributor
answered 4 hours ago
SHawardenSHawarden
412
412
New contributor
New contributor
add a comment |
add a comment |
I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".
Below, the files before the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
Below, the one liner command.
for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;
Below, the files after the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv
Is that what you're looking for? :)
References:
Looping through command output in bash
Substrings in bash
New contributor
add a comment |
I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".
Below, the files before the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
Below, the one liner command.
for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;
Below, the files after the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv
Is that what you're looking for? :)
References:
Looping through command output in bash
Substrings in bash
New contributor
add a comment |
I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".
Below, the files before the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
Below, the one liner command.
for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;
Below, the files after the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv
Is that what you're looking for? :)
References:
Looping through command output in bash
Substrings in bash
New contributor
I liked the little challenge that you've posted, so here is my solution. I'm assuming that all your files starts with 5 numeric characters, so using the cut command to replace the initial numeric files by "XXXXX".
Below, the files before the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 11111_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 12345_baz_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
Below, the one liner command.
for src in *.csv; do dst=XXXXX$(echo $src| cut -c6-); mv $src $dst; done;
Below, the files after the command.
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 67890_foo_file.xml
-rw-rw-r--. 1 daniel daniel 0 May 13 22:54 XXXXX_bar_file.csv
-rw-rw-r--. 1 daniel daniel 0 May 13 23:18 XXXXX_baz_file.csv
Is that what you're looking for? :)
References:
Looping through command output in bash
Substrings in bash
New contributor
edited 4 hours ago
New contributor
answered 4 hours ago
danieldeveloper001danieldeveloper001
1315
1315
New contributor
New contributor
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f518800%2fhow-to-rename-a-files-in-a-directory%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown