Changing a multiple file extension using single line command
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I have some files whose names contain multiple extensions:
$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$
I want to rename them
to remove all the existing extensions and replace them with .txt
.ÃÂ
Output should be below:
$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt
Is it possible to use find and xargs command?
find filenames xargs mv
add a comment |Â
up vote
1
down vote
favorite
I have some files whose names contain multiple extensions:
$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$
I want to rename them
to remove all the existing extensions and replace them with .txt
.ÃÂ
Output should be below:
$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt
Is it possible to use find and xargs command?
find filenames xargs mv
1
What happens in the situation of another file namedFile1_2345.R.1234
? Why does the command need to be on a single line?
â Jeff Schaller
Aug 14 at 1:00
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I have some files whose names contain multiple extensions:
$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$
I want to rename them
to remove all the existing extensions and replace them with .txt
.ÃÂ
Output should be below:
$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt
Is it possible to use find and xargs command?
find filenames xargs mv
I have some files whose names contain multiple extensions:
$ ls -r
File1_345.R.12345
File1_3.234.R.6789
File1_2345.R.2345
File1_12345.R.12345
$
I want to rename them
to remove all the existing extensions and replace them with .txt
.ÃÂ
Output should be below:
$ ls -r
File1_345.txt
File1_3.txt
File1_2345.txt
File1_12345.txt
Is it possible to use find and xargs command?
find filenames xargs mv
find filenames xargs mv
edited 2 days ago
Jeff Schaller
32.6k849110
32.6k849110
asked Aug 13 at 20:23
Aashish Raj
3516
3516
1
What happens in the situation of another file namedFile1_2345.R.1234
? Why does the command need to be on a single line?
â Jeff Schaller
Aug 14 at 1:00
add a comment |Â
1
What happens in the situation of another file namedFile1_2345.R.1234
? Why does the command need to be on a single line?
â Jeff Schaller
Aug 14 at 1:00
1
1
What happens in the situation of another file named
File1_2345.R.1234
? Why does the command need to be on a single line?â Jeff Schaller
Aug 14 at 1:00
What happens in the situation of another file named
File1_2345.R.1234
? Why does the command need to be on a single line?â Jeff Schaller
Aug 14 at 1:00
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
7
down vote
If you want to remove all extensions (everything after the first dot)
from each filename, do
$ for f in *
do
mv -- "$f" "$f%%.*.txt"
done
Of course, if you really want to do this in one line,
just collapse the above to
$ for f in *; do mv -- "$f" "$f%%.*.txt"; done
add a comment |Â
up vote
1
down vote
You can do it with GNU Parallel:
find ... | parallel mv '=s/..*//='.txt
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
If you want to remove all extensions (everything after the first dot)
from each filename, do
$ for f in *
do
mv -- "$f" "$f%%.*.txt"
done
Of course, if you really want to do this in one line,
just collapse the above to
$ for f in *; do mv -- "$f" "$f%%.*.txt"; done
add a comment |Â
up vote
7
down vote
If you want to remove all extensions (everything after the first dot)
from each filename, do
$ for f in *
do
mv -- "$f" "$f%%.*.txt"
done
Of course, if you really want to do this in one line,
just collapse the above to
$ for f in *; do mv -- "$f" "$f%%.*.txt"; done
add a comment |Â
up vote
7
down vote
up vote
7
down vote
If you want to remove all extensions (everything after the first dot)
from each filename, do
$ for f in *
do
mv -- "$f" "$f%%.*.txt"
done
Of course, if you really want to do this in one line,
just collapse the above to
$ for f in *; do mv -- "$f" "$f%%.*.txt"; done
If you want to remove all extensions (everything after the first dot)
from each filename, do
$ for f in *
do
mv -- "$f" "$f%%.*.txt"
done
Of course, if you really want to do this in one line,
just collapse the above to
$ for f in *; do mv -- "$f" "$f%%.*.txt"; done
edited 2 days ago
answered Aug 13 at 21:20
G-Man
11.7k92658
11.7k92658
add a comment |Â
add a comment |Â
up vote
1
down vote
You can do it with GNU Parallel:
find ... | parallel mv '=s/..*//='.txt
add a comment |Â
up vote
1
down vote
You can do it with GNU Parallel:
find ... | parallel mv '=s/..*//='.txt
add a comment |Â
up vote
1
down vote
up vote
1
down vote
You can do it with GNU Parallel:
find ... | parallel mv '=s/..*//='.txt
You can do it with GNU Parallel:
find ... | parallel mv '=s/..*//='.txt
answered Aug 14 at 21:50
Ole Tange
11.4k1344103
11.4k1344103
add a comment |Â
add a comment |Â
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%2f462380%2fchanging-a-multiple-file-extension-using-single-line-command%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
1
What happens in the situation of another file named
File1_2345.R.1234
? Why does the command need to be on a single line?â Jeff Schaller
Aug 14 at 1:00