When moving current directory I get “mv: cannot move `.' to `../dir/.': Device or resource busy”What do...
Amiga 500 OCS/ECS vs Mega Drive VDP
How do you determine which representation of a function to use for Newton's method?
Can I separate garlic into cloves for storage?
Minimum number of lines to draw 111 squares
What's the purpose of autocorrelation?
With a 500GB SSD and a 250GB SSD is it possible to mirror a 250GB partition on the 500GB with the 250GB SSD using ZFS?
Account creation and log-in system
Madrid to London w/ Expired 90/180 days stay as US citizen
Is there an in-universe reason Harry says this or is this simply a Rowling mistake?
Why would a fighter use the afterburner and air brakes at the same time?
What can I actually do with a high credit score?
How to convey to the people around me that I want to disengage myself from constant giving?
Carroll's interpretation of 1-forms
Talk about Grandpa's weird talk: Who are these folks?
Manager manipulates my leaves, what's in it for him?
Can a business put whatever they want into a contract?
What's the benefit of prohibiting the use of techniques/language constructs that have not been taught?
How can I create folders in folders in terminal
Plausibility and performance of a composite longbow
How often is duct tape used during crewed space missions?
Is the name of an interval between two notes unique and absolute?
Statistical tests for benchmark comparison
Output Distinct Factor Cuboids
How can I check that parent has more than 1 child?
When moving current directory I get “mv: cannot move `.' to `../dir/.': Device or resource busy”
What do the fields in ls -al output mean?Why does a new directory have a hard link count of 2 before anything is added to it?How does bash continue to work correctly when you move its working directory?Automatically moving files to a directory, one by one, and only when the target folder is emptyMoving /usr/lib without breaking everythingmv: cannot remove directory: Directory not emptycannot move Directory not emptyHow can I move a file within a directory to the current working directory without renaming?How to move several files in current directory by name to another directory?What happens when the current directory is deleted?Moving contents of current directory up one level and overwriting if exists recursivelyWhy can't you move another user's directory when you can move their file?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
$ mv . ../general/
mv: cannot move `.' to `../general/.': Device or resource busy
Does it mean that the current directory is a busy device or resource, and can't be moved away? Why is it?
directory mv
add a comment
|
$ mv . ../general/
mv: cannot move `.' to `../general/.': Device or resource busy
Does it mean that the current directory is a busy device or resource, and can't be moved away? Why is it?
directory mv
add a comment
|
$ mv . ../general/
mv: cannot move `.' to `../general/.': Device or resource busy
Does it mean that the current directory is a busy device or resource, and can't be moved away? Why is it?
directory mv
$ mv . ../general/
mv: cannot move `.' to `../general/.': Device or resource busy
Does it mean that the current directory is a busy device or resource, and can't be moved away? Why is it?
directory mv
directory mv
edited Mar 21 at 11:45
jimmij
34.1k8 gold badges82 silver badges116 bronze badges
34.1k8 gold badges82 silver badges116 bronze badges
asked Oct 5 '14 at 0:00
TimTim
30.9k91 gold badges297 silver badges550 bronze badges
30.9k91 gold badges297 silver badges550 bronze badges
add a comment
|
add a comment
|
4 Answers
4
active
oldest
votes
You can't move the directory you're current in. The current process is the one that's keeping it busy.
Instead, go up one level and name the previously-current directory to move it to the target.
add a comment
|
It is not possible to move a dot .
. The dot is not the same as current directory name. You can think about .
as a pointer to the directory, but not the directory itself, therefore,
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp
/home/jimmij/tmp
/home/jimmij/tmp
$ mkdir tmp1 tmp2
$ mv tmp1/. tmp2/
mv: cannot move ‘tmp1/.’ to ‘tmp2/.’: Device or resource busy
doesn't work, but
cd tmp1
mv ../tmp1 ../tmp2
works fine, so actually you can move current directory, although some commands can be confused after this operation:
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp2/tmp1
$ cd .
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
Similar story with ..
, i.e. parent directory.
In other words each directory must contain at least two elements: .
and ..
. You cannot move or delete them.
add a comment
|
The reason you're getting the message:
mv: cannot move
.' to
../general/.': Device or resource busy
is due to how the .
, and ..
work in addition to mv
. When you move something in Unix, the mv
command attempts to unlink everything that references the inode of the item that you're attempting to move. In this case that would be the inode of whatever the directory is that .
is referencing.
The "symbols/links" .
and ..
are linking to inodes and are in a sense special. You can read about their history here in the U&L Q&A titled: Why does a new directory have a hard link count of 2 before anything is added to it? If you've ever looked at a newly created directory, you'll notice that it always starts with a linked count of 2. The reason is due to the existence of the .
and ..
.
$ mkdir adir
$ ls -l | grep adir
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 adir
$ ls -la adir/
total 8
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 .
drwxrwxr-x. 3 saml saml 4096 Oct 5 08:02 ..
NOTE: Reference for ls
output if you're unclear is here in this U&L Q&A titled: What do the fields in ls -al output mean?
So they aren't names of actual directories, but are "symbols/links" that are linking to them. Therefore they meed to be unlinked prior to being able to mv
.
Well since your command is using the .
, it cannot be unlinked by the mv
command, hence the msg: "Device or resource busy".
References
- The Unix File System Hierarchy
add a comment
|
Linux forbids renaming any path that ends in the component .
or ..
, returning the error EBUSY; the following will also fail:
$ mkdir a a/aa
$ mv a/aa/.. b
mv: cannot move ‘a/aa/..’ to ‘b/..’: Device or resource busy
The code for this is in namei.c::renameat
. The last component of the pathname when passed to various functions needs to be of type LAST_NORM
, not LAST_DOT
or LAST_DOTDOT
.
FreeBSD returns the error EINVAL in each of these cases.
We can only guess as to why there is this restriction.
- The POSIX standard for rename states that
The rename() function shall fail if:
...
[EBUSY] The directory named by old or new is currently in use by the system or another process, and the implementation considers this an error.
One could consider .
to currently be in use by the process. But note that Linux allows the following, so a directory merely being in use by some process is not sufficient for rename
to fail:
$ mkdir /tmp/t
$ cd /tmp/t
$ mv /tmp/t /tmp/t1
$ /bin/pwd
/tmp/t1
The reason for forbidding the renaming of .
and ..
is probably "leads to less user confusion".
.
is typically a hard link to the directory's entry in its parent, and is somewhat special in that a process can always open.
to access its current working directory. Being able to rename it would be counterproductive.
..
is typically a hard link to the directory's parent, and is somewhat special in that a process opening..
will get the parent directory (or the directory itself, if it's a mount point). Being able to rename it would be counterproductive.
Linux also forbids rmdir
of a path whose last component is ..
(ENOTEMPTY) or .
(EINVAL). FreeBSD returns the error EINVAL for each of these.
The POSIX standard for rmdir has this:
The rmdir() function shall fail if:
...
[EINVAL] The path argument contains a last component that is dot.
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/4.0/"u003ecc by-sa 4.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%2f159345%2fwhen-moving-current-directory-i-get-mv-cannot-move-to-dir-device-o%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can't move the directory you're current in. The current process is the one that's keeping it busy.
Instead, go up one level and name the previously-current directory to move it to the target.
add a comment
|
You can't move the directory you're current in. The current process is the one that's keeping it busy.
Instead, go up one level and name the previously-current directory to move it to the target.
add a comment
|
You can't move the directory you're current in. The current process is the one that's keeping it busy.
Instead, go up one level and name the previously-current directory to move it to the target.
You can't move the directory you're current in. The current process is the one that's keeping it busy.
Instead, go up one level and name the previously-current directory to move it to the target.
answered Oct 5 '14 at 0:48
o11co11c
1,1085 silver badges11 bronze badges
1,1085 silver badges11 bronze badges
add a comment
|
add a comment
|
It is not possible to move a dot .
. The dot is not the same as current directory name. You can think about .
as a pointer to the directory, but not the directory itself, therefore,
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp
/home/jimmij/tmp
/home/jimmij/tmp
$ mkdir tmp1 tmp2
$ mv tmp1/. tmp2/
mv: cannot move ‘tmp1/.’ to ‘tmp2/.’: Device or resource busy
doesn't work, but
cd tmp1
mv ../tmp1 ../tmp2
works fine, so actually you can move current directory, although some commands can be confused after this operation:
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp2/tmp1
$ cd .
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
Similar story with ..
, i.e. parent directory.
In other words each directory must contain at least two elements: .
and ..
. You cannot move or delete them.
add a comment
|
It is not possible to move a dot .
. The dot is not the same as current directory name. You can think about .
as a pointer to the directory, but not the directory itself, therefore,
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp
/home/jimmij/tmp
/home/jimmij/tmp
$ mkdir tmp1 tmp2
$ mv tmp1/. tmp2/
mv: cannot move ‘tmp1/.’ to ‘tmp2/.’: Device or resource busy
doesn't work, but
cd tmp1
mv ../tmp1 ../tmp2
works fine, so actually you can move current directory, although some commands can be confused after this operation:
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp2/tmp1
$ cd .
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
Similar story with ..
, i.e. parent directory.
In other words each directory must contain at least two elements: .
and ..
. You cannot move or delete them.
add a comment
|
It is not possible to move a dot .
. The dot is not the same as current directory name. You can think about .
as a pointer to the directory, but not the directory itself, therefore,
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp
/home/jimmij/tmp
/home/jimmij/tmp
$ mkdir tmp1 tmp2
$ mv tmp1/. tmp2/
mv: cannot move ‘tmp1/.’ to ‘tmp2/.’: Device or resource busy
doesn't work, but
cd tmp1
mv ../tmp1 ../tmp2
works fine, so actually you can move current directory, although some commands can be confused after this operation:
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp2/tmp1
$ cd .
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
Similar story with ..
, i.e. parent directory.
In other words each directory must contain at least two elements: .
and ..
. You cannot move or delete them.
It is not possible to move a dot .
. The dot is not the same as current directory name. You can think about .
as a pointer to the directory, but not the directory itself, therefore,
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp
/home/jimmij/tmp
/home/jimmij/tmp
$ mkdir tmp1 tmp2
$ mv tmp1/. tmp2/
mv: cannot move ‘tmp1/.’ to ‘tmp2/.’: Device or resource busy
doesn't work, but
cd tmp1
mv ../tmp1 ../tmp2
works fine, so actually you can move current directory, although some commands can be confused after this operation:
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp1
/home/jimmij/tmp/tmp2/tmp1
$ cd .
$ pwd && echo $PWD && realpath .
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
/home/jimmij/tmp/tmp2/tmp1
Similar story with ..
, i.e. parent directory.
In other words each directory must contain at least two elements: .
and ..
. You cannot move or delete them.
edited Oct 5 '14 at 2:03
answered Oct 5 '14 at 1:29
jimmijjimmij
34.1k8 gold badges82 silver badges116 bronze badges
34.1k8 gold badges82 silver badges116 bronze badges
add a comment
|
add a comment
|
The reason you're getting the message:
mv: cannot move
.' to
../general/.': Device or resource busy
is due to how the .
, and ..
work in addition to mv
. When you move something in Unix, the mv
command attempts to unlink everything that references the inode of the item that you're attempting to move. In this case that would be the inode of whatever the directory is that .
is referencing.
The "symbols/links" .
and ..
are linking to inodes and are in a sense special. You can read about their history here in the U&L Q&A titled: Why does a new directory have a hard link count of 2 before anything is added to it? If you've ever looked at a newly created directory, you'll notice that it always starts with a linked count of 2. The reason is due to the existence of the .
and ..
.
$ mkdir adir
$ ls -l | grep adir
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 adir
$ ls -la adir/
total 8
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 .
drwxrwxr-x. 3 saml saml 4096 Oct 5 08:02 ..
NOTE: Reference for ls
output if you're unclear is here in this U&L Q&A titled: What do the fields in ls -al output mean?
So they aren't names of actual directories, but are "symbols/links" that are linking to them. Therefore they meed to be unlinked prior to being able to mv
.
Well since your command is using the .
, it cannot be unlinked by the mv
command, hence the msg: "Device or resource busy".
References
- The Unix File System Hierarchy
add a comment
|
The reason you're getting the message:
mv: cannot move
.' to
../general/.': Device or resource busy
is due to how the .
, and ..
work in addition to mv
. When you move something in Unix, the mv
command attempts to unlink everything that references the inode of the item that you're attempting to move. In this case that would be the inode of whatever the directory is that .
is referencing.
The "symbols/links" .
and ..
are linking to inodes and are in a sense special. You can read about their history here in the U&L Q&A titled: Why does a new directory have a hard link count of 2 before anything is added to it? If you've ever looked at a newly created directory, you'll notice that it always starts with a linked count of 2. The reason is due to the existence of the .
and ..
.
$ mkdir adir
$ ls -l | grep adir
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 adir
$ ls -la adir/
total 8
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 .
drwxrwxr-x. 3 saml saml 4096 Oct 5 08:02 ..
NOTE: Reference for ls
output if you're unclear is here in this U&L Q&A titled: What do the fields in ls -al output mean?
So they aren't names of actual directories, but are "symbols/links" that are linking to them. Therefore they meed to be unlinked prior to being able to mv
.
Well since your command is using the .
, it cannot be unlinked by the mv
command, hence the msg: "Device or resource busy".
References
- The Unix File System Hierarchy
add a comment
|
The reason you're getting the message:
mv: cannot move
.' to
../general/.': Device or resource busy
is due to how the .
, and ..
work in addition to mv
. When you move something in Unix, the mv
command attempts to unlink everything that references the inode of the item that you're attempting to move. In this case that would be the inode of whatever the directory is that .
is referencing.
The "symbols/links" .
and ..
are linking to inodes and are in a sense special. You can read about their history here in the U&L Q&A titled: Why does a new directory have a hard link count of 2 before anything is added to it? If you've ever looked at a newly created directory, you'll notice that it always starts with a linked count of 2. The reason is due to the existence of the .
and ..
.
$ mkdir adir
$ ls -l | grep adir
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 adir
$ ls -la adir/
total 8
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 .
drwxrwxr-x. 3 saml saml 4096 Oct 5 08:02 ..
NOTE: Reference for ls
output if you're unclear is here in this U&L Q&A titled: What do the fields in ls -al output mean?
So they aren't names of actual directories, but are "symbols/links" that are linking to them. Therefore they meed to be unlinked prior to being able to mv
.
Well since your command is using the .
, it cannot be unlinked by the mv
command, hence the msg: "Device or resource busy".
References
- The Unix File System Hierarchy
The reason you're getting the message:
mv: cannot move
.' to
../general/.': Device or resource busy
is due to how the .
, and ..
work in addition to mv
. When you move something in Unix, the mv
command attempts to unlink everything that references the inode of the item that you're attempting to move. In this case that would be the inode of whatever the directory is that .
is referencing.
The "symbols/links" .
and ..
are linking to inodes and are in a sense special. You can read about their history here in the U&L Q&A titled: Why does a new directory have a hard link count of 2 before anything is added to it? If you've ever looked at a newly created directory, you'll notice that it always starts with a linked count of 2. The reason is due to the existence of the .
and ..
.
$ mkdir adir
$ ls -l | grep adir
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 adir
$ ls -la adir/
total 8
drwxrwxr-x. 2 saml saml 4096 Oct 5 08:02 .
drwxrwxr-x. 3 saml saml 4096 Oct 5 08:02 ..
NOTE: Reference for ls
output if you're unclear is here in this U&L Q&A titled: What do the fields in ls -al output mean?
So they aren't names of actual directories, but are "symbols/links" that are linking to them. Therefore they meed to be unlinked prior to being able to mv
.
Well since your command is using the .
, it cannot be unlinked by the mv
command, hence the msg: "Device or resource busy".
References
- The Unix File System Hierarchy
edited 19 mins ago
muru
44.7k5 gold badges111 silver badges183 bronze badges
44.7k5 gold badges111 silver badges183 bronze badges
answered Oct 5 '14 at 11:49
slm♦slm
269k75 gold badges582 silver badges728 bronze badges
269k75 gold badges582 silver badges728 bronze badges
add a comment
|
add a comment
|
Linux forbids renaming any path that ends in the component .
or ..
, returning the error EBUSY; the following will also fail:
$ mkdir a a/aa
$ mv a/aa/.. b
mv: cannot move ‘a/aa/..’ to ‘b/..’: Device or resource busy
The code for this is in namei.c::renameat
. The last component of the pathname when passed to various functions needs to be of type LAST_NORM
, not LAST_DOT
or LAST_DOTDOT
.
FreeBSD returns the error EINVAL in each of these cases.
We can only guess as to why there is this restriction.
- The POSIX standard for rename states that
The rename() function shall fail if:
...
[EBUSY] The directory named by old or new is currently in use by the system or another process, and the implementation considers this an error.
One could consider .
to currently be in use by the process. But note that Linux allows the following, so a directory merely being in use by some process is not sufficient for rename
to fail:
$ mkdir /tmp/t
$ cd /tmp/t
$ mv /tmp/t /tmp/t1
$ /bin/pwd
/tmp/t1
The reason for forbidding the renaming of .
and ..
is probably "leads to less user confusion".
.
is typically a hard link to the directory's entry in its parent, and is somewhat special in that a process can always open.
to access its current working directory. Being able to rename it would be counterproductive.
..
is typically a hard link to the directory's parent, and is somewhat special in that a process opening..
will get the parent directory (or the directory itself, if it's a mount point). Being able to rename it would be counterproductive.
Linux also forbids rmdir
of a path whose last component is ..
(ENOTEMPTY) or .
(EINVAL). FreeBSD returns the error EINVAL for each of these.
The POSIX standard for rmdir has this:
The rmdir() function shall fail if:
...
[EINVAL] The path argument contains a last component that is dot.
add a comment
|
Linux forbids renaming any path that ends in the component .
or ..
, returning the error EBUSY; the following will also fail:
$ mkdir a a/aa
$ mv a/aa/.. b
mv: cannot move ‘a/aa/..’ to ‘b/..’: Device or resource busy
The code for this is in namei.c::renameat
. The last component of the pathname when passed to various functions needs to be of type LAST_NORM
, not LAST_DOT
or LAST_DOTDOT
.
FreeBSD returns the error EINVAL in each of these cases.
We can only guess as to why there is this restriction.
- The POSIX standard for rename states that
The rename() function shall fail if:
...
[EBUSY] The directory named by old or new is currently in use by the system or another process, and the implementation considers this an error.
One could consider .
to currently be in use by the process. But note that Linux allows the following, so a directory merely being in use by some process is not sufficient for rename
to fail:
$ mkdir /tmp/t
$ cd /tmp/t
$ mv /tmp/t /tmp/t1
$ /bin/pwd
/tmp/t1
The reason for forbidding the renaming of .
and ..
is probably "leads to less user confusion".
.
is typically a hard link to the directory's entry in its parent, and is somewhat special in that a process can always open.
to access its current working directory. Being able to rename it would be counterproductive.
..
is typically a hard link to the directory's parent, and is somewhat special in that a process opening..
will get the parent directory (or the directory itself, if it's a mount point). Being able to rename it would be counterproductive.
Linux also forbids rmdir
of a path whose last component is ..
(ENOTEMPTY) or .
(EINVAL). FreeBSD returns the error EINVAL for each of these.
The POSIX standard for rmdir has this:
The rmdir() function shall fail if:
...
[EINVAL] The path argument contains a last component that is dot.
add a comment
|
Linux forbids renaming any path that ends in the component .
or ..
, returning the error EBUSY; the following will also fail:
$ mkdir a a/aa
$ mv a/aa/.. b
mv: cannot move ‘a/aa/..’ to ‘b/..’: Device or resource busy
The code for this is in namei.c::renameat
. The last component of the pathname when passed to various functions needs to be of type LAST_NORM
, not LAST_DOT
or LAST_DOTDOT
.
FreeBSD returns the error EINVAL in each of these cases.
We can only guess as to why there is this restriction.
- The POSIX standard for rename states that
The rename() function shall fail if:
...
[EBUSY] The directory named by old or new is currently in use by the system or another process, and the implementation considers this an error.
One could consider .
to currently be in use by the process. But note that Linux allows the following, so a directory merely being in use by some process is not sufficient for rename
to fail:
$ mkdir /tmp/t
$ cd /tmp/t
$ mv /tmp/t /tmp/t1
$ /bin/pwd
/tmp/t1
The reason for forbidding the renaming of .
and ..
is probably "leads to less user confusion".
.
is typically a hard link to the directory's entry in its parent, and is somewhat special in that a process can always open.
to access its current working directory. Being able to rename it would be counterproductive.
..
is typically a hard link to the directory's parent, and is somewhat special in that a process opening..
will get the parent directory (or the directory itself, if it's a mount point). Being able to rename it would be counterproductive.
Linux also forbids rmdir
of a path whose last component is ..
(ENOTEMPTY) or .
(EINVAL). FreeBSD returns the error EINVAL for each of these.
The POSIX standard for rmdir has this:
The rmdir() function shall fail if:
...
[EINVAL] The path argument contains a last component that is dot.
Linux forbids renaming any path that ends in the component .
or ..
, returning the error EBUSY; the following will also fail:
$ mkdir a a/aa
$ mv a/aa/.. b
mv: cannot move ‘a/aa/..’ to ‘b/..’: Device or resource busy
The code for this is in namei.c::renameat
. The last component of the pathname when passed to various functions needs to be of type LAST_NORM
, not LAST_DOT
or LAST_DOTDOT
.
FreeBSD returns the error EINVAL in each of these cases.
We can only guess as to why there is this restriction.
- The POSIX standard for rename states that
The rename() function shall fail if:
...
[EBUSY] The directory named by old or new is currently in use by the system or another process, and the implementation considers this an error.
One could consider .
to currently be in use by the process. But note that Linux allows the following, so a directory merely being in use by some process is not sufficient for rename
to fail:
$ mkdir /tmp/t
$ cd /tmp/t
$ mv /tmp/t /tmp/t1
$ /bin/pwd
/tmp/t1
The reason for forbidding the renaming of .
and ..
is probably "leads to less user confusion".
.
is typically a hard link to the directory's entry in its parent, and is somewhat special in that a process can always open.
to access its current working directory. Being able to rename it would be counterproductive.
..
is typically a hard link to the directory's parent, and is somewhat special in that a process opening..
will get the parent directory (or the directory itself, if it's a mount point). Being able to rename it would be counterproductive.
Linux also forbids rmdir
of a path whose last component is ..
(ENOTEMPTY) or .
(EINVAL). FreeBSD returns the error EINVAL for each of these.
The POSIX standard for rmdir has this:
The rmdir() function shall fail if:
...
[EINVAL] The path argument contains a last component that is dot.
edited Oct 5 '14 at 17:42
answered Oct 5 '14 at 16:29
Mark PlotnickMark Plotnick
19.8k2 gold badges43 silver badges70 bronze badges
19.8k2 gold badges43 silver badges70 bronze badges
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%2f159345%2fwhen-moving-current-directory-i-get-mv-cannot-move-to-dir-device-o%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