Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

  1. Home
  2. UNIX(Linux)Beginner - Key Directories and Listing Contents (ls)

Key Directories and Listing Contents (ls) - Images: Japanese

Hey there, everyone!

Let's continue with some important directories in UNIX-based OSes, along with the basics of the 'ls' command.

First up: 'root directory'. The root directory is the very top of the filesystem (directory tree) — the highest-level directory from which everything else branches.

To navigate to the root directory using the 'cd' command:

cd /

Since it's the topmost directory, the path is just '/'. After navigating there, running 'pwd' confirms it.

[root@localhost ~]# cd /
[root@localhost ~]# pwd
/

Just a lone '/' — that's correct. You're at the root directory.

Now that we're at the root directory, let's explore the important directories that live here. Key directories in UNIX-based OSes tend to be located directly under the root directory or one level below, so let's take a look.

To see what's in the current directory, use the ls command mentioned briefly in the previous article. It lists the contents of the current directory.

For a basic listing with no options or arguments, just type ls.

[root@localhost ~]# ls

You should get output like this.

[root@localhost /]# ls
bin  boot  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var

These are all directories, and the ones sitting directly under the root directory are significant. Here's a rundown of each one.

/binStores the most essential system commands. Commands added later don't normally go here.
/bootContains files used during the boot process. "Boot" refers to the process of initializing all connected devices when the system powers on.
/devMainly holds storage devices and other hardware devices. UNIX treats devices as file-like objects, so when a device is connected, it appears here as a file-like entry.
/etcStores configuration files. Virtually every piece of software puts its config files here, so it tends to get cluttered.
/homeHome directories for general users. Each user gets a subdirectory here — for example, user 'hsakurama' would have the home directory '/home/hsakurama'. This is where the user starts when they log in.
/libContains files used by the commands in /bin and /sbin. Primarily for commands running in 32-bit mode.
/lib64Same as /lib, but for 64-bit commands.
/lost+foundWhere system backup files are stored.
/mediaFor CD drives, DVD drives, floppy drives, and similar media. Like /dev, these devices appear here as file-like objects.
/mntFor temporary mounts. "Mounting" means making a connected device recognizable and usable by the OS. This directory is for temporary use — for example, a USB drive plugged in would appear here. The difference from /media is the "temporary" aspect.
/optWhere programs installed via package managers go. A package manager is a tool that makes installing commands and software straightforward. More on this in a later article.
/procHolds running processes with assigned IDs. A "process" is roughly a program that's currently executing. UNIX assigns an ID to each process and manages them — those IDs appear here.
/rootThe home directory exclusively for the 'root' user. Note: "root directory" refers to '/' — this directory is specifically "root user's home directory." The reason root's home isn't at '/home/root' is that /home is accessible to many users, and placing root's home there would require loosening its permissions to match — a security problem. Keeping /root separate means it's only accessible by root, which is much safer.
/sbinHolds system-critical commands. Because they're critical, these are mainly root/admin commands. The 'shutdown' command from earlier lives here. Don't touch the contents of this directory.
/tmpTemporary file storage. Files here are automatically deleted after a reboot or after a certain amount of time. "tmp" is short for "temporary" — you'll also see it used as a variable name in code for the same reason.
/usrContains files and commands shared by all general users. Think of it as "files and commands everyone can use." Inside /usr, you'll find /usr/bin, /usr/lib, and so on — these work similarly to their counterparts directly under the root directory. For example, /bin holds core commands, and /usr/bin holds "shareable core commands".
/varVariable file storage. Unlike /tmp, files here aren't automatically deleted on reboot. Log files and temporary system data live here. Web server software by default often stores HTML files and similar content under /var/www — the reasoning being that those files are updated frequently and treated as variable data.

That's quite a list.

You don't need to memorize all of these right away — and you don't really have to. But knowing what each directory is for and how it's used will make a lot of things click faster. Glance back at this table occasionally, and you'll internalize it naturally as you use the system more.

Keep in mind that directory structures vary across different OSes — knowing CentOS's layout doesn't automatically transfer to every other UNIX-based system. That said, they tend to follow similar patterns.

When you run 'ls' in CentOS, the output often appears color-coded. Those colors have meaning — they tell you what kind of data each entry is.

There are many color patterns and they vary somewhat by OS, but the common ones to know are:

  • White — regular file
  • Blue — directory
  • Cyan (light blue) — symbolic link
  • Red — symbolic link with a broken target (the link destination doesn't exist)

Just remember those four and you'll be set.

'Symbolic link' is roughly equivalent to a Windows shortcut.

The 'ls' command doesn't output colors by default — but modern UNIX-based OSes are often preconfigured to show colors automatically, so a plain 'ls' will typically produce colored output without any extra flags.

If you ever want to explicitly request colored output from the original ls, you'd use the --color option, like this. But you don't need to memorize this one.

[root@localhost /]# ls --color

Alright, that covers the major UNIX directories and the basics of the ls command. Starting from the next article, we'll get into file and directory operations. See you there!

This article was written by Sakurama.

Author's beloved small mammal

桜舞 春人 Sakurama Haruto

A Tokyo-based programmer who has been creating various content since the ISDN era, with a bit of concern about his hair. A true long sleeper who generally feels unwell without at least 10 hours of sleep. His dream is to live a life where he can sleep as much as he wants. Loves games, sports, and music. Please share some hair with him.

If you find any errors or copyright issues, please .