"Everything is a file" is what made me start understanding linux few years ago and from there it got easier to use with each new concept.
Still this was really revolutionary to me when I first heard it. Made a bunch of things just click.
"Everything is a file" is what made me start understanding linux few years ago and from there it got easier to use with each new concept.
Still this was really revolutionary to me when I first heard it. Made a bunch of things just click.
42 Comments
MrChewy@lemmy.world · 31 pts · 221d
I may be dumb, been on linux too long or a combination of both. But what other way is there, does windows work differently? (regarding that)
rtxn@lemmy.world · 68 pts · 221d
"Everything is a file" means that many of the system's components are represented as abstractions in the filesystem. It's simply an API that allows reading from and writing to it by integrating into the hierarchical file structure.
If you take a look inside
/sys, you will find a fuckton of files, but they don't represent data stored on a mass storage medium. Instead, the directory contains a mountedsysfsfilesystem that contains file-like representations of various parts and properties of the system. For example, you can read them like a file by runningcat /sys/block/sda/queue/rotationalto check if thesdablock device is a spinning disk (1) or solid-state storage (0). Or you can write to them like a file by runningecho 1 > /sys/block/sda/devices/deleteto commandsda's driver to detach the device. Similarly,/proccontains a mountedprocfsfilesystem that presents information about running processes as file-like entries;/devcontains a mounteddevfsthat points to various devices; and/tmpand/runcontaintmpfsmounts for temporary storage in volatile memory (RAM or swap).Windows uses various other APIs (like the Component Object Model and others) to accomplish the same that are not necessarily tied into the filesystem.
TimeSquirrel@kbin.melroy.org · 29 pts · 221d
Exactly the same concept as memory-mapped hardware I/O, or virtual file system drivers. Makes it so you don't have to think too much about implementation details and uses a common interface that's already there.
ByteJunk@lemmy.world · 13 pts · 220d
Sensible, yes.
But this is alien tech in windows land, if you're reading some device status or something, you need a special app for that.
witty_username@feddit.nl · 15 pts · 221d
Successful_Try543@feddit.org · 37 pts · 221d
Also, in unixoid systems, devices are files too.
drosophila@lemmy.blahaj.zone · 47 pts · 221d
Anyone interested in this concept should take a look at plan9. Everything is even more of a file there.
Taking a screenshot, for example, can be done with:
cat /dev/screen | topng > screenshot.pngThat combined with the way that parent processes can alter their children's view of the filesystem namespace allows for extremely elegant abstractions. For example, every program just tries to write directly to
screenoraudio, but the desktop environment redirects their writes to the relevant servers. Which means that, in the absence of those servers, those same programs can run just fine and don't care whether they're being multiplexed or not. That also means that the plan9 userspace can be nested inside itself just using the normal mechanisms of how the OS works (that is, without a special tool like Docker).Peruvian_Skies@sh.itjust.works · 11 pts · 221d
This is very interesting.
2deck@lemmy.world · 6 pts · 220d
👀 What kind of voodoo...
ByteJunk@lemmy.world · 6 pts · 220d
That is indeed seductive.
Zagorath@aussie.zone · 15 pts · 221d
That might be part of it, but I was thinking it was more how things we don't think of as files, like sockets, are accessed with a file descriptor.
pewpew@feddit.it · 11 pts · 221d
Also hardware is treated like a file in /dev
Badabinski@kbin.earth · 8 pts · 221d
Hell, Bash provides filesystem-based sockets in
/dev/tcp, so a tcp connection can almost be like Unix sockets or anything else.I always found it weird that it was specifically provided by Bash...
unknownuserunknownlocation@kbin.earth · 3 pts · 221d
Mind you, the registry is also just a couple of files that are shown to the user as "the registry". IIRC, on Windows, go into the user account's root folder, and you'll have NTUSER.dat. That's the HKCU hive for that user.
Peruvian_Skies@sh.itjust.works · 7 pts · 221d
And that's precisely the difference. In both cases the configuration is data stored on disk but Linux presents it as files while Windows presents it as a registry tree. In Windows, you're not supposed to edit the registry by interacting with NTUSER.dat as a file.
Dialectical_Specialist@quokk.au · 17 pts · 220d
wait til you gentoo and find out even folders themselves are files(as far as the machine interprets it anyway)
87Six@lemmy.zip · 9 pts · 220d
Isn't that.. Normal tho?
janet_catcus@lemmy.blahaj.zone · 15 pts · 221d
it's all fun and games until you want to use your mouse and keyboard inputs on another machine and also view the other machines screen contents. then all of a sudden stuff stops being a file. quaint.
if only there was a way to share resources over a network...
FooBarrington@lemmy.world · 13 pts · 221d
Why aren't the Linux devs just using SMB to forward the mouse and keyboard files? Are they stupid?
mumblerfish@lemmy.world · 26 pts · 221d
What do you mean? This
doesn't work?
janet_catcus@lemmy.blahaj.zone · 4 pts · 220d
eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeew scoots faaaar away from you actually when writing the prior comment, i was thinking about the ease that is doing what i described on plan9, there everything is in fact a file, which you can simply mount via the 9p protocol
what mumblerfish suggests looks interesting and i would have to read some the man page of "nc", i suppose...
FauxLiving@lemmy.world · 7 pts · 220d
I've figured out how to control computers remotely and I'll share the script:
Client:
Server:
Just chmod 777 both files and run as root, ez.
jim3692@discuss.online · 4 pts · 220d
What's the difference between this and the classic "ssh user@server" ?
FauxLiving@lemmy.world · 3 pts · 219d
we're fans of internet horror memes and being loud in libraries. so we love scp and hate ssh
jim3692@discuss.online · 3 pts · 219d
😐
FauxLiving@lemmy.world · 2 pts · 219d
Don't judge me
caseyweederman@lemmy.ca · 2 pts · 219d
In case you were genuinely curious: the above humorous example bypasses very many very good safety precautions and conveniences.
When you boil everything down, one element stands out: the s in scp stands for ssh, so you are in fact still using ssh, just with several hoops bolted on.
FauxLiving@lemmy.world · 2 pts · 218d
I was taught in school that security and convenience are diametrically opposed, so if you can find any way of making this less secure/more convenient I'd be happy to deploy it to the entire credit union.
caseyweederman@lemmy.ca · 2 pts · 218d
Just make the entire filesystem 777. And bypass the ssh warning when id_rsa is too permissible.
Korhaka@sopuli.xyz · 8 pts · 221d
I am curious what you mean by everything is a file... What else would it be?
JayDee@lemmy.sdf.org · 17 pts · 221d
It's more a philosophy for Unix systems. When we say that "everything is a file", we're saying that even devices should show up on the filesystem (/dev), even network ports should show up on the filesystem, even processes should show up on the filesystem(/proc), etc... and that is as opposed to having a different system abstraction handle those functions instead.
Of course when you look deeper into it, linux does not explicitly follow that rule, it more just adheres to it. It's more a guideline than an explicit statement of fact
verstra@programming.dev · 13 pts · 221d
It could be a process, which you can talk to only via an IPC call. For example, dbus
gandalf_der_12te@discuss.tchncs.de · 3 pts · 220d
can't you somehow do IPC via filesystem-based sockets in linux too?
verstra@programming.dev · 3 pts · 219d
Yea, but socket is not a file. Maybe if you stretch the definition.
Well in any case, when people say that linux is great because everything is a file, they either mean that:
Zagorath@aussie.zone · 5 pts · 221d
Yeah I'm interested in how that works too.
I've recently been looking at the Nextcloud "all in one" Docker image. It works by mounting the docker.sock file into the master container, which allows that container to stand up a whole bunch of other containers on your machine.
How would that work on Windows, if the Docker socket isn't a file handle?
Peruvian_Skies@sh.itjust.works · 4 pts · 221d
Docker Desktop handles the abstraction in Windows and MacOS. The container thinks it mounted a file.
Zagorath@aussie.zone · 3 pts · 221d
Oh that's interesting. I wonder why they do it that way, considering macOS is a Unix OS.
BreadstickNinja@lemmy.world · 2 pts · 220d
I dunno, but it's a pain. Hiding low-level components from the user to make it more user-friendly.
I have an old 2014 macbook with a busted GPU temp sensor. The Mac firmware assumes the worst - that the computer is dangerously overheated - and therefore throttles back the CPU by 80% and runs the fans at full blast.
Fixing it on Mac required a number of third-party tools and flashing a custom firmware. I then installed Linux on the device - about ten lines of script that read from the working temp sensor on the CPU die and write a scaled value to /sys/ in response.
So much flippin easier on Linux.
Peruvian_Skies@sh.itjust.works · 2 pts · 220d
I just said that Docker Desktop handles it. I've never used a Mac so I don't know for sure what's going on under the hood there but I imagine that everything they can do the same between Mac and Linux, they do. It's easier that way.
MCHEVA4EVA@lemmy.world · 2 pts · 220d
AIO is a fun one to setup. I found it much easier with portainer. The thing that always catches me with Docker is the permissions after it's setup. I had nextcloud up for a week I could access my external hdd over Webdav and nothing else haha.
Fedop@slrpnk.net · 5 pts · 219d
Just in case, I have to share this great explanation of the term "everything is a file": https://unix.stackexchange.com/questions/141016/a-laymans-explanation-for-everything-is-a-file-what-differs-from-windows#141020
This really helped clear things up for me, the main idea is that everything is represented by the filesystem, so you can use the same file-manipulation tools on a ton of systems.
MrSoup@lemmy.zip · 3 pts · 220d
Until you discover dbus