Systematic Linux Study Notes

📢 This article was translated by gemini-3-flash-preview

Written by Hiyoung

Original article: https://blog.hiyoung.xyz/2022/08/01/84a03702e5a9/

(Reference video: https://www.bilibili.com/video/BV1WY4y1H7d3?p=1 )

1. Basics

1.1 Linux File System Directory Structure

Linux File System Directory Structure Source: Runoob

Small arrows in the diagram indicate that the file’s actual location is elsewhere.

  • /bin: Short for Binaries. Contains the most frequently used commands.
  • /boot:
    Core files used for starting Linux, including bootloader files and kernel images.
  • /dev:
    Short for Device. Contains external device files. In Linux, devices are accessed just like files.
  • /etc:
    Short for Etcetera. Contains all system management configuration files and subdirectories.
  • /home:
    User home directories. Every user has their own directory, usually named after their account (e.g., alice, bob, eve).
  • /lib:
    Short for Library. Contains basic dynamic shared libraries, similar to DLL files in Windows. Almost all applications require these libraries.
  • /lost+found:
    Usually empty. Contains file fragments recovered after an illegal system shutdown.
  • /media:
    Linux automatically recognizes devices like USB drives and optical drives and mounts them here.
  • /mnt:
    Used for temporary mounting of other file systems. You can mount an optical drive to /mnt/ to view its contents.
  • /opt:
    Short for optional. Directory for installing extra software (e.g., an ORACLE database). Empty by default.
  • /proc:
    Short for Processes. A virtual file system (pseudo file system) storing files representing the current kernel state. It resides in memory, not on the hard drive. You can access it for system info.
    Example: Disable ping with echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all.
  • /root:
    The home directory for the system administrator (superuser).
  • /sbin:
    Short for Superuser Binaries. Contains system management programs used by the admin.
  • /selinux:
    Specific to Redhat/CentOS. SELinux is a security mechanism similar to a firewall but more complex. This directory stores SELinux-related files.
  • /srv:
    Stores data required by services after they start.
  • /sys:
    Introduced in the 2.6 kernel. It installs the sysfs file system, which integrates information from proc (processes), devfs (devices), and devpts (pseudo-terminals). It reflects the kernel device tree.
  • /tmp:
    Short for temporary. Used for storing temporary files.
  • /usr:
    Short for Unix Shared Resources. An important directory containing many user applications and files, similar to “Program Files” in Windows.
  • /usr/bin:
    Applications used by system users.
  • /usr/sbin:
    Advanced management programs and system daemons for the superuser.
  • /usr/src:
    Default location for kernel source code.
  • /var:
    Short for variable. Contains files that frequently change, such as various log files.
  • /run:
    A temporary file system storing info since the system booted. Files are cleared on reboot. If /var/run exists, it should point here.

1.2 Basic File Attributes

1.2.1 Attributes

In Linux, the first character indicates whether the entry is a directory, file, or link.

  • d: Directory
  • : File
  • l: Link file
  • b: Storage device interface (random access device)
  • c: Serial port device, like a keyboard or mouse (one-time character device)

The following characters are grouped in threes, using rwx. r is read, w is write, and x is execute. If a permission is missing, it’s replaced by a dash .

Linux Study Notes 3

File attributes are defined by the first 10 characters (see below).

Linux Study Notes 4

From left to right (0-9):

Bit 0 is the file type. Bits 1-3 are owner permissions. Bits 4-6 are group permissions. Bits 7-9 are permissions for others.

1, 4, 7 represent read (r). 2, 5, 8 represent write (w). 3, 6, 9 represent execute (x).

1.2.2 Linux File Owner and Group

1. chgrp: Change group

Syntax:

1
chgrp [-R] groupname filename

Options:

  • -R: Recursive change. Apply to all files and subdirectories.

2. chown: Change owner (and group)

Syntax:

1
2
chown [-R] ownername filename
chown [-R] ownername:groupname filename

Example: Change install.log owner to bin in the home directory (~):

1
2
3
4
[root@www ~] cd ~
[root@www ~]# chown bin install.log
[root@www ~]# ls -l
-rw-r--r--  1 bin  users 68495 Jun 25 08:53 install.log

Change it back to root:root:

1
2
3
[root@www ~]# chown root:root install.log
[root@www ~]# ls -l
-rw-r--r--  1 root root 68495 Jun 25 08:53 install.log

3. chmod: Change permissions

Two methods: Numeric and Symbolic.

There are nine basic permissions: owner/group/others, each with read/write/execute.

Numeric values:

  • r: 4
  • w: 2
  • x: 1

Sum the values for each identity. For example, -rwxrwx—:

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others = — = 0+0+0 = 0

Total: 770.

Syntax:

1
chmod [-R] xyz file_or_dir

Example: Set .bashrc to full permissions:

1
2
3
4
5
[root@www ~]# ls -al .bashrc
-rw-r--r--  1 root root 395 Jul  4 11:45 .bashrc
[root@www ~]# chmod 777 .bashrc
[root@www ~]# ls -al .bashrc
-rwxrwxrwx  1 root root 395 Jul  4 11:45 .bashrc

For -rwxr-xr–, the score is [4+2+1][4+0+1][4+0+0]=754.

4. Symbolic permission changes

Use u (user), g (group), o (others), and a (all).

| chmod | u g o a | +(add) -(remove) =(set) | r w x | file/dir | |---|---|---|---|---|

Set permissions to -rwxr-xr–:

1
2
3
4
5
6
touch test1    // Create test1
ls -al test1    // Check default perms
#-rw-r--r-- 1 root root 0 Nov 15 10:32 test1
chmod u=rwx,g=rx,o=r  test1    // Modify perms
ls -al test1
-rwxr-xr-- 1 root root 0 Nov 15 10:32 test1

Remove execute permission for everyone:

1
2
3
chmod a-x test1
ls -al test1
#-rw-r--r-- 1 root root 0 Nov 15 10:32 test1

1.3 vim Text Editing

1.3.1 Three Vim Modes

Vim has three main modes: Command mode, Insert mode, and Last line mode (often referred to as general mode in some contexts).

Linux Study Notes 5

1.3.2 vim Shortcuts

Refer to: https://www.runoob.com/linux/linux-vim.html

1.4 Network Configuration

1.4.1 VMware Network Modes

Bridged Mode: VM connects directly to the external network (visible to outside). The host acts as a bridge. The VM gets its own IP from the router.

NAT Mode: Host and VM create a private network. NAT translates the VM’s IP (VM is invisible to outside). Since the host and VM are on different subnets, a virtual network card (VMnet8) connects the host to the VM’s LAN.

Host-only Mode: VM communicates only with the host. No Internet connection.

Linux Study Notes 6 Linux Study Notes 7

1.4.2 Configuring Static IP

Refer to: Setting Static IP in VM (CentOS example)

1.4.3 Configuring Hostname

1
2
3
4
5
6
7
8
hostname # View current hostname

vim /etc/hostname  # Edit hostname
# Reboot to apply

# Method 2 
hostnamectl set-hostname ... 
# Takes effect immediately
1
2
# Modify hosts file
vim /etc/hosts

1.5 System Management

1.5.1 service Management

An executing program or command is a “process.”

A process that remains in memory after starting is a “service.”

1
2
3
systemctl start|stop|restart|status servicename # Basic syntax

/usr/lib/systemd/system/    # Service directory
This post is licensed under CC BY-NC-SA 4.0 by the author.