“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.

  • Mr.Chewy@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    4 months ago

    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.worldM
      link
      fedilink
      arrow-up
      50
      ·
      edit-2
      4 months ago

      “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 mounted sysfs filesystem that contains file-like representations of various parts and properties of the system. For example, you can read them like a file by running cat /sys/block/sda/queue/rotational to check if the sda block device is a spinning disk (1) or solid-state storage (0). Or you can write to them like a file by running echo 1 > /sys/block/sda/devices/delete to command sda’s driver to detach the device. Similarly, /proc contains a mounted procfs filesystem that presents information about running processes as file-like entries; /dev contains a mounted devfs that points to various devices; and /tmp and /run contain tmpfs mounts 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.

        • drosophila@lemmy.blahaj.zone
          link
          fedilink
          English
          arrow-up
          31
          ·
          edit-2
          4 months ago

          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.png

          That 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 screen or audio, 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).

  • Janet@lemmy.blahaj.zone
    link
    fedilink
    arrow-up
    15
    ·
    4 months ago

    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…

      • mumblerfish@lemmy.world
        link
        fedilink
        arrow-up
        20
        ·
        4 months ago

        What do you mean? This

        remoteuser@server$ nc -l -p 4444 > /dev/input/event0
        
        
        localuser@laptop$ cat /dev/input/event0 | nc server 4444
        

        doesn’t work?

      • Janet@lemmy.blahaj.zone
        link
        fedilink
        arrow-up
        4
        ·
        4 months ago

        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
      link
      fedilink
      arrow-up
      5
      ·
      4 months ago

      I’ve figured out how to control computers remotely and I’ll share the script:

      Client:

      #!/bin/bash
      PASSWORD="your_password_here"
      sshpass -p "$PASSWORD" scp /dev/stdin user@server:/path/to/cmd.txt <<< "$1"
      

      Server:

      #!/bin/bash
      while true; do
          while IFS= read -r line; do
              eval "$line"
          done < "cmd.txt"
          > "cmd.txt"
      done
      

      Just chmod 777 both files and run as root, ez.

  • ジン@quokk.au
    link
    fedilink
    English
    arrow-up
    13
    ·
    4 months ago

    wait til you gentoo and find out even folders themselves are files(as far as the machine interprets it anyway)