EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Linux Directory Structure

By Balaji SBalaji S

Home » Software Development » Software Development Tutorials » Linux Tutorial » Linux Directory Structure

Linux Directory Structure

Introduction to Linux Directory Structure

The structure of the Linux directory looks like a tree. This is very much different from that of the windows file system. Linux directory will look like /bin, /lib, etc. File Hierarchy System (FHS) is maintained by Linux Foundation. The FHS defines the structure and purpose of a particular Linux directory. Courtesy of this FHS we will find the same directory structure in most Linux distribution. In this, we will discuss the important and basic Linux directories.

Linux Directory

Below are the important and basic Linux directories:

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

1) / – Root

The base of Linux directory is the root. This is the starting point of FHS. Every directory arises from the root directory. It is represented by a forward slash (/). If someone says to look into the slash directory then they referring to the root directory.

2) /bin

This directory contains all the binary or executable program files. All the source code that we write is in a human-readable form. This source is converted into a machine-readable code. The binary file is nothing but strings of zeroes and ones. Another important thing is that applications, programs, and commands that we use are sometimes located in the /bin directory.

Example: ps, ls, ping, grep, cp.

3) /etc

The core configuration files are stored in /etc directory. It controls the behavior of an operating system or application. This directory also contains startup and shutdown program scripts that are used to start or stop individual programs.

Example: /etc/logrotate.conf, /etc/resolv.conf.

4) /home

The user’s home directory is stored under /home directory. Linux system often contains multiple user accounts. The home directory allows the users to separate their data from other users in the Linux Operating System. For example, if the user name of the account is john then the home directory will be /home/john. Here the john directory is known as subdirectory. A subdirectory is nothing but a directory which resides inside another directory.

5) /opt

The opt directory is used for installing application softwares from third-party vendors that are not available in the Linux distribution. Usually, the software code is stored in the opt directory and the binary code is linked to the bin directory so that all users can run that software. For example, Google Earth application doesn’t come under Linux distribution and it is installed in the /opt/google/earth directory.

6) /tmp

All the temporary files created by the system and the user are stored under this directory. A user can also store files under this directory. But remember that the contents of this directory are deleted whenever the system reboot or restarts. So do not store files in this directory that you want to store for a long time.

Popular Course in this category
Linux Training Program (16 Courses, 3+ Projects)16 Online Courses | 3 Hands-on Projects | 160+ Hours | Verifiable Certificate of Completion | Lifetime Access
4.5 (6,013 ratings)
Course Price

View Course

Related Courses
Kali Linux Training (3 Courses, 3+ Projects)Red Hat Linux Training Program (4 Courses, 1+ Projects)

7) /usr

This is called a user directory. This directory contains libraries, source code, binaries and documentation required for second-level programs. The binary files of a user is stored in /usr/bin and the binary files of the system are stored in /usr/sbin. The system libraries are stored in /usr/lib.

Example: useradd, atd, cron, userdel.

8) /var

The variable data files such as log files are located in the /var directory. File contents which tend to grow are located in this directory. This includes

  • /var/log: System log files generated by OS and other applications.
  • /var/lib: Contains database and packages files.
  • /var/mail: Contains Emails.
  • /var/tmp: Contains Temporary files needed for reboot.

Listing Directories in Linux

The files and directories in the Linux Operating System can be listed using the ls command. Let us see how to use ls command to list files and directories.

LS COMMANDS

Syntax:

$ ls [options] [directory/file]

When ls command is used without any options or arguments it simply displays all the files and directories that is present in the current directory that the user is working in.

Command:

$ ls

Output:

Linux Directory Structure Example 1

If you want to list files in a particular directory use the directory name as the argument and pass it to the ls command.

Command:

$  ls  /etc

Output:

Linux Directory Structure Example 2

We can likewise pass different directories to the command ls isolated by space.

Command:

$ ls /etc /lib /var

Output:

Linux Directory Structure Example 3

If the user doesn’t have read permission to a particular directory then the output will produce a message saying permission denied.

Command:

$ ls /root

Output:

Linux Directory Structure Example 4

There are numerous options in ls. Let us discuss about few basic options.

Long Listing Format

By default ls command displays only the name of the file and directory. The -l option makes the ls command to display files in a long listing format. Using the -l option prints the following information.

  • file type
  • file permission
  • number of hard links present in the file
  • file owner
  • file group
  • file size
  • date and time
  • file name

Take a look at the following example

Command:

$  ls -l  /etc/hosts

Output:

Linux Directory Structure Example 5

Here the – indicates a regular file.

  • r: permission for reading file.
  • w: permission for writing.
  • x: permission for executing the particular file.
  • s: setgid bit.
  • t: sticky bit.

The next couple of fields which is root, root indicates the owner and name of the group. 337 is the size of the file in bytes. The next field indicates the date and time when the file is last modified. The last column indicates the name of the file.

How to Display Hidden Files?

In Linux distribution a hidden file starts with dot (.). In order to display a file which is hidden use the command shown below.

$  ls  -la ~/

Output:

Hidden Files Example 6

$  ls  -a

Hidden Files Example 7

$  ls  -al

Hidden Files Example 8

Sorting the Output:

To sort the output file by size use.

$  ls  -S

To sort the file by date and time.

$  ls  -t

To sort the file by extension name.

$  ls  -X

To List Sub-directories Recursively.

$ ls –R

If we want to display the output in reverse order.

$ ls -ltr /var

Reverse Order Example 9

The above command will sort the files by last edited time in var directory and displays it in reverse order.

Recommended Article

This is a guide to Linux Directory Structure. Here we discuss an overview of the Linux directory structure and how to list the files or directories in Linux using LS commands. You can also go through our other suggested articles to learn more –

  1. Linux System Commands
  2. Linux Distributions
  3. Linux Create File
  4. Linux uniq

Linux Training Program (16 Courses, 3+ Projects)

16 Online Courses

3 Hands-on Projects

160+ Hours

Verifiable Certificate of Completion

Lifetime Access

Learn More

0 Shares
Share
Tweet
Share
Primary Sidebar
Linux Tutorial
  • Linux Commands
    • CAT Command in Linux
    • PS command in Linux
    • Mkdir Command in Linux
    • rmdir command in Linux
    • mv command in Linux
    • Linux rm Command
    • CHMOD Command in Linux
    • Zip Command in Linux
    • Linux Route Command
    • SCP Command in Linux
    • du Command in Linux
    • Less Command in Linux
    • Copy Command in Linux
    • Head Command in Linux
    • Help Command in Linux
    • Linux History Command
    • hostname Command in Linux
    • GREP Command in Linux
    • Linux Curl Command
    • Linux List Users
    • Linux List Directories
    • Linux Directory Permissions
    • Find Directory Linux
    • Linux User Permission
    • Linux Add User
    • Linux Delete User
    • Linux uniq
    • Linux Filter Commands
    • Linux sort Command
    • Linux Sort by Size
    • Remove dir Linux
    • Linux tr Command
    • Linux Touch Command
    • Linux More Command
    • Linux Cal Command
    • Linux OD
    • Linux Zcat
    • Linux tracepath
    • Linux Sleep
    • Linux bg Command
    • Linux WC
    • Linux Read
    • Linux Write
    • Linux Rename Command
    • Linux Free Command
    • Linux tac
    • Linux Shred
    • Linux wget
    • Linux Date
    • Linux Untar
    • Linux JQ
    • Linux Xargs
    • Linux Mount Command
    • Linux mdadm
    • Linux comm
    • Linux tee Command
    • Tail Command in Linux
    • Linux gzip
    • Linux Directory Structure
    • Linux Alias Command
    • Linux Inode
    • Linux Ping
    • Linux Watch Command
    • Linux Split Command
    • Linux Size
    • Linux Network Stack
    • Linux Diff Command
    • Vim Command in Linux
    • Linux nslookup
  • Basic
    • Introduction to Linux
    • What is Linux
    • Careers in Linux
    • How to Install Linux
    • How to Install Ubuntu
    • How to Install Ubuntu Server
    • How To Install Debian
    • Advantage Of Linux
    • What is Raid in Linux
    • What is Raid 5?
    • Raid 5 vs Raid 6
    • Careers in Linux Administration
    • What is Shell in Linux?
    • Bash Shell in Linux
    • Linux Emulator
    • Linux Operators
    • Linux Apps
    • Linux Keyboard Shortcuts
    • Linux Crontab
    • What is Raid Storage
    • What is Vmware
    • What is RedHat
    • What is Debian
    • Uses of Ubuntu
    • Career In RedHat
    • Linux Distributions
    • Linux From Scratch
    • Linux Format
    • Cheat Sheet Linux
  • Advanced
    • Install VMware
    • Install GRUB
    • Chown Command in Linux
    • Linux Network Command
    • Configuring Linux Network Environment
    • DNS Configuration in Linux
    • Linux Users
    • Create User in Linux
    • DHCP Server in Linux
    • FTP Server in Linux
    • Linux Regular Expression
    • IP Command in Linux
    • Set IP Address in Linux
    • Tar Command in Linux
    • Dynamic Host Configuration Protocol
    • Linux Kill Signals
    • Linux File Permissions
    • Linux File System
    • Linux Create File
    • Linux Concatenate Files
    • Linux Join
    • Linux Process Management
    • Linux Proxy Server
    • Linux System Commands
    • Linux System Logging
    • NFS in Linux
    • Linux LVM
    • Linux Repository
    • Samba Server in Linux
    • Top Commands in Linux
    • Types of Shells in Linux
    • Shell Script Types For Linux
    • GCC Command in Linux
    • Monolithic Kernel
    • YARN Package Manager
    • Linux Sed Replace
    • Linux List Groups
    • Linux Container
    • Linux Find File by Name
    • Create Folder in Linux
    • Linux Move Folder
    • Linux Error Codes
    • Linux Automount
    • Linux HugePages
  • Kali Linux
    • Install Kali Linux
    • Kali Linux Uses
    • Kali Linux Commands
    • Kali Linux Repository
    • Kali Linux Packages
    • Kali Linux root password
    • Kali Linux Alternative
  • Interview Questions
    • Linux Interview Questions
    • Linux System Administration Interview
    • Red Hat Interview Questions

Related Courses

Kali Linux Training

Linux Training Course

Red Hat Training Course

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2020 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA Login

Forgot Password?

EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you
Book Your One Instructor : One Learner Free Class

Let’s Get Started

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Software Development Course

Web development, programming languages, Software testing & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

Special Offer - Linux Training Program (16 Courses, 3+ Projects) Learn More