Change all filenames in directory to numerals

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I have files in a directory where filenames are like
01 ABC DEF.m4a
02 DEF ABC.m4a
etc...
I want to convert these to
1.m4a
2.m4a
etc...
How can I do this using the command line?
files
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
I have files in a directory where filenames are like
01 ABC DEF.m4a
02 DEF ABC.m4a
etc...
I want to convert these to
1.m4a
2.m4a
etc...
How can I do this using the command line?
files
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have files in a directory where filenames are like
01 ABC DEF.m4a
02 DEF ABC.m4a
etc...
I want to convert these to
1.m4a
2.m4a
etc...
How can I do this using the command line?
files
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I have files in a directory where filenames are like
01 ABC DEF.m4a
02 DEF ABC.m4a
etc...
I want to convert these to
1.m4a
2.m4a
etc...
How can I do this using the command line?
files
files
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited Oct 4 at 6:57
roaima
40.9k547111
40.9k547111
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked Oct 4 at 6:53
Perseus14
132
132
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Perseus14 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
If you have the perl version of rename (sometimes called prename) you can use this
rename -n 's/^0*(d+).*(.m4a)z/$1$2/s' [0-9]*.m4a
When you're happy it's going to do what you want, remove the -n flag.
This uses a Regular Expression match:
^- require start-of-subject0*- match zero or more "0"(d+)- match and remember one or more decimal digits.*- match everything until...(.m4a)- match and remember literal ".m4a"z- require end-of-subjectùsflag - make sure.matches any byte (including newline, also valid in file names)
and then uses $1 and $2 to reference the value of the bracketed expressions.
ù Not strictly necessary here as the file names given by the shell as argument all end in .m4a and the previous .* is greedy. $ would also work here, but in rename which works on file names (which can be any sequence of non-0 bytes including newline), z is preferable as $ matches at the end of the subject like z but also before an eventual last newline character.
add a comment |Â
up vote
1
down vote
How for would
for FN in *.m4a; do mv -i "$FN" "$FN%% *.m4a"; done
get you?
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If you have the perl version of rename (sometimes called prename) you can use this
rename -n 's/^0*(d+).*(.m4a)z/$1$2/s' [0-9]*.m4a
When you're happy it's going to do what you want, remove the -n flag.
This uses a Regular Expression match:
^- require start-of-subject0*- match zero or more "0"(d+)- match and remember one or more decimal digits.*- match everything until...(.m4a)- match and remember literal ".m4a"z- require end-of-subjectùsflag - make sure.matches any byte (including newline, also valid in file names)
and then uses $1 and $2 to reference the value of the bracketed expressions.
ù Not strictly necessary here as the file names given by the shell as argument all end in .m4a and the previous .* is greedy. $ would also work here, but in rename which works on file names (which can be any sequence of non-0 bytes including newline), z is preferable as $ matches at the end of the subject like z but also before an eventual last newline character.
add a comment |Â
up vote
2
down vote
accepted
If you have the perl version of rename (sometimes called prename) you can use this
rename -n 's/^0*(d+).*(.m4a)z/$1$2/s' [0-9]*.m4a
When you're happy it's going to do what you want, remove the -n flag.
This uses a Regular Expression match:
^- require start-of-subject0*- match zero or more "0"(d+)- match and remember one or more decimal digits.*- match everything until...(.m4a)- match and remember literal ".m4a"z- require end-of-subjectùsflag - make sure.matches any byte (including newline, also valid in file names)
and then uses $1 and $2 to reference the value of the bracketed expressions.
ù Not strictly necessary here as the file names given by the shell as argument all end in .m4a and the previous .* is greedy. $ would also work here, but in rename which works on file names (which can be any sequence of non-0 bytes including newline), z is preferable as $ matches at the end of the subject like z but also before an eventual last newline character.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If you have the perl version of rename (sometimes called prename) you can use this
rename -n 's/^0*(d+).*(.m4a)z/$1$2/s' [0-9]*.m4a
When you're happy it's going to do what you want, remove the -n flag.
This uses a Regular Expression match:
^- require start-of-subject0*- match zero or more "0"(d+)- match and remember one or more decimal digits.*- match everything until...(.m4a)- match and remember literal ".m4a"z- require end-of-subjectùsflag - make sure.matches any byte (including newline, also valid in file names)
and then uses $1 and $2 to reference the value of the bracketed expressions.
ù Not strictly necessary here as the file names given by the shell as argument all end in .m4a and the previous .* is greedy. $ would also work here, but in rename which works on file names (which can be any sequence of non-0 bytes including newline), z is preferable as $ matches at the end of the subject like z but also before an eventual last newline character.
If you have the perl version of rename (sometimes called prename) you can use this
rename -n 's/^0*(d+).*(.m4a)z/$1$2/s' [0-9]*.m4a
When you're happy it's going to do what you want, remove the -n flag.
This uses a Regular Expression match:
^- require start-of-subject0*- match zero or more "0"(d+)- match and remember one or more decimal digits.*- match everything until...(.m4a)- match and remember literal ".m4a"z- require end-of-subjectùsflag - make sure.matches any byte (including newline, also valid in file names)
and then uses $1 and $2 to reference the value of the bracketed expressions.
ù Not strictly necessary here as the file names given by the shell as argument all end in .m4a and the previous .* is greedy. $ would also work here, but in rename which works on file names (which can be any sequence of non-0 bytes including newline), z is preferable as $ matches at the end of the subject like z but also before an eventual last newline character.
edited Oct 4 at 13:50
Stéphane Chazelas
287k53531868
287k53531868
answered Oct 4 at 7:00
roaima
40.9k547111
40.9k547111
add a comment |Â
add a comment |Â
up vote
1
down vote
How for would
for FN in *.m4a; do mv -i "$FN" "$FN%% *.m4a"; done
get you?
add a comment |Â
up vote
1
down vote
How for would
for FN in *.m4a; do mv -i "$FN" "$FN%% *.m4a"; done
get you?
add a comment |Â
up vote
1
down vote
up vote
1
down vote
How for would
for FN in *.m4a; do mv -i "$FN" "$FN%% *.m4a"; done
get you?
How for would
for FN in *.m4a; do mv -i "$FN" "$FN%% *.m4a"; done
get you?
answered Oct 4 at 11:10
RudiC
1,84219
1,84219
add a comment |Â
add a comment |Â
Perseus14 is a new contributor. Be nice, and check out our Code of Conduct.
Perseus14 is a new contributor. Be nice, and check out our Code of Conduct.
Perseus14 is a new contributor. Be nice, and check out our Code of Conduct.
Perseus14 is a new contributor. Be nice, and check out our Code of Conduct.
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473150%2fchange-all-filenames-in-directory-to-numerals%23new-answer', 'question_page');
);
Post as a guest
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
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
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