Linux File System

Understanding the Linux File System

The Linux file system is organized in a hierarchical structure, starting from the root directory (/). This structure is different from Windows and provides a more organized way to manage files and directories.

Key Directories:

  • /bin - Essential user command binaries
  • /etc - System configuration files
  • /home - User home directories
  • /var - Variable data files
  • /usr - User utilities and applications
  • /opt - Optional application software packages
  • /tmp - Temporary files
  • /dev - Device files
  • /proc - Process information
  • /boot - Boot loader files

File Types in Linux:

Regular Files (-)

Text files, binary files, images, etc.

ls -l file.txt

Directories (d)

Containers for files and other directories

ls -ld directory/

Symbolic Links (l)

Pointers to other files or directories

ln -s target link_name

Special Files

Block (b) and Character (c) devices

ls -l /dev/sda

Common File System Commands:

ls -la

List all files including hidden ones with detailed information

cd /path/to/directory

Change to specified directory

pwd

Print working directory (show current location)

mkdir -p /path/to/new/directory

Create nested directories

find / -name "filename" -type f

Search for files by name

File Permissions

Linux uses a robust permission system to control access to files and directories. Each file has three types of permissions:

Read (r)

Permission to view file contents

Write (w)

Permission to modify file contents

Execute (x)

Permission to run the file as a program

Permission Categories:

Owner (u)

The user who created the file

chmod u+x file.txt

Group (g)

Users who belong to the file's group

chmod g+w file.txt

Others (o)

All other users on the system

chmod o-r file.txt

Common Permission Examples:

chmod 755 myfile.txt

Sets permissions to: Owner (rwx), Group (r-x), Others (r-x)

chmod 644 myfile.txt

Sets permissions to: Owner (rw-), Group (r--), Others (r--)

chmod 777 myfile.txt

Sets permissions to: Owner (rwx), Group (rwx), Others (rwx)

File System Best Practices

Organization Tips:

  • Keep your home directory organized with clear subdirectories
  • Use meaningful names for files and directories
  • Regularly clean up temporary files
  • Back up important data regularly

Security Considerations:

  • Never store sensitive data in world-readable locations
  • Use appropriate permissions for sensitive files
  • Regularly audit file permissions
  • Be cautious with setuid and setgid permissions