In Linux, Everything is a File

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,263
Reaction score
2,431
Credits
3,941
Everyone knows what a files is... It's that "photo", "document", or "music" that you use. Programs are made of files, in fact, the whole Linux operating system is just a collection of files... But, now for the weird part. Not only is that digital photo that you uploaded to your computer a file, but your monitor is a file too! You see, in Linux, everything is a file! WOW!!! How can that be? Let's try to explain it.


The /dev directory

You'll see a lot of yellow outlined in black. These are the devices that your system uses or can use. Everything is considered a file in Linux, so your hard disk is kept track of as a file that sits there. If you're using an IDE hard drive (as opposed to SCSI), your hard drive will be known as /dev/hda. Don't delete that, because your hard disk will spin around, come jumping out of your computer, land on the floor and spill out ooze all over the place. No, not really. You will probably not have to look in /dev very much, so don't worry about that.

The /boot directory

Code:
cd /boot [ENTER]
Will get you into the /boot directory. You will not find any boots or shoes or footwear of any kind there. That's where the Linux kernel usually is. Power users may change the location of the kernel for reasons of their own (they may prefer /shoe), but it is normally placed there on most systems. You will eventually have to use this directory, because you may need to use two or more different types of kernels in the future. That will be taken up in a more advanced lesson.



root's directory /root
If you are not working as 'root' and you type cd /root, you will be taken to the directory /root. However, you won't be able to do anything while you're there. Root's home directory is a restricted area for everybody else. Linux response is sort of like, 'You don't have to know that'. Users' home directories are under certain restrictions for other users as well.


The /sbin directory

/sbin is another one of those off-limits directories. You may look, but you can't touch. This directory is like /bin in that it has frequently used programs in it, but they're only meant to be used by root. 'Shutdown' is in there. Only root can shutdown the system. If a user other than root tried to shutdown the system, he or she would get a message saying that only root can do that. Then that person would be followed by the secret police for three months.



The /tmp directory

/tmp is a directory that is used to store temporary files, as the name may suggest. You will find later on that when you use a Windows-style system with Linux like KDE, this window manager will create files there for temporary use. When you double click on an icon of a photo, the photo comes up for you to see but a temporary file is created while you're looking at the photo. The temporary file is deleted when you close the KDE image program. It's mainly the programs that work under a windows manager that take advantage of this directory.


The /var directory

/var is a directory for certain files that may change their size (i.e. variable size) For example, there are a few excellent databases for Linux. One is called MySQL. Normally, MySQL keeps its data in a subdirectory of /var called /var/mysql/. If I had an e-commerce website, I would have a database to register purchases. That database would obviously grow in size. And if it didn't then I'd be in trouble. It is also the normal place where email servers store their incoming mail. Again, email varies in size as well.


The /lib directory

/lib is for library files. That's where the name /lib comes from. Programs may use libraries to carry out their functions. Different programs use the same libraries, so Linux will store them here so that every program knows where to find them. You will probably not have to worry about this directory much unless you start getting messages like 'can't find shared library...'. That will sometimes happen when you've downloaded a program and had to compile it yourself from source. Even then, getting what are known as "dependency" problems are quite rare. Most programs, even when compiled from source, usually have a pre-configuration program that makes sure that they can find what libraries they "depend" on to run. If they don't, they'll tell you that you can't install the program.

The /home directory (home sweet home!)

We talked about /home before. This is a directory for storing users' personal files. All of us have certain preferences for using programs. These preferences are usually included in configuration files which are also stored in users' home directories. Most of these files start with a '.' (period/dot).

If you go to your home directory, '


Code:
cd /home/[username]
ls -a


You will see these files.

What's left

Most installations of Linux will also provide these directories:

/mnt
/cdrom
/floppy

These shouldn't contain anything. Later on, we'll explain in more detail what these are for. Let's just say that in Linux, if you want to see what's on a floppy disk or a CD, you're not going to be able to just click on an 'a:' icon or a 'd:' icon. You're going to do

Code:
cd /floppy or cd /cdrom

If you try that now you probably won't see anything. As I said, more about these directories later in the course.

Well, we've looked under Linux's hood, so to speak. In the next lesson, we'll take her for a little spin.
 


So whilst using the software, everything is a command, and for basic things, there are just different commands?
 
well, everything is a file... and there are commands to manipulate the files..

Code:
mv /dir1/file1 /dir2/[code]

uses the command mv (move) to move file1 from dir1 to dir2.

Exactly!

As Rob has said, "Everything is a file" just ties into the fact that in any UNIX-based operating system (including Linux) EVERY single thing is represented as a file somewhere in the file-system. Even things like devices and processes, which people might not necessarily think of as a file.

for basic things, there are just different commands?
What you have mentioned at the end of your comment is sort of true. You have hit upon something. But it doesn't really relate to the "everything is a file" concept that Rob was talking about. It has more to do with the "UNIX philosophy", as defined by Ken Thompson - one of the original authors of UNIX.

The Linux kernel, GNU software and many other programs used in Linux distributions are very much rooted in the UNIX philosophy - because many of them were originally designed to be part of a UNIX-like system.

The basic idea of the UNIX philosophy is that programs should be simple, short, clear, modular and perform a single task well.

So yes, when you are in the terminal on any UNIX-like OS- there are a lot of little programs/commands which do many different things. Most of these programs do extremely specific things. On their own, they might have very limited uses. But if you use pipes and input/output redirection, you can chain several of these simple commands together and perform all kinds of complex tasks with a single line.

Because of this, the Linux terminal is an extremely powerful and flexible tool.

As a simple example of using pipes and output redirection - Lets say I've ripped a CD to .ogg and I want to create a .m3u playlist for the album. All of the tracks have the track-number included in their filenames.
e.g. track1.ogg, track2.ogg etc.

After navigating into the directory containing the files, I could do it like this:
Code:
ls *.ogg | sort -V > playlist.m3u

This lists all of the .ogg files and pipes | the results to the sort command.

The sort command sorts the listing using natural version numbers (the -V option).
NOTE: If I sorted alphabetically, tracks 11..19 would appear before track 2 in the playlist. Likewise tracks 21..29 (assuming there were that many tracks) would appear before track 3.... That would never do! XD The -V option will ensure that the numbered tracks are listed in the correct sequence.

Finally, the output of the sort command is then redirected via output redirection >, to a file called playlist.m3u.

Job done!

By chaining two simple commands together and using output redirection, I have created a playlist of files!
 
Last edited:
Everyone knows what a files is... It's that "photo", "document", or "music" that you use. Programs are made of files, in fact, the whole Linux operating system is just a collection of files... But, now for the weird part. Not only is that digital photo that you uploaded to your computer a file, but your monitor is a file too! You see, in Linux, everything is a file! WOW!!! How can that be? Let's try to explain it.


The /dev directory

You'll see a lot of yellow outlined in black. These are the devices that your system uses or can use. Everything is considered a file in Linux, so your hard disk is kept track of as a file that sits there. If you're using an IDE hard drive (as opposed to SCSI), your hard drive will be known as /dev/hda. Don't delete that, because your hard disk will spin around, come jumping out of your computer, land on the floor and spill out ooze all over the place. No, not really. You will probably not have to look in /dev very much, so don't worry about that.

The /boot directory

Code:
cd /boot [ENTER]
Will get you into the /boot directory. You will not find any boots or shoes or footwear of any kind there. That's where the Linux kernel usually is. Power users may change the location of the kernel for reasons of their own (they may prefer /shoe), but it is normally placed there on most systems. You will eventually have to use this directory, because you may need to use two or more different types of kernels in the future. That will be taken up in a more advanced lesson.



root's directory /root
If you are not working as 'root' and you type cd /root, you will be taken to the directory /root. However, you won't be able to do anything while you're there. Root's home directory is a restricted area for everybody else. Linux response is sort of like, 'You don't have to know that'. Users' home directories are under certain restrictions for other users as well.


The /sbin directory

/sbin is another one of those off-limits directories. You may look, but you can't touch. This directory is like /bin in that it has frequently used programs in it, but they're only meant to be used by root. 'Shutdown' is in there. Only root can shutdown the system. If a user other than root tried to shutdown the system, he or she would get a message saying that only root can do that. Then that person would be followed by the secret police for three months.



The /tmp directory

/tmp is a directory that is used to store temporary files, as the name may suggest. You will find later on that when you use a Windows-style system with Linux like KDE, this window manager will create files there for temporary use. When you double click on an icon of a photo, the photo comes up for you to see but a temporary file is created while you're looking at the photo. The temporary file is deleted when you close the KDE image program. It's mainly the programs that work under a windows manager that take advantage of this directory.


The /var directory

/var is a directory for certain files that may change their size (i.e. variable size) For example, there are a few excellent databases for Linux. One is called MySQL. Normally, MySQL keeps its data in a subdirectory of /var called /var/mysql/. If I had an e-commerce website, I would have a database to register purchases. That database would obviously grow in size. And if it didn't then I'd be in trouble. It is also the normal place where email servers store their incoming mail. Again, email varies in size as well.


The /lib directory

/lib is for library files. That's where the name /lib comes from. Programs may use libraries to carry out their functions. Different programs use the same libraries, so Linux will store them here so that every program knows where to find them. You will probably not have to worry about this directory much unless you start getting messages like 'can't find shared library...'. That will sometimes happen when you've downloaded a program and had to compile it yourself from source. Even then, getting what are known as "dependency" problems are quite rare. Most programs, even when compiled from source, usually have a pre-configuration program that makes sure that they can find what libraries they "depend" on to run. If they don't, they'll tell you that you can't install the program.

The /home directory (home sweet home!)

We talked about /home before. This is a directory for storing users' personal files. All of us have certain preferences for using programs. These preferences are usually included in configuration files which are also stored in users' home directories. Most of these files start with a '.' (period/dot).

If you go to your home directory, '


Code:
cd /home/[username]
ls -a


You will see these files.

What's left

Most installations of Linux will also provide these directories:

/mnt
/cdrom
/floppy

These shouldn't contain anything. Later on, we'll explain in more detail what these are for. Let's just say that in Linux, if you want to see what's on a floppy disk or a CD, you're not going to be able to just click on an 'a:' icon or a 'd:' icon. You're going to do

Code:
cd /floppy or cd /cdrom

If you try that now you probably won't see anything. As I said, more about these directories later in the course.

Well, we've looked under Linux's hood, so to speak. In the next lesson, we'll take her for a little spin.
 
Everyone knows what a files is... It's that "photo", "document", or "music" that you use. Programs are made of files, in fact, the whole Linux operating system is just a collection of files... But, now for the weird part. Not only is that digital photo that you uploaded to your computer a file, but your monitor is a file too! You see, in Linux, everything is a file! WOW!!! How can that be? Let's try to explain it.


The /dev directory

You'll see a lot of yellow outlined in black. These are the devices that your system uses or can use. Everything is considered a file in Linux, so your hard disk is kept track of as a file that sits there. If you're using an IDE hard drive (as opposed to SCSI), your hard drive will be known as /dev/hda. Don't delete that, because your hard disk will spin around, come jumping out of your computer, land on the floor and spill out ooze all over the place. No, not really. You will probably not have to look in /dev very much, so don't worry about that.

The /boot directory

Code:
cd /boot [ENTER]
Will get you into the /boot directory. You will not find any boots or shoes or footwear of any kind there. That's where the Linux kernel usually is. Power users may change the location of the kernel for reasons of their own (they may prefer /shoe), but it is normally placed there on most systems. You will eventually have to use this directory, because you may need to use two or more different types of kernels in the future. That will be taken up in a more advanced lesson.



root's directory /root
If you are not working as 'root' and you type cd /root, you will be taken to the directory /root. However, you won't be able to do anything while you're there. Root's home directory is a restricted area for everybody else. Linux response is sort of like, 'You don't have to know that'. Users' home directories are under certain restrictions for other users as well.


The /sbin directory

/sbin is another one of those off-limits directories. You may look, but you can't touch. This directory is like /bin in that it has frequently used programs in it, but they're only meant to be used by root. 'Shutdown' is in there. Only root can shutdown the system. If a user other than root tried to shutdown the system, he or she would get a message saying that only root can do that. Then that person would be followed by the secret police for three months.



The /tmp directory

/tmp is a directory that is used to store temporary files, as the name may suggest. You will find later on that when you use a Windows-style system with Linux like KDE, this window manager will create files there for temporary use. When you double click on an icon of a photo, the photo comes up for you to see but a temporary file is created while you're looking at the photo. The temporary file is deleted when you close the KDE image program. It's mainly the programs that work under a windows manager that take advantage of this directory.


The /var directory

/var is a directory for certain files that may change their size (i.e. variable size) For example, there are a few excellent databases for Linux. One is called MySQL. Normally, MySQL keeps its data in a subdirectory of /var called /var/mysql/. If I had an e-commerce website, I would have a database to register purchases. That database would obviously grow in size. And if it didn't then I'd be in trouble. It is also the normal place where email servers store their incoming mail. Again, email varies in size as well.


The /lib directory

/lib is for library files. That's where the name /lib comes from. Programs may use libraries to carry out their functions. Different programs use the same libraries, so Linux will store them here so that every program knows where to find them. You will probably not have to worry about this directory much unless you start getting messages like 'can't find shared library...'. That will sometimes happen when you've downloaded a program and had to compile it yourself from source. Even then, getting what are known as "dependency" problems are quite rare. Most programs, even when compiled from source, usually have a pre-configuration program that makes sure that they can find what libraries they "depend" on to run. If they don't, they'll tell you that you can't install the program.

The /home directory (home sweet home!)

We talked about /home before. This is a directory for storing users' personal files. All of us have certain preferences for using programs. These preferences are usually included in configuration files which are also stored in users' home directories. Most of these files start with a '.' (period/dot).

If you go to your home directory, '


Code:
cd /home/[username]
ls -a


You will see these files.

What's left

Most installations of Linux will also provide these directories:

/mnt
/cdrom
/floppy

These shouldn't contain anything. Later on, we'll explain in more detail what these are for. Let's just say that in Linux, if you want to see what's on a floppy disk or a CD, you're not going to be able to just click on an 'a:' icon or a 'd:' icon. You're going to do

Code:
cd /floppy or cd /cdrom

If you try that now you probably won't see anything. As I said, more about these directories later in the course.

Well, we've looked under Linux's hood, so to speak. In the next lesson, we'll take her for a little spin.
"Will get you into the /boot directory. You will not find any boots or shoes or footwear of any kind there."
This is a terrible disappointment. I would only go to a directory labelled "boot" if I thought there would be boots in there. Footwear, anyway. If they didn't have boots but gave me other footwear instead, I would think this was a walk-around.
 
Ok, so this part here: The sort command sorts the listing using natural version numbers (the -V option).
NOTE: If I sorted alphabetically, tracks 11..19 would appear before track 2 in the playlist. Likewise tracks 21..29 (assuming there were that many tracks) would appear before track 3.... That would never do! XD The -V option will ensure that the numbered tracks are listed in the correct sequence.

I have seen this happen, in a non-Linux OS, and would shake my head going, "WTH is up this thing!" Thank you both for expounding on this stuff, I'm just learning and trying to wrap my head around Linux.
 
So every thing is a file including the hard drive that holds the files, the keyboard, mouse, CPU, etc ..... hardware and software is a file.... so basically Linux is a BIG config file.... edit it as you wish!( just know what your doing first please )
 
Hi there!
Sorry for my English, if from time to time it will be unclear, it is not my native language.
In "beginner Linux tutorial" so many articles, is there the correct way where better to begin and continue consistently?
If there is no way, such as one(Intro) to ... etc, could you tell me in which direction to go, just I want completely understand 'what it is' in every the next part. Thank you! :)
 
Hi there!
Sorry for my English, if from time to time it will be unclear, it is not my native language.
In "beginner Linux tutorial" so many articles, is there the correct way where better to begin and continue consistently?
If there is no way, such as one(Intro) to ... etc, could you tell me in which direction to go, just I want completely understand 'what it is' in every the next part. Thank you! :)

From what I can see - the posts in the tutorials section are not in any particular order. Each post contains information about an individual Linux related topic. The order of the topics in the forum corresponds with the last time anybody posted comments/content in them. So posts with recent comments appear at the top.

Perhaps at some point @Rob or one of the admins here might be able to update the titles of each article to include a number to indicate the recommended reading order. Or maybe they could create a sticky-post at the top of each tutorials forum with links to each article in a recommended reading order.

But until then, it doesn't look like there is a set order. So perhaps take a look at some of the different topics and ask some questions if there is anything you do not understand.
 

Members online


Latest posts

Top