mv: cannot stat 'filename_1_2_3': No such file or directory
Clash Royale CLAN TAG#URR8PPP
I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.
I used following command with backticks:
mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`
So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )
Is there any solution to do this with the current command? And what does this error mean exactly?
linux command-line terminal mv
add a comment |
I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.
I used following command with backticks:
mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`
So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )
Is there any solution to do this with the current command? And what does this error mean exactly?
linux command-line terminal mv
add a comment |
I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.
I used following command with backticks:
mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`
So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )
Is there any solution to do this with the current command? And what does this error mean exactly?
linux command-line terminal mv
I wanted to move large amount of files from many directories which are under the parent directory in who I'm positioned.
I used following command with backticks:
mv -t directory1/directory2/directory3/ `ls -R | grep _2_3`
So I wanted to move the source of command in backticks to the destination directory which is 'directory3' which are find Recursively under my current directory ( parent one )
Is there any solution to do this with the current command? And what does this error mean exactly?
linux command-line terminal mv
linux command-line terminal mv
edited Jan 24 at 20:30
Rui F Ribeiro
40.1k1479136
40.1k1479136
asked Jan 24 at 20:05
Miloš StojanovićMiloš Stojanović
155
155
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You will notice that ls -R
outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3
in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R
(on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.
Instead, assuming you'd want to move files whose filenames end in _2_3
to a directory /directory1/directory2/directory3
(and that this directory is not a subdirectory of the current directory), then
find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +
would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3
anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3
with as many of these pathnames as possible in batches.
In the bash
shell, you could possibly also do
shopt -s globstar
mv -t /directory1/directory2/directory3 **/*_2_3
unless the pattern expands to many thousands of names. The globstar
shell option in bash
enables the **
globbing pattern. It works like *
but will match across /
in pathnames. It would therefore find all names matching *_2_3
anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R
approach do).
In the zsh
shell, you could be more precise with the matching:
mv -t /directory1/directory2/directory3 **/*_2_3(.)
The (.)
modifies the behaviour of the preceding pattern to only match regular files. The **
pattern is enabled by default in zsh
.
If you wish to find files whose names contain _2_3
, then simply change the *_2_3
bit of the filename pattern in the above commands to *_2_3*
.
add a comment |
The important part of the message is: No such file or directory
. ls -R
doesn't include the filepath. So mv
have just the filename but cannot find it, because the path to it is missing.
Do this instead:
$ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +
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%2f496541%2fmv-cannot-stat-filename-1-2-3-no-such-file-or-directory%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 will notice that ls -R
outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3
in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R
(on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.
Instead, assuming you'd want to move files whose filenames end in _2_3
to a directory /directory1/directory2/directory3
(and that this directory is not a subdirectory of the current directory), then
find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +
would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3
anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3
with as many of these pathnames as possible in batches.
In the bash
shell, you could possibly also do
shopt -s globstar
mv -t /directory1/directory2/directory3 **/*_2_3
unless the pattern expands to many thousands of names. The globstar
shell option in bash
enables the **
globbing pattern. It works like *
but will match across /
in pathnames. It would therefore find all names matching *_2_3
anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R
approach do).
In the zsh
shell, you could be more precise with the matching:
mv -t /directory1/directory2/directory3 **/*_2_3(.)
The (.)
modifies the behaviour of the preceding pattern to only match regular files. The **
pattern is enabled by default in zsh
.
If you wish to find files whose names contain _2_3
, then simply change the *_2_3
bit of the filename pattern in the above commands to *_2_3*
.
add a comment |
You will notice that ls -R
outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3
in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R
(on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.
Instead, assuming you'd want to move files whose filenames end in _2_3
to a directory /directory1/directory2/directory3
(and that this directory is not a subdirectory of the current directory), then
find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +
would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3
anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3
with as many of these pathnames as possible in batches.
In the bash
shell, you could possibly also do
shopt -s globstar
mv -t /directory1/directory2/directory3 **/*_2_3
unless the pattern expands to many thousands of names. The globstar
shell option in bash
enables the **
globbing pattern. It works like *
but will match across /
in pathnames. It would therefore find all names matching *_2_3
anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R
approach do).
In the zsh
shell, you could be more precise with the matching:
mv -t /directory1/directory2/directory3 **/*_2_3(.)
The (.)
modifies the behaviour of the preceding pattern to only match regular files. The **
pattern is enabled by default in zsh
.
If you wish to find files whose names contain _2_3
, then simply change the *_2_3
bit of the filename pattern in the above commands to *_2_3*
.
add a comment |
You will notice that ls -R
outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3
in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R
(on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.
Instead, assuming you'd want to move files whose filenames end in _2_3
to a directory /directory1/directory2/directory3
(and that this directory is not a subdirectory of the current directory), then
find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +
would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3
anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3
with as many of these pathnames as possible in batches.
In the bash
shell, you could possibly also do
shopt -s globstar
mv -t /directory1/directory2/directory3 **/*_2_3
unless the pattern expands to many thousands of names. The globstar
shell option in bash
enables the **
globbing pattern. It works like *
but will match across /
in pathnames. It would therefore find all names matching *_2_3
anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R
approach do).
In the zsh
shell, you could be more precise with the matching:
mv -t /directory1/directory2/directory3 **/*_2_3(.)
The (.)
modifies the behaviour of the preceding pattern to only match regular files. The **
pattern is enabled by default in zsh
.
If you wish to find files whose names contain _2_3
, then simply change the *_2_3
bit of the filename pattern in the above commands to *_2_3*
.
You will notice that ls -R
outputs filenames. That is, it does not output pathnames. Therefore, if a file that contains the string _2_3
in its name is found in one of your subdirectories, there is no information about where that file is found in the output of ls -R
(on the same line as the filename). This makes your command fail (the filename is not found in the current directory). It would also fail for any file that contains a space, tab or newline in its name, and would potentially also produce strange results if any filename contained filename globbing characters.
Instead, assuming you'd want to move files whose filenames end in _2_3
to a directory /directory1/directory2/directory3
(and that this directory is not a subdirectory of the current directory), then
find . -type f -name '*_2_3' -exec mv -t /directory1/directory2/directory3 +
would do that. This would find the pathnames of all regular files (not directories or named pipes, or symbolic links etc.) whose names end with _2_3
anywhere in or under the current directory, and would execute mv -t /directory1/directory2/directory3
with as many of these pathnames as possible in batches.
In the bash
shell, you could possibly also do
shopt -s globstar
mv -t /directory1/directory2/directory3 **/*_2_3
unless the pattern expands to many thousands of names. The globstar
shell option in bash
enables the **
globbing pattern. It works like *
but will match across /
in pathnames. It would therefore find all names matching *_2_3
anywhere in or below the current directory. Note that this command does not care what type of name is matched, and might match directory names too, for example (but so would your ls -R
approach do).
In the zsh
shell, you could be more precise with the matching:
mv -t /directory1/directory2/directory3 **/*_2_3(.)
The (.)
modifies the behaviour of the preceding pattern to only match regular files. The **
pattern is enabled by default in zsh
.
If you wish to find files whose names contain _2_3
, then simply change the *_2_3
bit of the filename pattern in the above commands to *_2_3*
.
edited Jan 24 at 20:51
answered Jan 24 at 20:17
KusalanandaKusalananda
129k16245404
129k16245404
add a comment |
add a comment |
The important part of the message is: No such file or directory
. ls -R
doesn't include the filepath. So mv
have just the filename but cannot find it, because the path to it is missing.
Do this instead:
$ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +
add a comment |
The important part of the message is: No such file or directory
. ls -R
doesn't include the filepath. So mv
have just the filename but cannot find it, because the path to it is missing.
Do this instead:
$ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +
add a comment |
The important part of the message is: No such file or directory
. ls -R
doesn't include the filepath. So mv
have just the filename but cannot find it, because the path to it is missing.
Do this instead:
$ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +
The important part of the message is: No such file or directory
. ls -R
doesn't include the filepath. So mv
have just the filename but cannot find it, because the path to it is missing.
Do this instead:
$ find ./ -name '*_2_3*' -exec mv -t directory1/directory2/directory3/ +
answered Jan 24 at 20:19
finswimmerfinswimmer
52416
52416
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%2f496541%2fmv-cannot-stat-filename-1-2-3-no-such-file-or-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