Home » Questions » Computers [ Ask a new question ]

Why can I move things to /dev/null despite it being a pseudo-device represented by a file?

Why can I move things to /dev/null despite it being a pseudo-device represented by a file?

I always thought of /dev/null as a black hole, in the way that all data I send there will not be echoed back. However there's a problem with that definition. According to Wikipedia:

Asked by: Guest | Views: 67
Total answers/comments: 4
Guest [Entry]

"If you'll try to move anything to /dev/null under a plain user (not root), you will get a Permission denied error because mv something /dev/null is actually trying to delete /dev/null and then move something to what /dev/null was.

If you will try to do it under root, it will delete /dev/null (and then move the file provided by you in it's place)! You can restore it by rebooting or typing the following in a root shell (on Linux): mknod /dev/null c 1 3; chmod a+w /dev/null or in BSD: mknod /dev/null c 3 2; chmod a+w /dev/null."
Guest [Entry]

"You can't

# uname -sr
Linux 2.6.32-ARCH
# touch a
# mv a /dev/null
mv: inter-device move failed: `a' to `/dev/null'; unable to remove target: Permission denied"
Guest [Entry]

/dev/null is like a black hole and/or an empty file. terrific! You can put anything in here and get nothing from there.
Guest [Entry]

"Shell Scripting is a common use:

cat somefile >/dev/null 2>&1

Sometimes you don't want to see/show errors etc."