If I do: touch file; mv file /dev/null
as root, /dev/null
disappears. ls -lad /dev/null
results in no such file or directory. This breaks applications which depend on /dev/null
like SSH and can be resolved by doing mknod /dev/null c 1 3; chmod 666 /dev/null
. Why does moving a regular file to this special file result in the disappearance of /dev/null
?
To clarify, this was for testing purposes, and I understand how the mv
command works. What I am curious about is why ls -la /dev/null
before replacing it with a regular file shows the expected output, but afterwards it shows that /dev/null
does not exist even though a file was allegedly created via the original mv
command and the file command shows ASCII Text. I think this must be a combination of the ls
command behavior in conjunction with devfs
when a non special file replaces a character/special file. This is on Mac OS X, behaviors may vary on other OS's.
/dev/null
.rm
command.devfs
is funny about normal files. Strange you didn't get an error frommv
though. How about this way:touch testfile; mv testfile /dev
?mv
can only be atomic on the same filesystem.