Getting around in Linux directories

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
1,207
Reaction score
2,239
Credits
3,467
Now's the time to learn a little bit about the Linux file system. We'll learn about where Linux puts it stuff, where to find stuff and a little bit about what that stuff is.

When you're running Linux and start to type things on that black screen, you are using a shell. Any operating system uses a shell to get commands from the keyboard to the computer. It's a lot easier than punching holes in cards like they used to do in the old days. There are actually programs for Linux where you talk through a microphone and Linux will carry out commands that you've programmed in advance. It's really cool. For now, though, we'll concentrate on the keyboard. The most popular shell used for Linux is the bash shell. bash means "Bourne Again Shell". It is a free version of the Bourne shell and uses a little play on words, as you can see.

Getting in and out of directories with 'cd'
We saw a few commands in the last lesson, but we didn't go into them much. We will handle a lot of commands in more detail in later lessons. This lesson will cover those commands which you will need to see what's under Linux's hood.

The first one we should look at is 'cd'.

Code:
cd

Will get you in and out of directories. CD = Change Directory. Pretty simple eh?

Try this one:
Code:
cd /

This will get you into the 'root' or main directory. It's the directory of directories, the king of kings, your show of shows. The root directory shouldn't be confused with root's directory. That is /root.

Now type this:

Code:
ls

You will probably see something like this:


Code:
boot
cdrom
bin
dev
etc
floppy
home
lib
lost+found
mnt
opt
proc
root
sbin
tmp
usr
var


They will be blue in color. Those are directories.

The /bin directory


Code:
cd bin
ls


This is the famous bin/ directory. You know, I have always felt this one was misnamed. For example, when people say, 'That's no good, throw it in the bin'. Actually, bin/ is one of the most important directories in Linux. You'll find all of the most used commands there. Right now you should be seeing a lot of red (or green, depending on your version of Linux). Those are programs.

The /etc directory

Now let's look at another directory. There's a long way and a short cut. First the long way.


Code:
cd ..   
cd etc


Or you can just type:

Code:
cd /etc

Anyway, you are now in the etc/ directory. This houses most of the configuration files for Linux. lilo.conf, the file that tells you which OS to boot is in there.
you'll see: lilo.conf

And you don't even have to type the whole thing. You could just type 'ls li' and push the tab key. Linux will type the rest for you. Isn't that cool!

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


Code:
cd /dev
ls


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

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]
or, just:
Code:
cd

Code:
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

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
 


@Rob has been a little busy the last 5 or 6 years, but he'll get to a TOC eventually :)

(Wizard appears in a puff of smoke, bearing suggestions on stone tablets, drops them, they smash, oh well)

G'day @Aide O. A. and welcome to linux.org :)

There are 30 tutes spread over two pages, accessed from here

https://www.linux.org/forums/linux-beginner-tutorials.123/

At the bottom of your page is a feature "Thread Display Options", which brings up as per my screenshot

4D90Izo.png


... which may help you sort a little.

If you have any questions, Getting Started or General Linux are good places to begin.

Cheers and Avagudweegend

Chris Turner
wizardfromoz - that's DownUnder
 
i have a question...please see the attachment and waiting for your feedback .
why cannot create directory 'd2' : permission denied ?
 

Attachments

  • IMG_20181122_144224.jpg
    IMG_20181122_144224.jpg
    3.6 MB · Views: 1,822
I think the problem lies with
Code:
cd  /home

If you do an ls after that you will see that you are outside your Home and not inside your Home.

To make a directory outside your Home you must have superuser powers i.e. you must be Root.

Just do mkdir d1
Don't do cd /home
The do mkdir d2

...unless you want to make d2 outside your Home, then you will need...
(Either su or sudo) mkdir2
 
Firstly, thank you very much for these tutorials.

lilo.conf, the file that tells you which OS to boot is in there.

I guess the reason I don't have that file in my /etc/ directory is because I only have Linux OS installed. Am I right?
 
Thanks. I find your explanation very understandable!!
 
Last edited by a moderator:
  • Like
Reactions: Rob
Nope :)

G'day Sergio and welcome to linux.org.

Rob's article was written nearly 6 years ago. Lilo is no longer supported (phased out in 2016).

If you wish, you can read about it here.

https://wiki.archlinux.org/index.php/LILO

Cheers

Chris Turner
wizardfromoz
If you say so, i have tried to run the code but nothing popped out. Thanks for the relief
 
this are wonderful how can i got a pdf document , help me am a new commer
 
Understandable ! Thanks again for the tutorial.
One thing, what's wrong with linux naming system it's weird >>> - lilo.conf ? ? - bin - an important directory? --> Really? o_O
Better read tutorials when you're li'l drunk !! Will catch up little humor thingy !!
 
well there is a quirky sort of under current of humor in the Linux community. I prescribte to it but it mostly goes over most peoples heads. But take Linus Torvalds you might have heard he took time off to mediate on his navel; well reportedly he named the code version control "git" after his alter ego ! The linux system comes out with a few odd ones now and again , when you go to root user you see things like " with power comes great responsibilty" that sort of thing . I once got from my Slackware " you have commited a mis-demeanor and it will be reported ! " or words to that effect
 

Staff online

Members online


Top