how to remove all characters after and including “?” in filename?
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a large amount of files that were downloaded and ended up having what looks like authentication parameters added to the filename which I would like to remove. Examples:
file1.doc?b1h2uj3b123uiyb12
file2.xls?oi12jo3ij123oij
file3.jpg?0990xcizx0cxzczixuchbiasdu
Is there an easy way for me to strip everything after the question mark on the entire folder of files?
scripting terminal filenames rename
add a comment |
I have a large amount of files that were downloaded and ended up having what looks like authentication parameters added to the filename which I would like to remove. Examples:
file1.doc?b1h2uj3b123uiyb12
file2.xls?oi12jo3ij123oij
file3.jpg?0990xcizx0cxzczixuchbiasdu
Is there an easy way for me to strip everything after the question mark on the entire folder of files?
scripting terminal filenames rename
Are those the only files in the folder?
– Nasir Riley
Mar 17 at 19:14
Are you sure that's a literal question mark in the file name, and not some special character that e.g.ls
might print as a question mark? What does, e.g.printf "%qn" file1.doc*
(in Bash) show?
– ilkkachu
Mar 17 at 19:25
add a comment |
I have a large amount of files that were downloaded and ended up having what looks like authentication parameters added to the filename which I would like to remove. Examples:
file1.doc?b1h2uj3b123uiyb12
file2.xls?oi12jo3ij123oij
file3.jpg?0990xcizx0cxzczixuchbiasdu
Is there an easy way for me to strip everything after the question mark on the entire folder of files?
scripting terminal filenames rename
I have a large amount of files that were downloaded and ended up having what looks like authentication parameters added to the filename which I would like to remove. Examples:
file1.doc?b1h2uj3b123uiyb12
file2.xls?oi12jo3ij123oij
file3.jpg?0990xcizx0cxzczixuchbiasdu
Is there an easy way for me to strip everything after the question mark on the entire folder of files?
scripting terminal filenames rename
scripting terminal filenames rename
asked Mar 17 at 18:56
PhilPhil
1
1
Are those the only files in the folder?
– Nasir Riley
Mar 17 at 19:14
Are you sure that's a literal question mark in the file name, and not some special character that e.g.ls
might print as a question mark? What does, e.g.printf "%qn" file1.doc*
(in Bash) show?
– ilkkachu
Mar 17 at 19:25
add a comment |
Are those the only files in the folder?
– Nasir Riley
Mar 17 at 19:14
Are you sure that's a literal question mark in the file name, and not some special character that e.g.ls
might print as a question mark? What does, e.g.printf "%qn" file1.doc*
(in Bash) show?
– ilkkachu
Mar 17 at 19:25
Are those the only files in the folder?
– Nasir Riley
Mar 17 at 19:14
Are those the only files in the folder?
– Nasir Riley
Mar 17 at 19:14
Are you sure that's a literal question mark in the file name, and not some special character that e.g.
ls
might print as a question mark? What does, e.g. printf "%qn" file1.doc*
(in Bash) show?– ilkkachu
Mar 17 at 19:25
Are you sure that's a literal question mark in the file name, and not some special character that e.g.
ls
might print as a question mark? What does, e.g. printf "%qn" file1.doc*
(in Bash) show?– ilkkachu
Mar 17 at 19:25
add a comment |
2 Answers
2
active
oldest
votes
You can match all filenames with a question mark with *?*
, and remove the part after the ?
from a variable with $var%%?*
. The question mark itself is wildcard character, so has to be escaped in both cases.
A simple loop over the files and running mv
should do:
for f in ./*?*; do
echo mv -n "$f" "$f%%?*"
done
(The echo
is there so you can see what would be done before any changes being made. Remove it if the output looks sensible.)
add a comment |
Using the Perl rename
utility:
$ rename -v -n 's/[?].*//' *[?]*
rename(file1.doc?b1h2uj3b123uiyb12, file1.doc)
rename(file2.xls?oi12jo3ij123oij, file2.xls)
rename(file3.jpg?0990xcizx0cxzczixuchbiasdu, file3.jpg)
This applies the Perl substitution s/[?].*//
to each name. This would truncate the name just before the first question mark. The *[?]*
filename globbing pattern would expand to any name in the current directory that contains a question mark.
Run the command without -n
to actually rename files.
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%2f506861%2fhow-to-remove-all-characters-after-and-including-in-filename%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can match all filenames with a question mark with *?*
, and remove the part after the ?
from a variable with $var%%?*
. The question mark itself is wildcard character, so has to be escaped in both cases.
A simple loop over the files and running mv
should do:
for f in ./*?*; do
echo mv -n "$f" "$f%%?*"
done
(The echo
is there so you can see what would be done before any changes being made. Remove it if the output looks sensible.)
add a comment |
You can match all filenames with a question mark with *?*
, and remove the part after the ?
from a variable with $var%%?*
. The question mark itself is wildcard character, so has to be escaped in both cases.
A simple loop over the files and running mv
should do:
for f in ./*?*; do
echo mv -n "$f" "$f%%?*"
done
(The echo
is there so you can see what would be done before any changes being made. Remove it if the output looks sensible.)
add a comment |
You can match all filenames with a question mark with *?*
, and remove the part after the ?
from a variable with $var%%?*
. The question mark itself is wildcard character, so has to be escaped in both cases.
A simple loop over the files and running mv
should do:
for f in ./*?*; do
echo mv -n "$f" "$f%%?*"
done
(The echo
is there so you can see what would be done before any changes being made. Remove it if the output looks sensible.)
You can match all filenames with a question mark with *?*
, and remove the part after the ?
from a variable with $var%%?*
. The question mark itself is wildcard character, so has to be escaped in both cases.
A simple loop over the files and running mv
should do:
for f in ./*?*; do
echo mv -n "$f" "$f%%?*"
done
(The echo
is there so you can see what would be done before any changes being made. Remove it if the output looks sensible.)
answered Mar 17 at 19:29
ilkkachuilkkachu
63.4k10104181
63.4k10104181
add a comment |
add a comment |
Using the Perl rename
utility:
$ rename -v -n 's/[?].*//' *[?]*
rename(file1.doc?b1h2uj3b123uiyb12, file1.doc)
rename(file2.xls?oi12jo3ij123oij, file2.xls)
rename(file3.jpg?0990xcizx0cxzczixuchbiasdu, file3.jpg)
This applies the Perl substitution s/[?].*//
to each name. This would truncate the name just before the first question mark. The *[?]*
filename globbing pattern would expand to any name in the current directory that contains a question mark.
Run the command without -n
to actually rename files.
add a comment |
Using the Perl rename
utility:
$ rename -v -n 's/[?].*//' *[?]*
rename(file1.doc?b1h2uj3b123uiyb12, file1.doc)
rename(file2.xls?oi12jo3ij123oij, file2.xls)
rename(file3.jpg?0990xcizx0cxzczixuchbiasdu, file3.jpg)
This applies the Perl substitution s/[?].*//
to each name. This would truncate the name just before the first question mark. The *[?]*
filename globbing pattern would expand to any name in the current directory that contains a question mark.
Run the command without -n
to actually rename files.
add a comment |
Using the Perl rename
utility:
$ rename -v -n 's/[?].*//' *[?]*
rename(file1.doc?b1h2uj3b123uiyb12, file1.doc)
rename(file2.xls?oi12jo3ij123oij, file2.xls)
rename(file3.jpg?0990xcizx0cxzczixuchbiasdu, file3.jpg)
This applies the Perl substitution s/[?].*//
to each name. This would truncate the name just before the first question mark. The *[?]*
filename globbing pattern would expand to any name in the current directory that contains a question mark.
Run the command without -n
to actually rename files.
Using the Perl rename
utility:
$ rename -v -n 's/[?].*//' *[?]*
rename(file1.doc?b1h2uj3b123uiyb12, file1.doc)
rename(file2.xls?oi12jo3ij123oij, file2.xls)
rename(file3.jpg?0990xcizx0cxzczixuchbiasdu, file3.jpg)
This applies the Perl substitution s/[?].*//
to each name. This would truncate the name just before the first question mark. The *[?]*
filename globbing pattern would expand to any name in the current directory that contains a question mark.
Run the command without -n
to actually rename files.
answered Mar 17 at 19:44
Kusalananda♦Kusalananda
142k18265440
142k18265440
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%2f506861%2fhow-to-remove-all-characters-after-and-including-in-filename%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
Are those the only files in the folder?
– Nasir Riley
Mar 17 at 19:14
Are you sure that's a literal question mark in the file name, and not some special character that e.g.
ls
might print as a question mark? What does, e.g.printf "%qn" file1.doc*
(in Bash) show?– ilkkachu
Mar 17 at 19:25