Why doesn’t `mv file /dir` move the file to a subdirectory of the current working directory?

Clash Royale CLAN TAG#URR8PPP
I was in my /etc directory and typed the command
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
I thought that would move the file into the directory openvpn which is a subdirectory of the /etc directory. However, that doesn't seem to be what happened. All that I can confirm is that the command got executed.
command-line directory paths mv
add a comment |
I was in my /etc directory and typed the command
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
I thought that would move the file into the directory openvpn which is a subdirectory of the /etc directory. However, that doesn't seem to be what happened. All that I can confirm is that the command got executed.
command-line directory paths mv
add a comment |
I was in my /etc directory and typed the command
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
I thought that would move the file into the directory openvpn which is a subdirectory of the /etc directory. However, that doesn't seem to be what happened. All that I can confirm is that the command got executed.
command-line directory paths mv
I was in my /etc directory and typed the command
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
I thought that would move the file into the directory openvpn which is a subdirectory of the /etc directory. However, that doesn't seem to be what happened. All that I can confirm is that the command got executed.
command-line directory paths mv
command-line directory paths mv
edited Feb 12 at 10:48
dessert
24.2k670104
24.2k670104
asked Feb 12 at 10:24
whitelightningwhitelightning
10114
10114
add a comment |
add a comment |
5 Answers
5
active
oldest
votes
Provided a directory with this name doesn’t exist, you renamed the file to openvpn located in your root directory /. To revert this, run:
sudo mv /openvpn /etc/MyFile.conf
If the directory did exist you moved the file inside it, then the reversion is:
sudo mv /openvpn/MyFile.conf /etc/
To move it to an existing subdirectory of the current directory you can run any one of these – those use relative paths:
mv MyFile.conf openvpn
mv MyFile.conf openvpn/
mv MyFile.conf ./openvpn
mv MyFile.conf ./openvpn/
. is a link to the current directory, so ./ at the beginning of a path means “in this directory”. The slash at the end means that openvpn is a directory and you want to move the file inside it. If you don’t provide it, the file will be moved into it if a directory with this name exists, else the file will be renamed to openvpn. With a / at the end, mv will warn you if the directory is missing and not rename, so that’s the secure way if you don’t want to rename.
If your path begins with / on the other hand it’s an absolute path regardless of the current working directory, it’s always relative to the root directory /. Using absolute paths for both file and destination your command would look like this:
mv /etc/MyFile.conf /etc/openvpn
mv /etc/MyFile.conf /etc/openvpn/
Further reading
- What is a full path name?
- Absolute / canonical / relative paths on Unix & Linux
2
If you don't know whether or not the directory existed, try thesudo mv /openvpn/MyFile.conf /etc/command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just dosudo mv /openvpn /etc/MyFile.conf.
– flarn2006
Feb 13 at 19:17
add a comment |
You need to use
me@mylaptop:/etc$ sudo mv MyFile.conf openvpn/
to move the MyFile.conf file into the openvpn sub-directory of /etc/.
On the other hand
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
would move the file to the / directory as openvpn (i.e. rename as openvpn) instead (assuming /openvpn directory doesn't exist).
3
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
add a comment |
When you move a file, you tell the OS the directory into which you want to put it, or the new path you want to give it.
You told the OS "/openvpn". So it's going to do exactly that - check if /openvpn exists (meaning an object called "openvpn" located in the root directory) and is a directory, and if so move your file into it, or else if /openvpn is a file or doesn't exist, rename and move your file so it's now accessible as /openvpn.
What you wanted it to do was move it to within a directory "openvpn", which is to be found in your current directory, not one that's in the file system root directory (which is what the leading "/" signifies). So you had to point to that dir in the move command, not to absolute path "/openvpn". Any of these will work:
mv MyFile.conf openvpn- look in my current dir for this "openvpn"mv MyFile.conf /etc/openvpn- look for absolute path /etc/openvpnmv MyFile.conf openvpn/- look in my current dir, for a dir called openvpnmv MyFile.conf ./openvpn- makes the "current dir" even more obvious
Short version - you probably used "/" to mean "my current directory", therefore "/openvpn" to mean "openvpn which is in my current directory". But a leading "/" only ever means "the root directory", so "/openvpn" meant "openvpn in the root directory". What you needed was simply to use "openvpn" or "openvpn/", meaning "openvpn in my current directory".
1
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
add a comment |
Any path that starts with / is an absolute path, not relative.
If all paths were always relative to the current directory, how would you cd /etc in the first place? You'd have to cd ../../../../../etc and hope that was enough levels of .., or just keep doing cd .. until you got to the root directory.
Or you'd need some other syntax to express absolute paths. But Unix decided on / meaning absolute, anything else being relative to the process's current working directory. So mv MyFile.txt openvpn would work.
And no, it wouldn't work well to infer absolute vs. relative from files existing or not. We wouldn't want mkdir system calls to treat paths differently from chdir or rename system calls, and making the mv program do it just leaves room for inconsistency between mv and some other program that takes an output filename.
mv is already special because when the rename() destination is a directory, it appends the source filename to that destination directory and tries again. But notice that one simple implementation strategy relies of the first rename() system call failing with EEXIST or EISDIR. So we have to know whether a path is relative or absolute before checking the filesystem.
(Early Unix ran on slow computers, where extra checks if a directory existed could mean extra I/O if it wasn't cached, or more pressure on directory caching. But I think sanity / correctness arguments are sufficient to explain why your first guess wasn't a plausible way for the system to work, without resorting to historical efficiency arguments.)
add a comment |
To complete the other answers :
mv file.txt /location
is the same as, for Windows
mv file.txt c:location
The filesystem in linux is thought in accordance to the filesystem hierarchy standard, or FHS for short. it helps you knowing where should a file be placed depending on its nature and content.
The first folder (equivalent to c: in Windows) is /.
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%2f1117625%2fwhy-doesn-t-mv-file-dir-move-the-file-to-a-subdirectory-of-the-current-workin%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
Provided a directory with this name doesn’t exist, you renamed the file to openvpn located in your root directory /. To revert this, run:
sudo mv /openvpn /etc/MyFile.conf
If the directory did exist you moved the file inside it, then the reversion is:
sudo mv /openvpn/MyFile.conf /etc/
To move it to an existing subdirectory of the current directory you can run any one of these – those use relative paths:
mv MyFile.conf openvpn
mv MyFile.conf openvpn/
mv MyFile.conf ./openvpn
mv MyFile.conf ./openvpn/
. is a link to the current directory, so ./ at the beginning of a path means “in this directory”. The slash at the end means that openvpn is a directory and you want to move the file inside it. If you don’t provide it, the file will be moved into it if a directory with this name exists, else the file will be renamed to openvpn. With a / at the end, mv will warn you if the directory is missing and not rename, so that’s the secure way if you don’t want to rename.
If your path begins with / on the other hand it’s an absolute path regardless of the current working directory, it’s always relative to the root directory /. Using absolute paths for both file and destination your command would look like this:
mv /etc/MyFile.conf /etc/openvpn
mv /etc/MyFile.conf /etc/openvpn/
Further reading
- What is a full path name?
- Absolute / canonical / relative paths on Unix & Linux
2
If you don't know whether or not the directory existed, try thesudo mv /openvpn/MyFile.conf /etc/command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just dosudo mv /openvpn /etc/MyFile.conf.
– flarn2006
Feb 13 at 19:17
add a comment |
Provided a directory with this name doesn’t exist, you renamed the file to openvpn located in your root directory /. To revert this, run:
sudo mv /openvpn /etc/MyFile.conf
If the directory did exist you moved the file inside it, then the reversion is:
sudo mv /openvpn/MyFile.conf /etc/
To move it to an existing subdirectory of the current directory you can run any one of these – those use relative paths:
mv MyFile.conf openvpn
mv MyFile.conf openvpn/
mv MyFile.conf ./openvpn
mv MyFile.conf ./openvpn/
. is a link to the current directory, so ./ at the beginning of a path means “in this directory”. The slash at the end means that openvpn is a directory and you want to move the file inside it. If you don’t provide it, the file will be moved into it if a directory with this name exists, else the file will be renamed to openvpn. With a / at the end, mv will warn you if the directory is missing and not rename, so that’s the secure way if you don’t want to rename.
If your path begins with / on the other hand it’s an absolute path regardless of the current working directory, it’s always relative to the root directory /. Using absolute paths for both file and destination your command would look like this:
mv /etc/MyFile.conf /etc/openvpn
mv /etc/MyFile.conf /etc/openvpn/
Further reading
- What is a full path name?
- Absolute / canonical / relative paths on Unix & Linux
2
If you don't know whether or not the directory existed, try thesudo mv /openvpn/MyFile.conf /etc/command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just dosudo mv /openvpn /etc/MyFile.conf.
– flarn2006
Feb 13 at 19:17
add a comment |
Provided a directory with this name doesn’t exist, you renamed the file to openvpn located in your root directory /. To revert this, run:
sudo mv /openvpn /etc/MyFile.conf
If the directory did exist you moved the file inside it, then the reversion is:
sudo mv /openvpn/MyFile.conf /etc/
To move it to an existing subdirectory of the current directory you can run any one of these – those use relative paths:
mv MyFile.conf openvpn
mv MyFile.conf openvpn/
mv MyFile.conf ./openvpn
mv MyFile.conf ./openvpn/
. is a link to the current directory, so ./ at the beginning of a path means “in this directory”. The slash at the end means that openvpn is a directory and you want to move the file inside it. If you don’t provide it, the file will be moved into it if a directory with this name exists, else the file will be renamed to openvpn. With a / at the end, mv will warn you if the directory is missing and not rename, so that’s the secure way if you don’t want to rename.
If your path begins with / on the other hand it’s an absolute path regardless of the current working directory, it’s always relative to the root directory /. Using absolute paths for both file and destination your command would look like this:
mv /etc/MyFile.conf /etc/openvpn
mv /etc/MyFile.conf /etc/openvpn/
Further reading
- What is a full path name?
- Absolute / canonical / relative paths on Unix & Linux
Provided a directory with this name doesn’t exist, you renamed the file to openvpn located in your root directory /. To revert this, run:
sudo mv /openvpn /etc/MyFile.conf
If the directory did exist you moved the file inside it, then the reversion is:
sudo mv /openvpn/MyFile.conf /etc/
To move it to an existing subdirectory of the current directory you can run any one of these – those use relative paths:
mv MyFile.conf openvpn
mv MyFile.conf openvpn/
mv MyFile.conf ./openvpn
mv MyFile.conf ./openvpn/
. is a link to the current directory, so ./ at the beginning of a path means “in this directory”. The slash at the end means that openvpn is a directory and you want to move the file inside it. If you don’t provide it, the file will be moved into it if a directory with this name exists, else the file will be renamed to openvpn. With a / at the end, mv will warn you if the directory is missing and not rename, so that’s the secure way if you don’t want to rename.
If your path begins with / on the other hand it’s an absolute path regardless of the current working directory, it’s always relative to the root directory /. Using absolute paths for both file and destination your command would look like this:
mv /etc/MyFile.conf /etc/openvpn
mv /etc/MyFile.conf /etc/openvpn/
Further reading
- What is a full path name?
- Absolute / canonical / relative paths on Unix & Linux
edited Feb 19 at 10:31
answered Feb 12 at 10:34
dessertdessert
24.2k670104
24.2k670104
2
If you don't know whether or not the directory existed, try thesudo mv /openvpn/MyFile.conf /etc/command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just dosudo mv /openvpn /etc/MyFile.conf.
– flarn2006
Feb 13 at 19:17
add a comment |
2
If you don't know whether or not the directory existed, try thesudo mv /openvpn/MyFile.conf /etc/command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just dosudo mv /openvpn /etc/MyFile.conf.
– flarn2006
Feb 13 at 19:17
2
2
If you don't know whether or not the directory existed, try the
sudo mv /openvpn/MyFile.conf /etc/ command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just do sudo mv /openvpn /etc/MyFile.conf.– flarn2006
Feb 13 at 19:17
If you don't know whether or not the directory existed, try the
sudo mv /openvpn/MyFile.conf /etc/ command first. In the likely scenario the directory didn't exist, it'll just give you an error (probably "Not a directory") and not touch the filesystem. Then, you can just do sudo mv /openvpn /etc/MyFile.conf.– flarn2006
Feb 13 at 19:17
add a comment |
You need to use
me@mylaptop:/etc$ sudo mv MyFile.conf openvpn/
to move the MyFile.conf file into the openvpn sub-directory of /etc/.
On the other hand
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
would move the file to the / directory as openvpn (i.e. rename as openvpn) instead (assuming /openvpn directory doesn't exist).
3
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
add a comment |
You need to use
me@mylaptop:/etc$ sudo mv MyFile.conf openvpn/
to move the MyFile.conf file into the openvpn sub-directory of /etc/.
On the other hand
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
would move the file to the / directory as openvpn (i.e. rename as openvpn) instead (assuming /openvpn directory doesn't exist).
3
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
add a comment |
You need to use
me@mylaptop:/etc$ sudo mv MyFile.conf openvpn/
to move the MyFile.conf file into the openvpn sub-directory of /etc/.
On the other hand
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
would move the file to the / directory as openvpn (i.e. rename as openvpn) instead (assuming /openvpn directory doesn't exist).
You need to use
me@mylaptop:/etc$ sudo mv MyFile.conf openvpn/
to move the MyFile.conf file into the openvpn sub-directory of /etc/.
On the other hand
me@mylaptop:/etc$ sudo mv MyFile.conf /openvpn
would move the file to the / directory as openvpn (i.e. rename as openvpn) instead (assuming /openvpn directory doesn't exist).
edited Feb 12 at 10:57
answered Feb 12 at 10:30
pomskypomsky
31.8k1197128
31.8k1197128
3
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
add a comment |
3
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
3
3
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
Also, the slash at the end of the first command is optional. But I guess it's a good habit to get into, as it'll make the command fail if it isn't a directory, rather than creating a confusing situation like OP described (or worse, overwriting an important file.)
– flarn2006
Feb 13 at 19:20
add a comment |
When you move a file, you tell the OS the directory into which you want to put it, or the new path you want to give it.
You told the OS "/openvpn". So it's going to do exactly that - check if /openvpn exists (meaning an object called "openvpn" located in the root directory) and is a directory, and if so move your file into it, or else if /openvpn is a file or doesn't exist, rename and move your file so it's now accessible as /openvpn.
What you wanted it to do was move it to within a directory "openvpn", which is to be found in your current directory, not one that's in the file system root directory (which is what the leading "/" signifies). So you had to point to that dir in the move command, not to absolute path "/openvpn". Any of these will work:
mv MyFile.conf openvpn- look in my current dir for this "openvpn"mv MyFile.conf /etc/openvpn- look for absolute path /etc/openvpnmv MyFile.conf openvpn/- look in my current dir, for a dir called openvpnmv MyFile.conf ./openvpn- makes the "current dir" even more obvious
Short version - you probably used "/" to mean "my current directory", therefore "/openvpn" to mean "openvpn which is in my current directory". But a leading "/" only ever means "the root directory", so "/openvpn" meant "openvpn in the root directory". What you needed was simply to use "openvpn" or "openvpn/", meaning "openvpn in my current directory".
1
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
add a comment |
When you move a file, you tell the OS the directory into which you want to put it, or the new path you want to give it.
You told the OS "/openvpn". So it's going to do exactly that - check if /openvpn exists (meaning an object called "openvpn" located in the root directory) and is a directory, and if so move your file into it, or else if /openvpn is a file or doesn't exist, rename and move your file so it's now accessible as /openvpn.
What you wanted it to do was move it to within a directory "openvpn", which is to be found in your current directory, not one that's in the file system root directory (which is what the leading "/" signifies). So you had to point to that dir in the move command, not to absolute path "/openvpn". Any of these will work:
mv MyFile.conf openvpn- look in my current dir for this "openvpn"mv MyFile.conf /etc/openvpn- look for absolute path /etc/openvpnmv MyFile.conf openvpn/- look in my current dir, for a dir called openvpnmv MyFile.conf ./openvpn- makes the "current dir" even more obvious
Short version - you probably used "/" to mean "my current directory", therefore "/openvpn" to mean "openvpn which is in my current directory". But a leading "/" only ever means "the root directory", so "/openvpn" meant "openvpn in the root directory". What you needed was simply to use "openvpn" or "openvpn/", meaning "openvpn in my current directory".
1
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
add a comment |
When you move a file, you tell the OS the directory into which you want to put it, or the new path you want to give it.
You told the OS "/openvpn". So it's going to do exactly that - check if /openvpn exists (meaning an object called "openvpn" located in the root directory) and is a directory, and if so move your file into it, or else if /openvpn is a file or doesn't exist, rename and move your file so it's now accessible as /openvpn.
What you wanted it to do was move it to within a directory "openvpn", which is to be found in your current directory, not one that's in the file system root directory (which is what the leading "/" signifies). So you had to point to that dir in the move command, not to absolute path "/openvpn". Any of these will work:
mv MyFile.conf openvpn- look in my current dir for this "openvpn"mv MyFile.conf /etc/openvpn- look for absolute path /etc/openvpnmv MyFile.conf openvpn/- look in my current dir, for a dir called openvpnmv MyFile.conf ./openvpn- makes the "current dir" even more obvious
Short version - you probably used "/" to mean "my current directory", therefore "/openvpn" to mean "openvpn which is in my current directory". But a leading "/" only ever means "the root directory", so "/openvpn" meant "openvpn in the root directory". What you needed was simply to use "openvpn" or "openvpn/", meaning "openvpn in my current directory".
When you move a file, you tell the OS the directory into which you want to put it, or the new path you want to give it.
You told the OS "/openvpn". So it's going to do exactly that - check if /openvpn exists (meaning an object called "openvpn" located in the root directory) and is a directory, and if so move your file into it, or else if /openvpn is a file or doesn't exist, rename and move your file so it's now accessible as /openvpn.
What you wanted it to do was move it to within a directory "openvpn", which is to be found in your current directory, not one that's in the file system root directory (which is what the leading "/" signifies). So you had to point to that dir in the move command, not to absolute path "/openvpn". Any of these will work:
mv MyFile.conf openvpn- look in my current dir for this "openvpn"mv MyFile.conf /etc/openvpn- look for absolute path /etc/openvpnmv MyFile.conf openvpn/- look in my current dir, for a dir called openvpnmv MyFile.conf ./openvpn- makes the "current dir" even more obvious
Short version - you probably used "/" to mean "my current directory", therefore "/openvpn" to mean "openvpn which is in my current directory". But a leading "/" only ever means "the root directory", so "/openvpn" meant "openvpn in the root directory". What you needed was simply to use "openvpn" or "openvpn/", meaning "openvpn in my current directory".
edited Feb 13 at 3:31
answered Feb 12 at 14:50
StilezStilez
1593
1593
1
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
add a comment |
1
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
1
1
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
Not sure why this answer was downvoted; it's correct and I actually think it's the clearest!
– Lightness Races in Orbit
Feb 12 at 21:40
add a comment |
Any path that starts with / is an absolute path, not relative.
If all paths were always relative to the current directory, how would you cd /etc in the first place? You'd have to cd ../../../../../etc and hope that was enough levels of .., or just keep doing cd .. until you got to the root directory.
Or you'd need some other syntax to express absolute paths. But Unix decided on / meaning absolute, anything else being relative to the process's current working directory. So mv MyFile.txt openvpn would work.
And no, it wouldn't work well to infer absolute vs. relative from files existing or not. We wouldn't want mkdir system calls to treat paths differently from chdir or rename system calls, and making the mv program do it just leaves room for inconsistency between mv and some other program that takes an output filename.
mv is already special because when the rename() destination is a directory, it appends the source filename to that destination directory and tries again. But notice that one simple implementation strategy relies of the first rename() system call failing with EEXIST or EISDIR. So we have to know whether a path is relative or absolute before checking the filesystem.
(Early Unix ran on slow computers, where extra checks if a directory existed could mean extra I/O if it wasn't cached, or more pressure on directory caching. But I think sanity / correctness arguments are sufficient to explain why your first guess wasn't a plausible way for the system to work, without resorting to historical efficiency arguments.)
add a comment |
Any path that starts with / is an absolute path, not relative.
If all paths were always relative to the current directory, how would you cd /etc in the first place? You'd have to cd ../../../../../etc and hope that was enough levels of .., or just keep doing cd .. until you got to the root directory.
Or you'd need some other syntax to express absolute paths. But Unix decided on / meaning absolute, anything else being relative to the process's current working directory. So mv MyFile.txt openvpn would work.
And no, it wouldn't work well to infer absolute vs. relative from files existing or not. We wouldn't want mkdir system calls to treat paths differently from chdir or rename system calls, and making the mv program do it just leaves room for inconsistency between mv and some other program that takes an output filename.
mv is already special because when the rename() destination is a directory, it appends the source filename to that destination directory and tries again. But notice that one simple implementation strategy relies of the first rename() system call failing with EEXIST or EISDIR. So we have to know whether a path is relative or absolute before checking the filesystem.
(Early Unix ran on slow computers, where extra checks if a directory existed could mean extra I/O if it wasn't cached, or more pressure on directory caching. But I think sanity / correctness arguments are sufficient to explain why your first guess wasn't a plausible way for the system to work, without resorting to historical efficiency arguments.)
add a comment |
Any path that starts with / is an absolute path, not relative.
If all paths were always relative to the current directory, how would you cd /etc in the first place? You'd have to cd ../../../../../etc and hope that was enough levels of .., or just keep doing cd .. until you got to the root directory.
Or you'd need some other syntax to express absolute paths. But Unix decided on / meaning absolute, anything else being relative to the process's current working directory. So mv MyFile.txt openvpn would work.
And no, it wouldn't work well to infer absolute vs. relative from files existing or not. We wouldn't want mkdir system calls to treat paths differently from chdir or rename system calls, and making the mv program do it just leaves room for inconsistency between mv and some other program that takes an output filename.
mv is already special because when the rename() destination is a directory, it appends the source filename to that destination directory and tries again. But notice that one simple implementation strategy relies of the first rename() system call failing with EEXIST or EISDIR. So we have to know whether a path is relative or absolute before checking the filesystem.
(Early Unix ran on slow computers, where extra checks if a directory existed could mean extra I/O if it wasn't cached, or more pressure on directory caching. But I think sanity / correctness arguments are sufficient to explain why your first guess wasn't a plausible way for the system to work, without resorting to historical efficiency arguments.)
Any path that starts with / is an absolute path, not relative.
If all paths were always relative to the current directory, how would you cd /etc in the first place? You'd have to cd ../../../../../etc and hope that was enough levels of .., or just keep doing cd .. until you got to the root directory.
Or you'd need some other syntax to express absolute paths. But Unix decided on / meaning absolute, anything else being relative to the process's current working directory. So mv MyFile.txt openvpn would work.
And no, it wouldn't work well to infer absolute vs. relative from files existing or not. We wouldn't want mkdir system calls to treat paths differently from chdir or rename system calls, and making the mv program do it just leaves room for inconsistency between mv and some other program that takes an output filename.
mv is already special because when the rename() destination is a directory, it appends the source filename to that destination directory and tries again. But notice that one simple implementation strategy relies of the first rename() system call failing with EEXIST or EISDIR. So we have to know whether a path is relative or absolute before checking the filesystem.
(Early Unix ran on slow computers, where extra checks if a directory existed could mean extra I/O if it wasn't cached, or more pressure on directory caching. But I think sanity / correctness arguments are sufficient to explain why your first guess wasn't a plausible way for the system to work, without resorting to historical efficiency arguments.)
answered Feb 13 at 6:55
Peter CordesPeter Cordes
1,019814
1,019814
add a comment |
add a comment |
To complete the other answers :
mv file.txt /location
is the same as, for Windows
mv file.txt c:location
The filesystem in linux is thought in accordance to the filesystem hierarchy standard, or FHS for short. it helps you knowing where should a file be placed depending on its nature and content.
The first folder (equivalent to c: in Windows) is /.
add a comment |
To complete the other answers :
mv file.txt /location
is the same as, for Windows
mv file.txt c:location
The filesystem in linux is thought in accordance to the filesystem hierarchy standard, or FHS for short. it helps you knowing where should a file be placed depending on its nature and content.
The first folder (equivalent to c: in Windows) is /.
add a comment |
To complete the other answers :
mv file.txt /location
is the same as, for Windows
mv file.txt c:location
The filesystem in linux is thought in accordance to the filesystem hierarchy standard, or FHS for short. it helps you knowing where should a file be placed depending on its nature and content.
The first folder (equivalent to c: in Windows) is /.
To complete the other answers :
mv file.txt /location
is the same as, for Windows
mv file.txt c:location
The filesystem in linux is thought in accordance to the filesystem hierarchy standard, or FHS for short. it helps you knowing where should a file be placed depending on its nature and content.
The first folder (equivalent to c: in Windows) is /.
answered Feb 14 at 7:29
Pierre Antoine GuillaumePierre Antoine Guillaume
1313
1313
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%2f1117625%2fwhy-doesn-t-mv-file-dir-move-the-file-to-a-subdirectory-of-the-current-workin%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