Moving millions of files to a different directory with specfic name patternsNeed to copy files to existing directory and remove files already there with the same name but different extensionfind file, copy but with different nameIs there a better way than cp to copy millions of files while preserving hard links?Comparing files with different extensions but possibly similar contentsCopy files from a directory if name present in a text fileHow to copy multiple files with a same name from children directory to another directory without losing the parent directory?Copy directory structure with random number of filesMoving specific files to two different locationsMoving millions of small files results in “out of space” errorCopying files based on partial names in a file
Nested-Loop-Join: How many comparisons and how many pages-accesses?
Variation in the spelling of word-final M
Why does the Earth have a z-component at the start of the J2000 epoch?
Is this a plot hole in the Lost Mine of Phandelver adventure?
Is it rude to tell recruiters I would only change jobs for a better salary?
Relationship between GCD, LCM and the Riemann Zeta function
Absconding a company after 1st day of joining
How did John Lennon tune his guitar
How would someone destroy a black hole that’s at the centre of a planet?
How to fit a linear model in the Bayesian way in Mathematica?
Can I activate an iPhone without an Apple ID?
I quit, and boss offered me 3 month "grace period" where I could still come back
3D-Plot with an inequality condition for parameter values
Can a continent naturally split into two distant parts within a week?
Alternatives to using writing paper for writing practice
Did the Shuttle's rudder or elevons operate when flown on its carrier 747?
Possible isometry groups of open manifolds
Is `curl something | sudo bash -` a reasonably safe installation method?
Is a public company able to check out who owns its shares in very detailed format?
Why linear regression uses "vertical" distance to the best-fit-line, instead of actual distance?
What exactly is the Tension force?
What are some symbols representing peasants/oppressed persons fighting back?
how to generate correct single and double quotes in tex
How can I legally visit the United States Minor Outlying Islands in the Pacific?
Moving millions of files to a different directory with specfic name patterns
Need to copy files to existing directory and remove files already there with the same name but different extensionfind file, copy but with different nameIs there a better way than cp to copy millions of files while preserving hard links?Comparing files with different extensions but possibly similar contentsCopy files from a directory if name present in a text fileHow to copy multiple files with a same name from children directory to another directory without losing the parent directory?Copy directory structure with random number of filesMoving specific files to two different locationsMoving millions of small files results in “out of space” errorCopying files based on partial names in a file
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have millions of files with the following nomenclature on a Linux machine:
1559704165_a1ac6f55fef555ee.jpg
The first 10 digits are timestamp and the ones followed by a _
are specific ids. I want to move all the files matching specific filename ids to a different folder.
I tried this on the directory with files
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
However I am getting an error indicating:
bash 1559704165_a1ac6f55fef555ee.jpg: command not found
When I tried, mv ??????????_a1ac*.jpg
I am getting argument list too long error. I have atleast 15 different filename patterns. How do I move them.
file-copy
add a comment |
I have millions of files with the following nomenclature on a Linux machine:
1559704165_a1ac6f55fef555ee.jpg
The first 10 digits are timestamp and the ones followed by a _
are specific ids. I want to move all the files matching specific filename ids to a different folder.
I tried this on the directory with files
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
However I am getting an error indicating:
bash 1559704165_a1ac6f55fef555ee.jpg: command not found
When I tried, mv ??????????_a1ac*.jpg
I am getting argument list too long error. I have atleast 15 different filename patterns. How do I move them.
file-copy
1
The bash says it all: it tries to execute that filename as it is the first on the line in the 2nd stage of the pipe (your 2nd stage pipe is:| ??????????_a1ac*.jpg
: bash expands it to several filename, the first being1559704165_a1ac6f55fef555ee.jpg
, si you end up, in that 2nd pipe stage, trying to execute:1559704165_a1ac6f55fef555ee.jpg next_matching_filename 3rd_matching_filename ... nth_matching_filename
. I guess you tried instead to filter to that filename (see answers below for that)
– Olivier Dulac
Jul 8 at 13:08
add a comment |
I have millions of files with the following nomenclature on a Linux machine:
1559704165_a1ac6f55fef555ee.jpg
The first 10 digits are timestamp and the ones followed by a _
are specific ids. I want to move all the files matching specific filename ids to a different folder.
I tried this on the directory with files
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
However I am getting an error indicating:
bash 1559704165_a1ac6f55fef555ee.jpg: command not found
When I tried, mv ??????????_a1ac*.jpg
I am getting argument list too long error. I have atleast 15 different filename patterns. How do I move them.
file-copy
I have millions of files with the following nomenclature on a Linux machine:
1559704165_a1ac6f55fef555ee.jpg
The first 10 digits are timestamp and the ones followed by a _
are specific ids. I want to move all the files matching specific filename ids to a different folder.
I tried this on the directory with files
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
However I am getting an error indicating:
bash 1559704165_a1ac6f55fef555ee.jpg: command not found
When I tried, mv ??????????_a1ac*.jpg
I am getting argument list too long error. I have atleast 15 different filename patterns. How do I move them.
file-copy
file-copy
edited Jul 6 at 13:56
terdon♦
138k33 gold badges285 silver badges462 bronze badges
138k33 gold badges285 silver badges462 bronze badges
asked Jul 6 at 13:07
ApricotApricot
2873 silver badges13 bronze badges
2873 silver badges13 bronze badges
1
The bash says it all: it tries to execute that filename as it is the first on the line in the 2nd stage of the pipe (your 2nd stage pipe is:| ??????????_a1ac*.jpg
: bash expands it to several filename, the first being1559704165_a1ac6f55fef555ee.jpg
, si you end up, in that 2nd pipe stage, trying to execute:1559704165_a1ac6f55fef555ee.jpg next_matching_filename 3rd_matching_filename ... nth_matching_filename
. I guess you tried instead to filter to that filename (see answers below for that)
– Olivier Dulac
Jul 8 at 13:08
add a comment |
1
The bash says it all: it tries to execute that filename as it is the first on the line in the 2nd stage of the pipe (your 2nd stage pipe is:| ??????????_a1ac*.jpg
: bash expands it to several filename, the first being1559704165_a1ac6f55fef555ee.jpg
, si you end up, in that 2nd pipe stage, trying to execute:1559704165_a1ac6f55fef555ee.jpg next_matching_filename 3rd_matching_filename ... nth_matching_filename
. I guess you tried instead to filter to that filename (see answers below for that)
– Olivier Dulac
Jul 8 at 13:08
1
1
The bash says it all: it tries to execute that filename as it is the first on the line in the 2nd stage of the pipe (your 2nd stage pipe is:
| ??????????_a1ac*.jpg
: bash expands it to several filename, the first being 1559704165_a1ac6f55fef555ee.jpg
, si you end up, in that 2nd pipe stage, trying to execute: 1559704165_a1ac6f55fef555ee.jpg next_matching_filename 3rd_matching_filename ... nth_matching_filename
. I guess you tried instead to filter to that filename (see answers below for that)– Olivier Dulac
Jul 8 at 13:08
The bash says it all: it tries to execute that filename as it is the first on the line in the 2nd stage of the pipe (your 2nd stage pipe is:
| ??????????_a1ac*.jpg
: bash expands it to several filename, the first being 1559704165_a1ac6f55fef555ee.jpg
, si you end up, in that 2nd pipe stage, trying to execute: 1559704165_a1ac6f55fef555ee.jpg next_matching_filename 3rd_matching_filename ... nth_matching_filename
. I guess you tried instead to filter to that filename (see answers below for that)– Olivier Dulac
Jul 8 at 13:08
add a comment |
5 Answers
5
active
oldest
votes
You should use:
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg'
-exec mv -t destination "" +
So maxdepth 1
means that you want to search in current directory no subdirectories.
type f
means find only files.
name '??????????_a1ac*.jpg'
is a pattern that matches with file you are searching.
mv -t destination "" +
means move matched files to destination. Here +
adds new matched files to previous one like:
mv -t dest a b c d
Here a b c d are different files.
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
Note that-t
is a GNU extension and so may not be available on other types of UNIX derivatives.
– Kevin
Jul 8 at 18:22
When you say "Double quotes prevents word splitting." I presume you are referring to""
, in which case I want to point out thatis not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.
– jw013
Jul 9 at 18:59
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
add a comment |
Your command,
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
Pipes the list of all the files TO all the files!
find . -maxdepth 1 -type f -name `*_a1ac*.jpg` -print0 |
xargs -0 -r mv -t "/home/ubuntu/ntest"
will do the trick.
1
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
add a comment |
You're very close. You should use the -name
option to find
. And remember to quote the pattern.
So
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' |xargs mv -t "/home/ubuntu/ntest"
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
1
you should add a-print0
as the last argument to the find (instead of the default: -print), and add a-0
as the first option to xargs (ie:xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)
– Olivier Dulac
Jul 8 at 13:10
add a comment |
Not as "good" as the find
solutions, but another valid solution is to make the mv
commands more granular.
This does 4096 moves, with a fewer number of files moved per mv
operation.
FILEPAT=a1ac
for i in $(seq $((0x000)) $((0xfff)));
do
H=$(printf '%xn' $i)
mv 1559704165_$FILEPAT$H*.jpg /home/ubuntu/ntest
done
This is a clever hack for those withoutfind
(for whatever reason).
– forest
Jul 8 at 7:44
add a comment |
If you want to move files on the same host system, which I guess you are doing with your mv
, rsync
could be a faster option:
rsync -av --inplace -W /source/??????????_a1ac*.jpg /home/ubuntu/ntest/
--inplace
and -W
are set to speed up the process.
Should this yield another argument list too long error then you could feed lists to rsync
Make the list with find, for example
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and give it to rsync
rsync -av --inplace -W --files-from=/tmp/my_image_list.txt /path/to/files /home/ubuntu/ntest/
The source here is /path/to/files
, because rsync
will treat the list you give it as relative to your source.
The point being: rsync
is faster than mv
, if the files are not on the same filesystem.
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with--files-from=/tmp/my_image_list.txt
. The point being thatrsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.
– Robert Riedl
Jul 8 at 13:46
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
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%2f528679%2fmoving-millions-of-files-to-a-different-directory-with-specfic-name-patterns%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
You should use:
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg'
-exec mv -t destination "" +
So maxdepth 1
means that you want to search in current directory no subdirectories.
type f
means find only files.
name '??????????_a1ac*.jpg'
is a pattern that matches with file you are searching.
mv -t destination "" +
means move matched files to destination. Here +
adds new matched files to previous one like:
mv -t dest a b c d
Here a b c d are different files.
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
Note that-t
is a GNU extension and so may not be available on other types of UNIX derivatives.
– Kevin
Jul 8 at 18:22
When you say "Double quotes prevents word splitting." I presume you are referring to""
, in which case I want to point out thatis not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.
– jw013
Jul 9 at 18:59
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
add a comment |
You should use:
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg'
-exec mv -t destination "" +
So maxdepth 1
means that you want to search in current directory no subdirectories.
type f
means find only files.
name '??????????_a1ac*.jpg'
is a pattern that matches with file you are searching.
mv -t destination "" +
means move matched files to destination. Here +
adds new matched files to previous one like:
mv -t dest a b c d
Here a b c d are different files.
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
Note that-t
is a GNU extension and so may not be available on other types of UNIX derivatives.
– Kevin
Jul 8 at 18:22
When you say "Double quotes prevents word splitting." I presume you are referring to""
, in which case I want to point out thatis not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.
– jw013
Jul 9 at 18:59
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
add a comment |
You should use:
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg'
-exec mv -t destination "" +
So maxdepth 1
means that you want to search in current directory no subdirectories.
type f
means find only files.
name '??????????_a1ac*.jpg'
is a pattern that matches with file you are searching.
mv -t destination "" +
means move matched files to destination. Here +
adds new matched files to previous one like:
mv -t dest a b c d
Here a b c d are different files.
You should use:
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg'
-exec mv -t destination "" +
So maxdepth 1
means that you want to search in current directory no subdirectories.
type f
means find only files.
name '??????????_a1ac*.jpg'
is a pattern that matches with file you are searching.
mv -t destination "" +
means move matched files to destination. Here +
adds new matched files to previous one like:
mv -t dest a b c d
Here a b c d are different files.
edited Jul 10 at 4:00
answered Jul 6 at 13:42
Prvt_YadvPrvt_Yadv
3,7413 gold badges17 silver badges34 bronze badges
3,7413 gold badges17 silver badges34 bronze badges
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
Note that-t
is a GNU extension and so may not be available on other types of UNIX derivatives.
– Kevin
Jul 8 at 18:22
When you say "Double quotes prevents word splitting." I presume you are referring to""
, in which case I want to point out thatis not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.
– jw013
Jul 9 at 18:59
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
add a comment |
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
Note that-t
is a GNU extension and so may not be available on other types of UNIX derivatives.
– Kevin
Jul 8 at 18:22
When you say "Double quotes prevents word splitting." I presume you are referring to""
, in which case I want to point out thatis not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.
– jw013
Jul 9 at 18:59
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
Thanks for concisely answering this persons question. Rather than simply dumping a solution, maybe you could explain how/what/why. Instead of being useful to one person, one time, it can be useful to everyone, all the time. Same question has been asked & answered countless times over the last 40-50 years. Problem is, it's never explained well. Teach a man to fish.. In the meantime: gnu.org/software/findutils/manual/html_node/find_html/… and as is often the case Wikipedia's more useful than the official docs: en.wikipedia.org/wiki/Find_(Unix)
– tjt263
Jul 8 at 17:22
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
See updated answer.
– Prvt_Yadv
Jul 8 at 17:48
Note that
-t
is a GNU extension and so may not be available on other types of UNIX derivatives.– Kevin
Jul 8 at 18:22
Note that
-t
is a GNU extension and so may not be available on other types of UNIX derivatives.– Kevin
Jul 8 at 18:22
When you say "Double quotes prevents word splitting." I presume you are referring to
""
, in which case I want to point out that
is not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.– jw013
Jul 9 at 18:59
When you say "Double quotes prevents word splitting." I presume you are referring to
""
, in which case I want to point out that
is not expanded by the shell and does not need to be quoted. The shell passes
to find, and find sees
and replaces it with pathnames. Find exec does not use the shell parser and does not do any word-splitting of its own. Quoting it does not do any harm, it is just that the justification given is a bit inaccurate.– jw013
Jul 9 at 18:59
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
@jw013 thanks .
– Prvt_Yadv
Jul 10 at 6:49
add a comment |
Your command,
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
Pipes the list of all the files TO all the files!
find . -maxdepth 1 -type f -name `*_a1ac*.jpg` -print0 |
xargs -0 -r mv -t "/home/ubuntu/ntest"
will do the trick.
1
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
add a comment |
Your command,
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
Pipes the list of all the files TO all the files!
find . -maxdepth 1 -type f -name `*_a1ac*.jpg` -print0 |
xargs -0 -r mv -t "/home/ubuntu/ntest"
will do the trick.
1
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
add a comment |
Your command,
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
Pipes the list of all the files TO all the files!
find . -maxdepth 1 -type f -name `*_a1ac*.jpg` -print0 |
xargs -0 -r mv -t "/home/ubuntu/ntest"
will do the trick.
Your command,
find . -maxdepth 1 -type f | ??????????_a1ac*.jpg |xargs mv -t "/home/ubuntu/ntest"
Pipes the list of all the files TO all the files!
find . -maxdepth 1 -type f -name `*_a1ac*.jpg` -print0 |
xargs -0 -r mv -t "/home/ubuntu/ntest"
will do the trick.
answered Jul 6 at 13:49
waltinatorwaltinator
9085 silver badges10 bronze badges
9085 silver badges10 bronze badges
1
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
add a comment |
1
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
1
1
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
many thanks...your solution worked too...thank you for letting me know where I went wrong
– Apricot
Jul 6 at 14:13
add a comment |
You're very close. You should use the -name
option to find
. And remember to quote the pattern.
So
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' |xargs mv -t "/home/ubuntu/ntest"
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
1
you should add a-print0
as the last argument to the find (instead of the default: -print), and add a-0
as the first option to xargs (ie:xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)
– Olivier Dulac
Jul 8 at 13:10
add a comment |
You're very close. You should use the -name
option to find
. And remember to quote the pattern.
So
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' |xargs mv -t "/home/ubuntu/ntest"
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
1
you should add a-print0
as the last argument to the find (instead of the default: -print), and add a-0
as the first option to xargs (ie:xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)
– Olivier Dulac
Jul 8 at 13:10
add a comment |
You're very close. You should use the -name
option to find
. And remember to quote the pattern.
So
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' |xargs mv -t "/home/ubuntu/ntest"
You're very close. You should use the -name
option to find
. And remember to quote the pattern.
So
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' |xargs mv -t "/home/ubuntu/ntest"
answered Jul 6 at 13:45
Stephen HarrisStephen Harris
28.7k3 gold badges57 silver badges85 bronze badges
28.7k3 gold badges57 silver badges85 bronze badges
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
1
you should add a-print0
as the last argument to the find (instead of the default: -print), and add a-0
as the first option to xargs (ie:xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)
– Olivier Dulac
Jul 8 at 13:10
add a comment |
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
1
you should add a-print0
as the last argument to the find (instead of the default: -print), and add a-0
as the first option to xargs (ie:xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)
– Olivier Dulac
Jul 8 at 13:10
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
Many thanks...your solution worked too....additional thanks for letting me know i was close to the solution....its a motivator for a novice like me
– Apricot
Jul 6 at 14:12
1
1
you should add a
-print0
as the last argument to the find (instead of the default: -print), and add a -0
as the first option to xargs (ie: xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled. find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)– Olivier Dulac
Jul 8 at 13:10
you should add a
-print0
as the last argument to the find (instead of the default: -print), and add a -0
as the first option to xargs (ie: xargs -0 mv -t "/home/ubuntu/ntest"
). that way, all kind of weird filenames (with spaces in it, with "newline" in it, etc) can be handled. find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' -print0 |xargs -0 mv -t "/home/ubuntu/ntest"
(works only with GNU-like find, though)– Olivier Dulac
Jul 8 at 13:10
add a comment |
Not as "good" as the find
solutions, but another valid solution is to make the mv
commands more granular.
This does 4096 moves, with a fewer number of files moved per mv
operation.
FILEPAT=a1ac
for i in $(seq $((0x000)) $((0xfff)));
do
H=$(printf '%xn' $i)
mv 1559704165_$FILEPAT$H*.jpg /home/ubuntu/ntest
done
This is a clever hack for those withoutfind
(for whatever reason).
– forest
Jul 8 at 7:44
add a comment |
Not as "good" as the find
solutions, but another valid solution is to make the mv
commands more granular.
This does 4096 moves, with a fewer number of files moved per mv
operation.
FILEPAT=a1ac
for i in $(seq $((0x000)) $((0xfff)));
do
H=$(printf '%xn' $i)
mv 1559704165_$FILEPAT$H*.jpg /home/ubuntu/ntest
done
This is a clever hack for those withoutfind
(for whatever reason).
– forest
Jul 8 at 7:44
add a comment |
Not as "good" as the find
solutions, but another valid solution is to make the mv
commands more granular.
This does 4096 moves, with a fewer number of files moved per mv
operation.
FILEPAT=a1ac
for i in $(seq $((0x000)) $((0xfff)));
do
H=$(printf '%xn' $i)
mv 1559704165_$FILEPAT$H*.jpg /home/ubuntu/ntest
done
Not as "good" as the find
solutions, but another valid solution is to make the mv
commands more granular.
This does 4096 moves, with a fewer number of files moved per mv
operation.
FILEPAT=a1ac
for i in $(seq $((0x000)) $((0xfff)));
do
H=$(printf '%xn' $i)
mv 1559704165_$FILEPAT$H*.jpg /home/ubuntu/ntest
done
answered Jul 8 at 0:28
RonJohnRonJohn
5834 silver badges16 bronze badges
5834 silver badges16 bronze badges
This is a clever hack for those withoutfind
(for whatever reason).
– forest
Jul 8 at 7:44
add a comment |
This is a clever hack for those withoutfind
(for whatever reason).
– forest
Jul 8 at 7:44
This is a clever hack for those without
find
(for whatever reason).– forest
Jul 8 at 7:44
This is a clever hack for those without
find
(for whatever reason).– forest
Jul 8 at 7:44
add a comment |
If you want to move files on the same host system, which I guess you are doing with your mv
, rsync
could be a faster option:
rsync -av --inplace -W /source/??????????_a1ac*.jpg /home/ubuntu/ntest/
--inplace
and -W
are set to speed up the process.
Should this yield another argument list too long error then you could feed lists to rsync
Make the list with find, for example
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and give it to rsync
rsync -av --inplace -W --files-from=/tmp/my_image_list.txt /path/to/files /home/ubuntu/ntest/
The source here is /path/to/files
, because rsync
will treat the list you give it as relative to your source.
The point being: rsync
is faster than mv
, if the files are not on the same filesystem.
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with--files-from=/tmp/my_image_list.txt
. The point being thatrsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.
– Robert Riedl
Jul 8 at 13:46
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
add a comment |
If you want to move files on the same host system, which I guess you are doing with your mv
, rsync
could be a faster option:
rsync -av --inplace -W /source/??????????_a1ac*.jpg /home/ubuntu/ntest/
--inplace
and -W
are set to speed up the process.
Should this yield another argument list too long error then you could feed lists to rsync
Make the list with find, for example
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and give it to rsync
rsync -av --inplace -W --files-from=/tmp/my_image_list.txt /path/to/files /home/ubuntu/ntest/
The source here is /path/to/files
, because rsync
will treat the list you give it as relative to your source.
The point being: rsync
is faster than mv
, if the files are not on the same filesystem.
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with--files-from=/tmp/my_image_list.txt
. The point being thatrsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.
– Robert Riedl
Jul 8 at 13:46
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
add a comment |
If you want to move files on the same host system, which I guess you are doing with your mv
, rsync
could be a faster option:
rsync -av --inplace -W /source/??????????_a1ac*.jpg /home/ubuntu/ntest/
--inplace
and -W
are set to speed up the process.
Should this yield another argument list too long error then you could feed lists to rsync
Make the list with find, for example
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and give it to rsync
rsync -av --inplace -W --files-from=/tmp/my_image_list.txt /path/to/files /home/ubuntu/ntest/
The source here is /path/to/files
, because rsync
will treat the list you give it as relative to your source.
The point being: rsync
is faster than mv
, if the files are not on the same filesystem.
If you want to move files on the same host system, which I guess you are doing with your mv
, rsync
could be a faster option:
rsync -av --inplace -W /source/??????????_a1ac*.jpg /home/ubuntu/ntest/
--inplace
and -W
are set to speed up the process.
Should this yield another argument list too long error then you could feed lists to rsync
Make the list with find, for example
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and give it to rsync
rsync -av --inplace -W --files-from=/tmp/my_image_list.txt /path/to/files /home/ubuntu/ntest/
The source here is /path/to/files
, because rsync
will treat the list you give it as relative to your source.
The point being: rsync
is faster than mv
, if the files are not on the same filesystem.
edited Jul 10 at 6:30
answered Jul 8 at 7:09
Robert RiedlRobert Riedl
1178 bronze badges
1178 bronze badges
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with--files-from=/tmp/my_image_list.txt
. The point being thatrsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.
– Robert Riedl
Jul 8 at 13:46
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
add a comment |
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with--files-from=/tmp/my_image_list.txt
. The point being thatrsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.
– Robert Riedl
Jul 8 at 13:46
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
This is likely to hit the same "argument list too long" error the OP mentioned
– Grump
Jul 8 at 13:24
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with --files-from=/tmp/my_image_list.txt
. The point being that rsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.– Robert Riedl
Jul 8 at 13:46
@Grump, to avoid this, OP could write the list of files to copy to a file, i.e.
find . -maxdepth 1 -type f -name '??????????_a1ac*.jpg' > /tmp/my_image_list.txt
and then pass it to rsync with --files-from=/tmp/my_image_list.txt
. The point being that rsync
is faster. Unless the files reside on the same filesystem, which OP has not indicated.– Robert Riedl
Jul 8 at 13:46
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@RobertRiedl: you should edit your answer and add this information. Comments can be impermanent.
– NickD
Jul 10 at 4:13
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
@NickD, I've updated my answer.
– Robert Riedl
Jul 10 at 6:31
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%2f528679%2fmoving-millions-of-files-to-a-different-directory-with-specfic-name-patterns%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
1
The bash says it all: it tries to execute that filename as it is the first on the line in the 2nd stage of the pipe (your 2nd stage pipe is:
| ??????????_a1ac*.jpg
: bash expands it to several filename, the first being1559704165_a1ac6f55fef555ee.jpg
, si you end up, in that 2nd pipe stage, trying to execute:1559704165_a1ac6f55fef555ee.jpg next_matching_filename 3rd_matching_filename ... nth_matching_filename
. I guess you tried instead to filter to that filename (see answers below for that)– Olivier Dulac
Jul 8 at 13:08