The Linux file system hierarchy standard (FHS) defines the main directories and their contents.
/bin: Essential user command binaries./boot: Boot loader files and the Linux kernel./dev: Device files./etc: System-wide configuration files./home: User home directories./lib: Essential shared libraries and kernel modules./lib64: Essential 64-bit shared libraries and kernel modules./media: Mount point for removable media./mnt: Temporary mount point for file systems./opt: Optional application software packages./proc: Virtual file system containing process and kernel information (lost on reboot)./root: Home directory for the root user./run: Runtime variable data./sbin: Essential system binaries./srv: Data for services provided by the system./sys: Virtual file system providing information about devices./tmp: Temporary files (often cleared on reboot)./usr: User applications and data./var: Variable datta files (e.g., logs).
Mounting File Systems
To mount a storage device, such as a CD-ROM drive, perform the following steps:
- Ensure the device is accessible: For a CD-ROM, this means having a disc loaded.
- Identify the device file: Use
ls -l /dev/cdromto find the device node. - Mount the device: Create a mount point directory (e.g.,
/mnt) if it doesn't exist, then use themountcommand:
To unmount, usemount /dev/cdrom /mntumount:umount /mnt/
Network Configuration
Network interface configuration is typically found in /etc/sysconfig/network-scripts/. The ifcfg-eth0 file contains parameters like:
TYPE: Network type (e.g.,Ethernet).BOOTPROTO: IP address assignment method (none,static,dhcp).NAME: Logical interface name (e.g.,eth0).DEVICE: Physical interface name (e.g.,eth0).ONBOOT: Whether the interface is enabled on boot (yesorno).IPADDR: Static IP address.PREFIX: Subnet mask prefix length.GATEWAY: Default gateway address.DNS1: Primary DNS server address.
To apply changes:
- Restart the network service:
systemctl restart network. - Or, restart specific inetrface:
ifdown eth0 && ifup eth0.
DNS resolution information is stored in /etc/resolv.conf.
Hostname Configuration
- CentOS 7:
- Temporary:
hostname new_hostname - Permanent:
hostnamectl set-hostname new_hostname(also sets temporarily) - To view the file for permanent configuration (though
hostnamectlis preferred):cat /etc/hostname.
- Temporary:
- CentOS 6:
- Temporary:
hostname new_hostname - Permanent: Edit
/etc/sysconfig/network.
- Temporary:
To check the OS version, use cat /etc/redhat-release.
Host File Mapping
The /etc/hosts file provides local IP address to hostname mapping. This is checked before DNS resolution.
Automatic Mounts
The /etc/fstab file defines file systems to be mounted automatically at boot time.
Startup Scripts
The /etc/rc.local script is executed at the end of the boot process. Ensure it has execute permissions (chmod +x /etc/rc.d/rc.local). Commands placed here will run on startup.
System Runlevels
Runlevels define the system's operating state. In modern systems (systemd), these are referred to as 'targets'.
-
CentOS 6 Runlevels:
- 0: Halt
- 1: Single-user mode (rescue)
- 2: Multi-user mode, without networking
- 3: Full multi-user mode, with networking (standard CLI)
- 4: Unused
- 5: Graphical multi-user mode
- 6: Reboot
-
CentOS 7 Targets:
poweroff.target(0)rescue.target(1)multi-user.target(2, 3, 4)graphical.target(5)reboot.target(6)
-
View current runlevel:
runlevel. -
Switch runlevel temporarily:
init <runlevel>. -
Set default target permanently (CentOS 7):
systemctl set-default <target_name>.target. -
Check default target:
systemctl get-default.
Environment Variables
- Temporary variables: Set using
VARIABLE_NAME=value. Access withecho $VARIABLE_NAME. - Permanent variables: Add
export VARIABLE_NAME=valueto/etc/profileand runsource /etc/profile. - The
PATHvariable defines directories searched for executable commands. To modifyPATHpermanently, edit/etc/profileand add the desired directories usingexport PATH=....
Aliases
Aliases create shortcuts for commands. Syntax: alias new_name='original_command'.
Example: alias catnet='cat /etc/sysconfig/network-scripts/ifcfg-eth0'.
To remove an alias: unalias new_name.
Login Banners
- Message of the Day (MOTD): The
/etc/motdfile's content is displayed after a successful login. - Pre-login Banners: The
/etc/issueand/etc/issue.netfiles display messages before login. To clear a file, useecho "" > /path/to/fileor> /path/to/file.