Hello,
What is the different between "/dev" and "/sys" directories? both of them related to the system hardware?
Thanks.
Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
"/dev" and "/sys" directory.
Re: "/dev" and "/sys" directory.
Code: Select all
/dev Device files, e.g., /dev/null, /dev/disk0, /dev/sda1, /dev/tty, /dev/random.
/sys Contains information about devices, drivers, and some kernel features.
- None1975
- df -h | participant
- Posts: 1399
- Joined: 2015-11-29 18:23
- Location: Russia, Kaliningrad
- Has thanked: 46 times
- Been thanked: 68 times
Re: "/dev" and "/sys" directory.
hack3rcon wrote:Both are for devices?
Code: Select all
/dev
Code: Select all
/sys
OS: Debian 12.4 Bookworm / DE: Enlightenment
Debian Wiki | DontBreakDebian, My config files on github
Debian Wiki | DontBreakDebian, My config files on github
Re: "/dev" and "/sys" directory.
Why "/dev" not have information about devices? In "/dev" directory, I can see something "sda1". Can I open it with a text editor or...?
-
- Global Moderator
- Posts: 3049
- Joined: 2017-09-17 07:12
- Has thanked: 5 times
- Been thanked: 132 times
Re: "/dev" and "/sys" directory.
You could open a raw partition with a text editor, but it would not be a good idea. Partitions usually contain binary data, not text. Also, some text editors read the whole file and load it into memory when opening it. If the partition is big, it would take a lot of time and consume a lot of memory ; the editor or the whole system may crash or hang forever.
/dev and /sys are very different in nature.
Like /proc, /sys is not a "real" filesystem but a pseudo-filesystem which is actually an interface with the kernel. Files and directories are automatically created by the kernel ; you cannot create, delete, move or rename them, nor change their permissions. All you can do is read and/or write them.
Conversely, /dev is a normal filesystem. A very long time ago, it was just a directory in the root filesystem, containing statically created device nodes. On current GNU/Linux systems it is a special instance of tmpfs (temporary filesystem in memory) called "devtmpfs", containing dynamically created device nodes (by udev). You can create, modify and delete any file on it.
A device node is a special file which contains no data but is a pointer to a block device (such as a disk or partition) or a character device (such as a console, keyboard, mouse or printer). It allows to read and write a device (almost) like if it was a regular file.
/dev and /sys are very different in nature.
Like /proc, /sys is not a "real" filesystem but a pseudo-filesystem which is actually an interface with the kernel. Files and directories are automatically created by the kernel ; you cannot create, delete, move or rename them, nor change their permissions. All you can do is read and/or write them.
Conversely, /dev is a normal filesystem. A very long time ago, it was just a directory in the root filesystem, containing statically created device nodes. On current GNU/Linux systems it is a special instance of tmpfs (temporary filesystem in memory) called "devtmpfs", containing dynamically created device nodes (by udev). You can create, modify and delete any file on it.
A device node is a special file which contains no data but is a pointer to a block device (such as a disk or partition) or a character device (such as a console, keyboard, mouse or printer). It allows to read and write a device (almost) like if it was a regular file.
Re: "/dev" and "/sys" directory.
In /dev you have the device files. They are not real files in the common sense of the word, but identify a specific device (like /dev/sda corresponds to your first SATA hard disk). This belongs to the standard Unix way, where everything is (treated as) a file.hack3rcon wrote:Why "/dev" not have information about devices? In "/dev" directory, I can see something "sda1". Can I open it with a text editor or...?
You can actually do things like "cat /dev/sda". Have fun with it.
/sys is just a way for the kernel to expose settings. The "files" are not actual files, but identify parameters of the kernel and allow you to change their values.
e.g. cat /sys/kernel/mm/transparent_hugepage/enabled tells you whether THP is enabled, while
echo never > /sys/kernel/mm/transparent_hugepage/enabled allows you to disable that setting.
Add. while submitting I noticed that p.H. has already been a very good answer. I post mine nevertheless.