How to move multiple files at once to a specific destination directory?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I got a bunch of files in some directory (along with many other files) that I want to move.
Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.
But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?
command-line mv
add a comment |
I got a bunch of files in some directory (along with many other files) that I want to move.
Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.
But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?
command-line mv
add a comment |
I got a bunch of files in some directory (along with many other files) that I want to move.
Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.
But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?
command-line mv
I got a bunch of files in some directory (along with many other files) that I want to move.
Luckily, all the files I want to move contain a certain identifier in their names, so I can ls | grep IDENTIFIER to get the exact list of files to move.
But, how can I execute mv file /path/to/dest/folder/ at once, and not one by one (there's a lot of files to move)?
command-line mv
command-line mv
edited Jan 24 '18 at 9:47
muru
1
1
asked Nov 8 '12 at 13:13
gilad hochgilad hoch
780299
780299
add a comment |
add a comment |
12 Answers
12
active
oldest
votes
If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:
mv *IDENTIFIER* ~/YourPath/
* is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.
This will move all the files that contain the IDENTIFIER you specified.
add a comment |
You could use
mv -t DESTINATION file1 file2 file3
and
mv -t DESTINATION `ls|grep IDENTIFIER`
works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.
5
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
3
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
7
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.mv file1 file2 ... destination
– Sheljohn
Jul 23 '17 at 15:29
2
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
3
Why you shouldn't parse the output ofls.
– dessert
Dec 1 '17 at 9:42
add a comment |
You can use wildcards.
Example: To move all files having extension .doc
mv *.doc /path/to/dest/folder/
This will move all doc file under the current directory to the specific destination.
Edit
To answer the comment.
mv *.ext *.xml *.txt /path/to/dest/folder/
2
but the list of files to move is not determined by extension. some of the files are named:ABC-IDENTIFIER-XYZ.extand some justIDENTIFIER-XYZ.extall having different extensions, mostlyxmlorproperties.
– gilad hoch
Nov 8 '12 at 13:25
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
won't work since there are other.xmlfiles (for instance) i do'nt want to move.
– gilad hoch
Nov 8 '12 at 13:50
add a comment |
In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
first go to the directory that contains the files you want to move
mv file1.ext1 file2.ext2 file3.ext3.. /destination/
In case the files are scattered in different directories, you only need to specify the path for each file in the move command
add a comment |
I use tuomaz's technique, but slightly modified:
mv file1 file2 file3 -t DESTINATION
I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:
mv file1 DESTINATION
The man page formvdoesn't mention a-toption.
– Noumenon
Oct 24 '16 at 3:25
1
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
add a comment |
Use this command:
mv `ls|grep IDENTIFIER` /path/to/dest/folder
However, ls is not recommended for this kind of use. Use find command instead.
8
lsis not recommended for this kind of use. If you want to list files, especially with agrepbehind, usefind . -name *IDENTIFIER*.
– NorTicUs
Nov 8 '12 at 13:48
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
3
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
don't parsels
– Zanna
Sep 7 '17 at 15:15
add a comment |
If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:
ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/
The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
1
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
add a comment |
If the files are in the same dir you can use
mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/
(tested in Ubuntu 16.04)
1
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
1
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
add a comment |
find -type f -name "[range]" -exec mv {} target-directory ';'
this command will move file names with any pattern/range to target-directory.
eg.
find -type f -name "file[1-50000]" -exec mv {} target-directory ';'
it will move files with names like file1, file2 ... file50000 to target-directory.
add a comment |
You can use the output from ls to input into mv commnad
mv $(ls | grep IDENTIFIER) /path/to/dest/dir
The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.
1
don't parsels
– Zanna
Sep 7 '17 at 15:14
add a comment |
Using this command you can move multiple files.
mv SourceFilenames ~DestinationPath
add a comment |
Easiest way is like this
mv {file1,file2,file3} DESTINATION
or directory
mv {directory1,directory2,directory3} DESTINATION
or both files and directories
mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION
Hope this helps
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2faskubuntu.com%2fquestions%2f214560%2fhow-to-move-multiple-files-at-once-to-a-specific-destination-directory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
12 Answers
12
active
oldest
votes
12 Answers
12
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:
mv *IDENTIFIER* ~/YourPath/
* is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.
This will move all the files that contain the IDENTIFIER you specified.
add a comment |
If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:
mv *IDENTIFIER* ~/YourPath/
* is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.
This will move all the files that contain the IDENTIFIER you specified.
add a comment |
If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:
mv *IDENTIFIER* ~/YourPath/
* is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.
This will move all the files that contain the IDENTIFIER you specified.
If you want to move ABC-IDENTIFIER-XYZ.ext or IDENTIFIER-XYZ.xml, you can use:
mv *IDENTIFIER* ~/YourPath/
* is a wildcard for zero or more characters, this means zero or more characters, followed by IDENTIFIER, followed by zero or more characters.
This will move all the files that contain the IDENTIFIER you specified.
edited Nov 11 '12 at 17:07
answered Nov 8 '12 at 13:33
Evandro SilvaEvandro Silva
6,63852944
6,63852944
add a comment |
add a comment |
You could use
mv -t DESTINATION file1 file2 file3
and
mv -t DESTINATION `ls|grep IDENTIFIER`
works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.
5
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
3
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
7
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.mv file1 file2 ... destination
– Sheljohn
Jul 23 '17 at 15:29
2
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
3
Why you shouldn't parse the output ofls.
– dessert
Dec 1 '17 at 9:42
add a comment |
You could use
mv -t DESTINATION file1 file2 file3
and
mv -t DESTINATION `ls|grep IDENTIFIER`
works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.
5
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
3
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
7
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.mv file1 file2 ... destination
– Sheljohn
Jul 23 '17 at 15:29
2
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
3
Why you shouldn't parse the output ofls.
– dessert
Dec 1 '17 at 9:42
add a comment |
You could use
mv -t DESTINATION file1 file2 file3
and
mv -t DESTINATION `ls|grep IDENTIFIER`
works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.
You could use
mv -t DESTINATION file1 file2 file3
and
mv -t DESTINATION `ls|grep IDENTIFIER`
works, but I'm not sure if mv is invoked multiple times or not as grep will output a new line for each match.
edited Nov 14 '12 at 11:13
answered Nov 14 '12 at 11:07
tuomaztuomaz
1,865273
1,865273
5
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
3
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
7
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.mv file1 file2 ... destination
– Sheljohn
Jul 23 '17 at 15:29
2
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
3
Why you shouldn't parse the output ofls.
– dessert
Dec 1 '17 at 9:42
add a comment |
5
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
3
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
7
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.mv file1 file2 ... destination
– Sheljohn
Jul 23 '17 at 15:29
2
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
3
Why you shouldn't parse the output ofls.
– dessert
Dec 1 '17 at 9:42
5
5
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
works on linux, not sure if it will work on mac
– Alexander Mills
Dec 10 '16 at 20:25
3
3
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
works on mac and git bash via git for windwows.
– Brandt Solovij
Feb 23 '17 at 12:55
7
7
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.
mv file1 file2 ... destination– Sheljohn
Jul 23 '17 at 15:29
Does not work on Mac (10.11.16 El Capitan). But you can simply put the target folder at the back, i.e.
mv file1 file2 ... destination– Sheljohn
Jul 23 '17 at 15:29
2
2
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
-1 for second approach as it will fall for files including new lines
– αғsнιη
Sep 7 '17 at 15:33
3
3
Why you shouldn't parse the output of
ls.– dessert
Dec 1 '17 at 9:42
Why you shouldn't parse the output of
ls.– dessert
Dec 1 '17 at 9:42
add a comment |
You can use wildcards.
Example: To move all files having extension .doc
mv *.doc /path/to/dest/folder/
This will move all doc file under the current directory to the specific destination.
Edit
To answer the comment.
mv *.ext *.xml *.txt /path/to/dest/folder/
2
but the list of files to move is not determined by extension. some of the files are named:ABC-IDENTIFIER-XYZ.extand some justIDENTIFIER-XYZ.extall having different extensions, mostlyxmlorproperties.
– gilad hoch
Nov 8 '12 at 13:25
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
won't work since there are other.xmlfiles (for instance) i do'nt want to move.
– gilad hoch
Nov 8 '12 at 13:50
add a comment |
You can use wildcards.
Example: To move all files having extension .doc
mv *.doc /path/to/dest/folder/
This will move all doc file under the current directory to the specific destination.
Edit
To answer the comment.
mv *.ext *.xml *.txt /path/to/dest/folder/
2
but the list of files to move is not determined by extension. some of the files are named:ABC-IDENTIFIER-XYZ.extand some justIDENTIFIER-XYZ.extall having different extensions, mostlyxmlorproperties.
– gilad hoch
Nov 8 '12 at 13:25
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
won't work since there are other.xmlfiles (for instance) i do'nt want to move.
– gilad hoch
Nov 8 '12 at 13:50
add a comment |
You can use wildcards.
Example: To move all files having extension .doc
mv *.doc /path/to/dest/folder/
This will move all doc file under the current directory to the specific destination.
Edit
To answer the comment.
mv *.ext *.xml *.txt /path/to/dest/folder/
You can use wildcards.
Example: To move all files having extension .doc
mv *.doc /path/to/dest/folder/
This will move all doc file under the current directory to the specific destination.
Edit
To answer the comment.
mv *.ext *.xml *.txt /path/to/dest/folder/
edited Nov 8 '12 at 13:33
answered Nov 8 '12 at 13:21
AchuAchu
16.2k136499
16.2k136499
2
but the list of files to move is not determined by extension. some of the files are named:ABC-IDENTIFIER-XYZ.extand some justIDENTIFIER-XYZ.extall having different extensions, mostlyxmlorproperties.
– gilad hoch
Nov 8 '12 at 13:25
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
won't work since there are other.xmlfiles (for instance) i do'nt want to move.
– gilad hoch
Nov 8 '12 at 13:50
add a comment |
2
but the list of files to move is not determined by extension. some of the files are named:ABC-IDENTIFIER-XYZ.extand some justIDENTIFIER-XYZ.extall having different extensions, mostlyxmlorproperties.
– gilad hoch
Nov 8 '12 at 13:25
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
won't work since there are other.xmlfiles (for instance) i do'nt want to move.
– gilad hoch
Nov 8 '12 at 13:50
2
2
but the list of files to move is not determined by extension. some of the files are named:
ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.– gilad hoch
Nov 8 '12 at 13:25
but the list of files to move is not determined by extension. some of the files are named:
ABC-IDENTIFIER-XYZ.ext and some just IDENTIFIER-XYZ.ext all having different extensions, mostly xml or properties.– gilad hoch
Nov 8 '12 at 13:25
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@giladhoch How about the edited one?
– Achu
Nov 8 '12 at 13:36
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
@gliadhoch If you are so comfortable using grep, you can see my answer above/below.
– ignite
Nov 8 '12 at 13:47
won't work since there are other
.xml files (for instance) i do'nt want to move.– gilad hoch
Nov 8 '12 at 13:50
won't work since there are other
.xml files (for instance) i do'nt want to move.– gilad hoch
Nov 8 '12 at 13:50
add a comment |
In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
first go to the directory that contains the files you want to move
mv file1.ext1 file2.ext2 file3.ext3.. /destination/
In case the files are scattered in different directories, you only need to specify the path for each file in the move command
add a comment |
In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
first go to the directory that contains the files you want to move
mv file1.ext1 file2.ext2 file3.ext3.. /destination/
In case the files are scattered in different directories, you only need to specify the path for each file in the move command
add a comment |
In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
first go to the directory that contains the files you want to move
mv file1.ext1 file2.ext2 file3.ext3.. /destination/
In case the files are scattered in different directories, you only need to specify the path for each file in the move command
In case you want to move a set of irrelevant files (no common pattern in the names and types) you can do as Mr. Rajanand said:
first go to the directory that contains the files you want to move
mv file1.ext1 file2.ext2 file3.ext3.. /destination/
In case the files are scattered in different directories, you only need to specify the path for each file in the move command
answered Mar 26 '14 at 4:03
Ismail AL-taharwaIsmail AL-taharwa
30122
30122
add a comment |
add a comment |
I use tuomaz's technique, but slightly modified:
mv file1 file2 file3 -t DESTINATION
I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:
mv file1 DESTINATION
The man page formvdoesn't mention a-toption.
– Noumenon
Oct 24 '16 at 3:25
1
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
add a comment |
I use tuomaz's technique, but slightly modified:
mv file1 file2 file3 -t DESTINATION
I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:
mv file1 DESTINATION
The man page formvdoesn't mention a-toption.
– Noumenon
Oct 24 '16 at 3:25
1
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
add a comment |
I use tuomaz's technique, but slightly modified:
mv file1 file2 file3 -t DESTINATION
I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:
mv file1 DESTINATION
I use tuomaz's technique, but slightly modified:
mv file1 file2 file3 -t DESTINATION
I find this easier to remember and harder to screw up since it uses the same ordering as the vanilla mv operation:
mv file1 DESTINATION
answered Jan 20 '15 at 16:11
Blake FrederickBlake Frederick
20124
20124
The man page formvdoesn't mention a-toption.
– Noumenon
Oct 24 '16 at 3:25
1
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
add a comment |
The man page formvdoesn't mention a-toption.
– Noumenon
Oct 24 '16 at 3:25
1
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
The man page for
mv doesn't mention a -t option.– Noumenon
Oct 24 '16 at 3:25
The man page for
mv doesn't mention a -t option.– Noumenon
Oct 24 '16 at 3:25
1
1
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
linux.die.net/man/1/mv yes it does
– geoyws
Feb 20 '17 at 4:00
add a comment |
Use this command:
mv `ls|grep IDENTIFIER` /path/to/dest/folder
However, ls is not recommended for this kind of use. Use find command instead.
8
lsis not recommended for this kind of use. If you want to list files, especially with agrepbehind, usefind . -name *IDENTIFIER*.
– NorTicUs
Nov 8 '12 at 13:48
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
3
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
don't parsels
– Zanna
Sep 7 '17 at 15:15
add a comment |
Use this command:
mv `ls|grep IDENTIFIER` /path/to/dest/folder
However, ls is not recommended for this kind of use. Use find command instead.
8
lsis not recommended for this kind of use. If you want to list files, especially with agrepbehind, usefind . -name *IDENTIFIER*.
– NorTicUs
Nov 8 '12 at 13:48
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
3
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
don't parsels
– Zanna
Sep 7 '17 at 15:15
add a comment |
Use this command:
mv `ls|grep IDENTIFIER` /path/to/dest/folder
However, ls is not recommended for this kind of use. Use find command instead.
Use this command:
mv `ls|grep IDENTIFIER` /path/to/dest/folder
However, ls is not recommended for this kind of use. Use find command instead.
edited Nov 13 '12 at 18:18
answered Nov 8 '12 at 13:44
igniteignite
6,87232852
6,87232852
8
lsis not recommended for this kind of use. If you want to list files, especially with agrepbehind, usefind . -name *IDENTIFIER*.
– NorTicUs
Nov 8 '12 at 13:48
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
3
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
don't parsels
– Zanna
Sep 7 '17 at 15:15
add a comment |
8
lsis not recommended for this kind of use. If you want to list files, especially with agrepbehind, usefind . -name *IDENTIFIER*.
– NorTicUs
Nov 8 '12 at 13:48
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
3
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
don't parsels
– Zanna
Sep 7 '17 at 15:15
8
8
ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.– NorTicUs
Nov 8 '12 at 13:48
ls is not recommended for this kind of use. If you want to list files, especially with a grep behind, use find . -name *IDENTIFIER*.– NorTicUs
Nov 8 '12 at 13:48
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
This answer was just to demonstrate how you can use the output of previous command in mv. As ls|grep was mentioned in the question, I just copied it.
– ignite
Nov 8 '12 at 13:50
3
3
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
As stated by @NorTicUs, the use of ls is ill advised. Also, files with spaces could cause a problem.
– Paddy Landau
Nov 13 '12 at 14:27
don't parse
ls– Zanna
Sep 7 '17 at 15:15
don't parse
ls– Zanna
Sep 7 '17 at 15:15
add a comment |
If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:
ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/
The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
1
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
add a comment |
If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:
ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/
The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
1
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
add a comment |
If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:
ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/
The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.
If you have so many files to move you can actually have too many for the mv command (or other commands like rm). I suggest using xargs to move each file individually in a loop like fashion. One way to get around that is to do:
ls -1 | grep IDENTIFIER | xargs -i mv {} /path/to/dest/folder/
The ls -1 (minus one) ensures that there is only one filename on each line. If you have hidden aliases for the ls command you can have multiple filenames on a single line and inadvertently move a file you did not intend to move.
answered Nov 14 '12 at 10:05
AggieBillAggieBill
612
612
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
1
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
add a comment |
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
1
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
This is also useful when your IDENTIFIER is not easily turned into a wildcard, or you want to use grep with a more complex regex.
– AggieBill
Nov 14 '12 at 10:11
1
1
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
+1 for xargs. find is almost always better and safer than ls. find . IDENTIFIER -exec mv {} /path/to/dest/folder ; (untested code) The . is for the current working directory. The ; is to end the command to be executed. Depending on what you're doing, you might have to add a -maxdepth 1 to keep it from recursing into subdirectories.
– Joe
Nov 14 '12 at 23:33
add a comment |
If the files are in the same dir you can use
mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/
(tested in Ubuntu 16.04)
1
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
1
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
add a comment |
If the files are in the same dir you can use
mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/
(tested in Ubuntu 16.04)
1
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
1
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
add a comment |
If the files are in the same dir you can use
mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/
(tested in Ubuntu 16.04)
If the files are in the same dir you can use
mv /path/to/source/dir/{file1,file2,*.ext1,*.ext2} /path/to/destination/
(tested in Ubuntu 16.04)
edited Dec 1 '17 at 11:22
answered Dec 1 '17 at 9:19
SruliSruli
11614
11614
1
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
1
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
add a comment |
1
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
1
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
1
1
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
This doesn't really add something to the existing answers, don't you think?
– dessert
Dec 1 '17 at 9:46
1
1
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
just eliminates the need to specify full path to dir for each file
– Sruli
Dec 1 '17 at 11:22
add a comment |
find -type f -name "[range]" -exec mv {} target-directory ';'
this command will move file names with any pattern/range to target-directory.
eg.
find -type f -name "file[1-50000]" -exec mv {} target-directory ';'
it will move files with names like file1, file2 ... file50000 to target-directory.
add a comment |
find -type f -name "[range]" -exec mv {} target-directory ';'
this command will move file names with any pattern/range to target-directory.
eg.
find -type f -name "file[1-50000]" -exec mv {} target-directory ';'
it will move files with names like file1, file2 ... file50000 to target-directory.
add a comment |
find -type f -name "[range]" -exec mv {} target-directory ';'
this command will move file names with any pattern/range to target-directory.
eg.
find -type f -name "file[1-50000]" -exec mv {} target-directory ';'
it will move files with names like file1, file2 ... file50000 to target-directory.
find -type f -name "[range]" -exec mv {} target-directory ';'
this command will move file names with any pattern/range to target-directory.
eg.
find -type f -name "file[1-50000]" -exec mv {} target-directory ';'
it will move files with names like file1, file2 ... file50000 to target-directory.
edited Sep 7 '17 at 15:12
Zanna
51.5k13141244
51.5k13141244
answered Sep 7 '17 at 14:51
user734124user734124
311
311
add a comment |
add a comment |
You can use the output from ls to input into mv commnad
mv $(ls | grep IDENTIFIER) /path/to/dest/dir
The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.
1
don't parsels
– Zanna
Sep 7 '17 at 15:14
add a comment |
You can use the output from ls to input into mv commnad
mv $(ls | grep IDENTIFIER) /path/to/dest/dir
The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.
1
don't parsels
– Zanna
Sep 7 '17 at 15:14
add a comment |
You can use the output from ls to input into mv commnad
mv $(ls | grep IDENTIFIER) /path/to/dest/dir
The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.
You can use the output from ls to input into mv commnad
mv $(ls | grep IDENTIFIER) /path/to/dest/dir
The command between $() returns a list of the file names matching your search, and that can be provided as a parameter for the mv command.
answered Nov 13 '12 at 19:38
Fuad SaudFuad Saud
1563
1563
1
don't parsels
– Zanna
Sep 7 '17 at 15:14
add a comment |
1
don't parsels
– Zanna
Sep 7 '17 at 15:14
1
1
don't parse
ls– Zanna
Sep 7 '17 at 15:14
don't parse
ls– Zanna
Sep 7 '17 at 15:14
add a comment |
Using this command you can move multiple files.
mv SourceFilenames ~DestinationPath
add a comment |
Using this command you can move multiple files.
mv SourceFilenames ~DestinationPath
add a comment |
Using this command you can move multiple files.
mv SourceFilenames ~DestinationPath
Using this command you can move multiple files.
mv SourceFilenames ~DestinationPath
answered Nov 14 '12 at 10:13
RajanandRajanand
112
112
add a comment |
add a comment |
Easiest way is like this
mv {file1,file2,file3} DESTINATION
or directory
mv {directory1,directory2,directory3} DESTINATION
or both files and directories
mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION
Hope this helps
add a comment |
Easiest way is like this
mv {file1,file2,file3} DESTINATION
or directory
mv {directory1,directory2,directory3} DESTINATION
or both files and directories
mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION
Hope this helps
add a comment |
Easiest way is like this
mv {file1,file2,file3} DESTINATION
or directory
mv {directory1,directory2,directory3} DESTINATION
or both files and directories
mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION
Hope this helps
Easiest way is like this
mv {file1,file2,file3} DESTINATION
or directory
mv {directory1,directory2,directory3} DESTINATION
or both files and directories
mv {file1,file2,file3,directory1,directory2,directory3} DESTINATION
Hope this helps
answered Nov 6 '18 at 1:26
SabrinaSabrina
22618
22618
add a comment |
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- 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%2faskubuntu.com%2fquestions%2f214560%2fhow-to-move-multiple-files-at-once-to-a-specific-destination-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