Why can I cat /dev?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












I can cat /dev, I can ls /dev, I can't less /dev. Why does cat let me cat this directory but no other directories?



Picture of this behaviour in zsh.










share|improve this question







New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2




    What exact OS is this? What exact cat is this? What is the output of ls -ld /dev? What is the output (if available) of LC_ALL=C mountpoint -d /dev?
    – Kamil Maciorowski
    3 hours ago










  • Looks like macOS to me.
    – grawity
    3 hours ago










  • @KamilMaciorowski, here's the output and neofetch for your information :) i.imgur.com/3azpnDt.png
    – haboutnnah
    2 hours ago















up vote
2
down vote

favorite
1












I can cat /dev, I can ls /dev, I can't less /dev. Why does cat let me cat this directory but no other directories?



Picture of this behaviour in zsh.










share|improve this question







New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 2




    What exact OS is this? What exact cat is this? What is the output of ls -ld /dev? What is the output (if available) of LC_ALL=C mountpoint -d /dev?
    – Kamil Maciorowski
    3 hours ago










  • Looks like macOS to me.
    – grawity
    3 hours ago










  • @KamilMaciorowski, here's the output and neofetch for your information :) i.imgur.com/3azpnDt.png
    – haboutnnah
    2 hours ago













up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I can cat /dev, I can ls /dev, I can't less /dev. Why does cat let me cat this directory but no other directories?



Picture of this behaviour in zsh.










share|improve this question







New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I can cat /dev, I can ls /dev, I can't less /dev. Why does cat let me cat this directory but no other directories?



Picture of this behaviour in zsh.







linux cat






share|improve this question







New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 4 hours ago









haboutnnah

1164




1164




New contributor




haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






haboutnnah is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 2




    What exact OS is this? What exact cat is this? What is the output of ls -ld /dev? What is the output (if available) of LC_ALL=C mountpoint -d /dev?
    – Kamil Maciorowski
    3 hours ago










  • Looks like macOS to me.
    – grawity
    3 hours ago










  • @KamilMaciorowski, here's the output and neofetch for your information :) i.imgur.com/3azpnDt.png
    – haboutnnah
    2 hours ago













  • 2




    What exact OS is this? What exact cat is this? What is the output of ls -ld /dev? What is the output (if available) of LC_ALL=C mountpoint -d /dev?
    – Kamil Maciorowski
    3 hours ago










  • Looks like macOS to me.
    – grawity
    3 hours ago










  • @KamilMaciorowski, here's the output and neofetch for your information :) i.imgur.com/3azpnDt.png
    – haboutnnah
    2 hours ago








2




2




What exact OS is this? What exact cat is this? What is the output of ls -ld /dev? What is the output (if available) of LC_ALL=C mountpoint -d /dev?
– Kamil Maciorowski
3 hours ago




What exact OS is this? What exact cat is this? What is the output of ls -ld /dev? What is the output (if available) of LC_ALL=C mountpoint -d /dev?
– Kamil Maciorowski
3 hours ago












Looks like macOS to me.
– grawity
3 hours ago




Looks like macOS to me.
– grawity
3 hours ago












@KamilMaciorowski, here's the output and neofetch for your information :) i.imgur.com/3azpnDt.png
– haboutnnah
2 hours ago





@KamilMaciorowski, here's the output and neofetch for your information :) i.imgur.com/3azpnDt.png
– haboutnnah
2 hours ago











1 Answer
1






active

oldest

votes

















up vote
6
down vote



accepted










Less is a text file viewer, cat is a tool for copying arbitrary data. So less performs its own checking to make sure you're not opening something that will have massive amounts of data or behave very strangely. On the other hand, cat has no such checking at all – if the kernel lets you open something (even if it's a pipe or a device or something worse), cat will read it.



So why does the OS allow cat to open directories? Traditionally in BSD-style systems all directories could be read as files, and that was how programs would list a directory in the first place: by just interpreting dirent structures stored on disk.



Later on, those on-disk structures began to diverge from the dirent used by the kernel: where previously a directory was a linear list, later filesystems began using hashtables, B-trees, and so on. So reading directories directly wasn't straightforward anymore – the kernel grew dedicated functions for this. (I'm not sure if that was the main reason, or if they were primarily added for other reasons such as caching.)



Some BSD systems continue to let you open all directories for reading; I don't know whether they give you the raw data from disk, or whether they return an emulated dirent list instead, or whether they let the filesystem driver decide.



So perhaps macOS is one of those operating systems where the kernel allows it as long as the filesystem provides the data. And the difference is that /dev is on a devfs filesystem that was written to allow this in the early days, while / is on an APFS filesystem that omitted this feature as unnecessary in modern times.



Disclaimer: I haven't actually done any research on BSDs or macOS. I'm just winging it.






share|improve this answer




















  • This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
    – haboutnnah
    2 hours ago











  • On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
    – grawity
    2 hours ago










  • You're right! See this: i.imgur.com/pcVpo1o.png
    – haboutnnah
    2 hours ago










  • This is really neat @grawity, i.imgur.com/8QuR0FK.png
    – haboutnnah
    2 hours ago










  • Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
    – grawity
    1 hour ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "3"
;
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',
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
);



);






haboutnnah is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1372086%2fwhy-can-i-cat-dev%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
6
down vote



accepted










Less is a text file viewer, cat is a tool for copying arbitrary data. So less performs its own checking to make sure you're not opening something that will have massive amounts of data or behave very strangely. On the other hand, cat has no such checking at all – if the kernel lets you open something (even if it's a pipe or a device or something worse), cat will read it.



So why does the OS allow cat to open directories? Traditionally in BSD-style systems all directories could be read as files, and that was how programs would list a directory in the first place: by just interpreting dirent structures stored on disk.



Later on, those on-disk structures began to diverge from the dirent used by the kernel: where previously a directory was a linear list, later filesystems began using hashtables, B-trees, and so on. So reading directories directly wasn't straightforward anymore – the kernel grew dedicated functions for this. (I'm not sure if that was the main reason, or if they were primarily added for other reasons such as caching.)



Some BSD systems continue to let you open all directories for reading; I don't know whether they give you the raw data from disk, or whether they return an emulated dirent list instead, or whether they let the filesystem driver decide.



So perhaps macOS is one of those operating systems where the kernel allows it as long as the filesystem provides the data. And the difference is that /dev is on a devfs filesystem that was written to allow this in the early days, while / is on an APFS filesystem that omitted this feature as unnecessary in modern times.



Disclaimer: I haven't actually done any research on BSDs or macOS. I'm just winging it.






share|improve this answer




















  • This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
    – haboutnnah
    2 hours ago











  • On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
    – grawity
    2 hours ago










  • You're right! See this: i.imgur.com/pcVpo1o.png
    – haboutnnah
    2 hours ago










  • This is really neat @grawity, i.imgur.com/8QuR0FK.png
    – haboutnnah
    2 hours ago










  • Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
    – grawity
    1 hour ago














up vote
6
down vote



accepted










Less is a text file viewer, cat is a tool for copying arbitrary data. So less performs its own checking to make sure you're not opening something that will have massive amounts of data or behave very strangely. On the other hand, cat has no such checking at all – if the kernel lets you open something (even if it's a pipe or a device or something worse), cat will read it.



So why does the OS allow cat to open directories? Traditionally in BSD-style systems all directories could be read as files, and that was how programs would list a directory in the first place: by just interpreting dirent structures stored on disk.



Later on, those on-disk structures began to diverge from the dirent used by the kernel: where previously a directory was a linear list, later filesystems began using hashtables, B-trees, and so on. So reading directories directly wasn't straightforward anymore – the kernel grew dedicated functions for this. (I'm not sure if that was the main reason, or if they were primarily added for other reasons such as caching.)



Some BSD systems continue to let you open all directories for reading; I don't know whether they give you the raw data from disk, or whether they return an emulated dirent list instead, or whether they let the filesystem driver decide.



So perhaps macOS is one of those operating systems where the kernel allows it as long as the filesystem provides the data. And the difference is that /dev is on a devfs filesystem that was written to allow this in the early days, while / is on an APFS filesystem that omitted this feature as unnecessary in modern times.



Disclaimer: I haven't actually done any research on BSDs or macOS. I'm just winging it.






share|improve this answer




















  • This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
    – haboutnnah
    2 hours ago











  • On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
    – grawity
    2 hours ago










  • You're right! See this: i.imgur.com/pcVpo1o.png
    – haboutnnah
    2 hours ago










  • This is really neat @grawity, i.imgur.com/8QuR0FK.png
    – haboutnnah
    2 hours ago










  • Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
    – grawity
    1 hour ago












up vote
6
down vote



accepted







up vote
6
down vote



accepted






Less is a text file viewer, cat is a tool for copying arbitrary data. So less performs its own checking to make sure you're not opening something that will have massive amounts of data or behave very strangely. On the other hand, cat has no such checking at all – if the kernel lets you open something (even if it's a pipe or a device or something worse), cat will read it.



So why does the OS allow cat to open directories? Traditionally in BSD-style systems all directories could be read as files, and that was how programs would list a directory in the first place: by just interpreting dirent structures stored on disk.



Later on, those on-disk structures began to diverge from the dirent used by the kernel: where previously a directory was a linear list, later filesystems began using hashtables, B-trees, and so on. So reading directories directly wasn't straightforward anymore – the kernel grew dedicated functions for this. (I'm not sure if that was the main reason, or if they were primarily added for other reasons such as caching.)



Some BSD systems continue to let you open all directories for reading; I don't know whether they give you the raw data from disk, or whether they return an emulated dirent list instead, or whether they let the filesystem driver decide.



So perhaps macOS is one of those operating systems where the kernel allows it as long as the filesystem provides the data. And the difference is that /dev is on a devfs filesystem that was written to allow this in the early days, while / is on an APFS filesystem that omitted this feature as unnecessary in modern times.



Disclaimer: I haven't actually done any research on BSDs or macOS. I'm just winging it.






share|improve this answer












Less is a text file viewer, cat is a tool for copying arbitrary data. So less performs its own checking to make sure you're not opening something that will have massive amounts of data or behave very strangely. On the other hand, cat has no such checking at all – if the kernel lets you open something (even if it's a pipe or a device or something worse), cat will read it.



So why does the OS allow cat to open directories? Traditionally in BSD-style systems all directories could be read as files, and that was how programs would list a directory in the first place: by just interpreting dirent structures stored on disk.



Later on, those on-disk structures began to diverge from the dirent used by the kernel: where previously a directory was a linear list, later filesystems began using hashtables, B-trees, and so on. So reading directories directly wasn't straightforward anymore – the kernel grew dedicated functions for this. (I'm not sure if that was the main reason, or if they were primarily added for other reasons such as caching.)



Some BSD systems continue to let you open all directories for reading; I don't know whether they give you the raw data from disk, or whether they return an emulated dirent list instead, or whether they let the filesystem driver decide.



So perhaps macOS is one of those operating systems where the kernel allows it as long as the filesystem provides the data. And the difference is that /dev is on a devfs filesystem that was written to allow this in the early days, while / is on an APFS filesystem that omitted this feature as unnecessary in modern times.



Disclaimer: I haven't actually done any research on BSDs or macOS. I'm just winging it.







share|improve this answer












share|improve this answer



share|improve this answer










answered 3 hours ago









grawity

224k34462524




224k34462524











  • This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
    – haboutnnah
    2 hours ago











  • On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
    – grawity
    2 hours ago










  • You're right! See this: i.imgur.com/pcVpo1o.png
    – haboutnnah
    2 hours ago










  • This is really neat @grawity, i.imgur.com/8QuR0FK.png
    – haboutnnah
    2 hours ago










  • Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
    – grawity
    1 hour ago
















  • This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
    – haboutnnah
    2 hours ago











  • On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
    – grawity
    2 hours ago










  • You're right! See this: i.imgur.com/pcVpo1o.png
    – haboutnnah
    2 hours ago










  • This is really neat @grawity, i.imgur.com/8QuR0FK.png
    – haboutnnah
    2 hours ago










  • Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
    – grawity
    1 hour ago















This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
– haboutnnah
2 hours ago





This seems to make sense. Are there any other sections of storage that differ from the standard OS filesystem? I assumed /etc would, so I used that as my benchmark.
– haboutnnah
2 hours ago













On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
– grawity
2 hours ago




On the contrary, generally /etc is just a regular folder containing regular files. There may be other virtual filesystems though – run mount or /sbin/mount to see what's currently mounted where.
– grawity
2 hours ago












You're right! See this: i.imgur.com/pcVpo1o.png
– haboutnnah
2 hours ago




You're right! See this: i.imgur.com/pcVpo1o.png
– haboutnnah
2 hours ago












This is really neat @grawity, i.imgur.com/8QuR0FK.png
– haboutnnah
2 hours ago




This is really neat @grawity, i.imgur.com/8QuR0FK.png
– haboutnnah
2 hours ago












Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
– grawity
1 hour ago




Well, directly reading a disk is fairly normal operation because disks just have a flat structure anyway (this is how you can make an .iso image of a CD).
– grawity
1 hour ago










haboutnnah is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















haboutnnah is a new contributor. Be nice, and check out our Code of Conduct.












haboutnnah is a new contributor. Be nice, and check out our Code of Conduct.











haboutnnah is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1372086%2fwhy-can-i-cat-dev%23new-answer', 'question_page');

);

Post as a guest













































































Comments

Popular posts from this blog

What does second last employer means? [closed]

List of Gilmore Girls characters

Confectionery