Linux Commands | Introduction to Linux | Linux Directories

Drives

Windows has the concept of drives such as “C:” and “D:”, but Unix/Linux does not. Additional hard disks, CD-ROMs, and similar devices are accessed with path names such as /dev/hda and /dev/cdrom.

Directories

A directory is almost the same as what Windows calls a “folder”. Windows separates directories (folders) with backslashes (\), as in \Program Files\Microsoft Office\..., while Unix/Linux uses slashes (/), as in /home/devkuma/public_html/index.html.

home
└── devkuma
    └── pubilc_html
        ├── image
        │   ├── aaa.gif
        │   └── bbb.gif
        └── js
            ├── xxx.js
            └── zzz.js

Root Directory

The top directory in the directory hierarchy is called the root directory. The first slash (/) represents the root directory.

/

Home Directory

In Unix/Linux, each user is assigned a separate directory. This is called the “home directory”. Common examples include /home/{user name} on Linux, /Users/{user name} on Mac OS X, and /usr/{user name} on older Unix-like operating systems, although other directories may also be used.

/home/devkuma

Current Directory

The directory you are currently in is called the current directory. Running the pwd command shows which directory you are currently in. For example, if you run pwd while inside the public_html directory, it is displayed as follows.

/home/devkuma/public_html

Parent Directory

Every directory except the root directory has a parent directory. The parent directory is represented by ... ../xxx.html means xxx.html in the parent directory of the current directory. /home/users/../users/devkuma has the same meaning as /home/users/devkuma.

Path Names

A path name represents the location of a file in a directory, such as /home/foo/index.html. This indicates a file named index.html inside the foo directory inside the home directory.

Absolute Path Name

If a path name starts with a slash (/), it represents a relative position from the root directory. This is called an absolute path name or a full path name.

This may differ slightly from how URLs are described. For example, the absolute path name /home/devkuma/public_html/index.htm may be mapped to the virtual path name /index.htm in a URL.

Also, with services such as BIGLOBE, the root directory may differ between FTP login and CGI script execution, so care is required.

Relative Path Name

If a path name starts with something other than a slash (/), it represents a location relative to the current directory. This is called a relative path name.

For example, if the current directory is /home/users, writing devkuma/index.html points to /home/users/devkuma/index.html.

Virtual Path Name

This is more of a WWW term than a UNIX term. In http://server-name/path-name, the /path-name part is called a virtual path name. As described above, it differs from an absolute path name.

Major Directories

/

The top-level directory above all files and directories on Linux.
It is the most important directory and forms the foundation of the system.
The / at the beginning of a string represents the top level, and later / characters are directory separators. The final / at the end of a string is usually omitted.

/boot

Contains the Linux kernel memory image and files needed during the boot process.

/bin

Contains basic Linux command executable files.

/root

The home directory of the superuser root.

/home

The directory where home directories for users other than the administrator are created.
When a regular user account is created, it is usually created under this directory by default.

/etc

Contains data files for system and user administration and administrator commands.
It contains system configuration files and account information, making it the first directory to back up.

/dev

Contains device files that provide an interface between file systems and hardware.
It includes device files for floppy disks, hard disks, CD-ROMs, and other devices.

/lib

Contains libraries for various languages.
It is the system shared library directory, where library files required by programs exist.

/mnt

A directory used for remote devices.
Mount points for devices used by the system exist here.
Nothing is displayed before mounting, but when a specific device is mounted, its contents appear.

/media

A directory used for local devices.

/sbin

Contains command files for system operation and administration, and only administrators can use them. Commands needed during the boot process are here, while larger commands needed during normal operation are in /usr/sbin.

/usr

Contains most of the files needed for Linux to run, as well as packages installed by users of each account.
Large files are often found here.

/proc

A virtual file system that provides kernel and process information and is stored in memory.
It is a directory representing process information; when checking process status with the ps command, the contents included in this directory are shown.

/proc/cpuinfo

Contains information about the CPU.

/proc/devices

Contains information about device drivers.

/proc/kmsg

Contains messages output by the kernel.

/proc/meminfp

Contains information about physical and virtual memory.

/proc/net

Contains network information.

/tmp

A directory that stores temporary files used for a short time. PHP file uploads are first stored here, and session information and similar temporary data are also kept here.

/var

A variable file directory where files created or changed during system operation exist.
It records mail, spool files, name server data, and other security-related information.

/var/log

A directory where log files exist.

  • /var/log/cron : Scheduled task logs
  • /var/log/maillog : Mail logs
  • /var/log/messages : System message logs
  • /var/log/secure : Access and authentication logs
  • /var/log/spooler : Printer connection logs
  • /var/log/dmesg : System device and file system boot message logs
  • /var/log/boot.log : Logs for checking system device and daemon execution status during boot

/var/spool/mail

A directory where sent and received mail is stored.