Skip to content

tags: - LINUX INSTALLATION AND PACKAGE MANAGEMENT - ADMINISTRATIVE TASKS - ESSENTIAL SYSTEM SERVICES


...

SYSTEM ARCHITECTURE

shutdown

command in Linux is used to halt, power off, or reboot the system. It provides various options to schedule shutdowns, broadcast messages, and cancel scheduled actions.

Basic Syntax: shutdown [OPTION] [TIME] [MESSAGE]

Flags (Options):

  • -r or --reboot: Reboot the system after shutdown.
  • -h or --halt: Halt the system (power off) after .
  • -P or --poweroff: Power off the system immediately (no delay).
  • -c or --cancel: Cancel a scheduled shutdown.
  • +m or --delay=m: Schedule shutdown after m minutes from now.
  • hh:mm or --time=hh:mm: Schedule shutdown at a specific time (24-hour format).

dmesg

command in Linux displays the kernel ring buffer, which contains messages generated by the kernel during system boot and operation. These messages provide valuable information for troubleshooting and debugging system issues.

Flags and Options:

  • -C, --clear: Clears the ring buffer, removing all existing messages.
  • -c, --read-clear: Prints the current contents of the ring buffer and then clears it.
  • -f, --facility: Restricts output to a specific facility (e.g., kernel, device, or module).
  • -H, --human: Enables human-readable timestamps and pipes output to a pager (less).
  • -L, --level: Restricts output to a specific log level (e.g., error, warning, or info).

### rmmod rmmod is used to remove or unload a kernel module from the system.

Flags:

  • -s : Specify the module name or device file to unload (e.g., rmmod -s bluetooth).
  • -f : Force the removal of the module, even if it’s still in use (use with caution).
  • -v : Verbose mode, providing more detailed information about the removal process.
  • -w, --Wait : isolate a module that is in use and wait until it is no longer in use before removing.
  • -s, --syslog : send errors to the syslog (syetem log) instead of sending to standard error. Example: rmmod -s bluetooth removes the Bluetooth module.

### modprobe Purpose : modprobe is used to load or unload kernel modules.

Flags:

  • -r : Remove the specified module (equivalent to rmmod).
  • -a : Auto-load modules specified in /etc/modules or /etc/modprobe.d/*.conf files.
  • -q : Quiet mode, suppressing error messages.
  • -v : Verbose mode, providing more detailed information about the loading or unloading process.
  • -t : Test mode, simulating the loading or unloading of a module without actually doing so. Example: modprobe -r bluetooth removes the Bluetooth module.

lspci

Purpose : lspci is used to list and gather information about PCI buses and devices.

Flags:

  • -t : Tree-like output, showing the hierarchical structure of PCI devices.
  • -v : Verbose mode, providing detailed information about each device.
  • -vv : More verbose mode, including configuration registers and interrupt lines.
  • -vvv: Extremely verbose mode, including low-level details.
  • -m : Machine-readable output, suitable for scripting or processing.

LINUX INSTALLATION AND PACKAGE MANAGEMENT

dpkg

Purpose : package manager for Debian

Flags:

  • -i : Install a package (e.g., dpkg -i package.deb)
  • -r : Remove a package (e.g., dpkg -r package)
  • -L : List the contents of an installed package (e.g., dpkg -L package)
  • -S : Search for a file belonging to a package (e.g., dpkg -S /path/to/file)
  • --contents : Show the contents of a package file (e.g., dpkg --contents package.deb)
  • --install : Install a package with options (e.g., dpkg --install --force-overwrite package.deb)

apt

Purpose : package manager for Debian

Flags:

-f : Force installation or removal of a package (e.g., apt install -f package) -o : Override configuration options (e.g., apt install -o APT::Get::Force-Yes=true package) -q : Quiet mode (e.g., apt install -q package) -s`` : Simulation mode (e.g., apt install -s package)-y: Assume yes to prompts (e.g., apt install -y package)--fix-broken``` : Fix broken dependencies (e.g., apt install --fix-broken)

yum

Purpose : Package management system for RPM-based Linux distributions, such as Red Hat Enterprise Linux (RHEL), CentOS, and Fedora.

Flags:

  • -y : Assume yes to prompts (e.g., yum install -y package)
  • -q : Quiet mode (e.g., yum install -q package)
  • --skip-broken : Skip packages with broken dependencies (e.g., yum install --skip-broken package)
  • --enablerepo : Enable a specific repository (e.g., yum install --enablerepo=epel package)
  • --disablerepo : Disable a specific repository (e.g., yum install --disablerepo=epel package)
  • --setopt : Set a configuration option (e.g., yum install --setopt=tsflags=nodocs package)

dnf

Purpose : Next-generation package manager for RPM-based Linux distributions, replacing YUM as the default package manager in Fedora and other RHEL-based systems.

Flags:

  • -y : Assume yes to prompts (e.g., dnf install -y package)
  • -q : Quiet mode (e.g., dnf install -q package)
  • --skip-broken : Skip packages with broken dependencies (e.g., dnf install --skip-broken package)
  • --enablerepo : Enable a specific repository (e.g., dnf install --enablerepo=epel package)
  • --disablerepo : Disable a specific repository (e.g., dnf install --disablerepo=epel package)
  • --allow-erasing : Allow erasing of installed packages to resolve dependencies (e.g., dnf install --allow-erasing package)

zypper

Purpose : Package manager for openSUSE and SUSE Linux Enterprise distributions, as well as other RPM-based systems.

Flags:

  • -n : Non-interactive mode (e.g., zypper install -n package)
  • -q : Quiet mode (e.g., zypper install -q package)
  • --force : Force installation or removal of a package (e.g., zypper install --force package)
  • --clean : Clean up package cache (e.g., zypper clean)
  • --refresh : Refresh package metadata (e.g., zypper refresh)
  • --from : Specify a repository to install from (e.g., zypper install --from=home:username:repo package)

GNU AND UNIX COMMANDS

rm (Remove)

Purpose: Delete files and directories

Flags:

  • -i: Interactive mode, prompting for confirmation before deleting each file.
  • -r: Recursive deletion, removing directories and their contents.
  • -f: Force deletion, skipping prompts and errors.
  • -v: Verbose mode, displaying file names as they are deleted.
  • -d: Delete directories only, without prompting for confirmation. Example: rm -r /path/to/directory deletes the directory and its contents recursively

ls (List)

Purpose: Display file and directory information

Flags:

  • -l: Long format, displaying detailed file information.
  • -a: Show all files, including hidden ones.
  • -t: Sort files by time, with newest first.
  • -r: Recursively list directory contents.
  • -d: List directories only, without listing their contents. Example: ls -l /path/to/directory shows detailed information about files and directories in the specified path

uname (Unix Name)

Purpose: Display system information

Flags:

  • -a or --all: Display all system information, including kernel version, OS, and hardware architecture.
  • -m or --nodename: Display the network name of the machine.
  • -n or --hostname: Display the hostname of the machine.
  • -r or --release: Display the kernel release version.
  • -s or --sysname: Display the operating system name. Example: uname -a displays all system information

kill

Purpose: Send a signal to terminate a process

Flags:

  • -9 (SIGKILL): Send a SIGKILL signal to terminate a process immediately
  • -15 (SIGTERM): Send a SIGTERM signal to terminate a process gracefully
  • -HUP (SIGHUP): Send a SIGHUP signal to restart a process
  • -INT (SIGINT): Send a SIGINT signal to interrupt a process
  • -USR1 (SIGUSR1): Send a SIGUSR1 signal to a process Example: kill -9 terminates a process immediately

job

Purpose: Manage jobs (background processes) in the shell

Flags:

  • -l (list): List all jobs
  • -r (remove): Remove a job by its job number
  • -s (suspend): Suspend a job
  • -t (terminate): Terminate a job
  • -x (exit): Exit a job Example: job -l lists all running jobs

Devices, Linux Filesystems, Filesystem Hierarchy Standard

lsblk

Purpose: lists information about all available or the specified block devices.

Flags:

  • -a, --all: Also list empty devices and RAM disk devices.
  • -b, --bytes: Print the SIZE column in bytes rather than in a human-readable format.
  • -f, --fs: Output info about filesystems.
  • -l, --list: Produce output in the form of a list.
  • -p, --paths: Print full device paths.

mkfs

Purpose: is used to build a Linux filesystem on a device, usually a hard disk partition.

Flags:

  • -t, --type : Specify the type of filesystem to be built. If not specified, the default filesystem type (ext2) is used.
  • -F: Force the creation of a filesystem on the target device even if a filesystem is detected on it.
  • -c : Checks the target device for bad blocks before creating the filesystem.
  • -n : This is a truly useful option that simulates the creation of the filesystem, and displays what would be done if executed without the n option.
  • -q : Quiet mode. mke2fs will run normally, but will not produce any output to the terminal.

du

Purpose: estimate file space usage.

Flags:

  • -a, --all : write counts for all files, not just directories.
  • -h, --human-readable : print sizes in human readable format (e.g., 1K 234M 2G)
  • -c, --total : produce a grand total.
  • -S, --separate-dirs : for directories do not include size of subdirectories.
  • --inodes : list inode usage information instead of block usage.

df

Purpose: displays the amount of disk space available on the already mounted file systems.

Flags:

  • -a, --all: includes all file systems even inaccessible ones.
  • -i, --inodes: list inode information instead of block usage
  • -h, --human-readable: print sizes in human readable format.
  • -t, --type=TYPE: limit listing to file systems of type TYPE.
  • -T, --print-type : print file system type.

mount

Purpose : mount a filesystem.

Flag:

  • -a: Mounts all file systems listed in /etc/fstab.
  • -l : Lists all the file systems mounted and adds labels to each device.
  • -r : Mounts the file system in read-only mode.
  • -t : Indicates the file system type.
  • -v : Mounts verbosely, describing each operation.

## SHELL AND SHELL SCRIPTING

  1. source (or .) - Execute Commands from a File.

The source command (or .) is used to execute commands from a file in the current shell session. It is commonly used to load shell scripts or configurations. Flags:

< filename >: Specifies the file to source and execute in the current shell.

  • -: Negates the effect of an alias (if used with a command).
  • -x: Enables a trace of
  • -v : Prints each command before executing it (similar to -x, but without showing expanded arguments).
  • -c : Executes commands given as an argument, but in a new shell.

Example:

source ~/.bashrc # Loads the user's bash configuration file

  1. env - Display or Set Environment Variables

The env command is used to display or set environment variables temporarily. Flags: - -i: Starts with a completely clean environment (no inherited variables).

  • <VAR=value>: Temporarily sets an environment variable for the command that follows.

  • -u: Unsets an environment variable (e.g., env -u VAR). -0: Use null characters instead of newlines when displaying environment variables (useful for script processing).

  • -: Lists all the environment variables.

Example:

env VAR=value command # Temporarily set VAR for command execution

  1. set - Set or Unset Shell Options and Positional Parameters

The set command is used to set or unset shell options and positional parameters. Flags: - -o option: Sets shell options (e.g., -o nounset to treat unset variables as errors). - +o option: Unsets a shell option. - -x: Enable tracing, which prints commands as they are executed (for debugging). - -e: Exit immediately if a command exits with a non-zero status. - --: End option processing (useful when filenames start with a hyphen).

Example: set -e # Exit immediately if a command fails

  1. export - Set Environment Variables

The export command is used to set environment variables, making them available to child processes. Flags: - <VAR=value>: Sets the environment variable VAR to value and exports it. - -p: Displays all environment variables that are marked for export. - <VAR>: Exports an already defined variable without changing its value. - -f: Export functions (in Bash, to make them available in subshells). - --help: Displays help information about the export command.

Example:

export PATH="$PATH:/new/path" # Adds a new directory to PATH

  1. unset- Remove Variables or Functions

The unset command is used to remove variables or functions from the shell environment. Flags: - <VAR>: Unsets a variable, removing it from the shell environment. - -f : Unsets a function definition. - -v : Unsets a variable (same as without the -v flag). - --help: Displays help information. - --: End option processing for variable names that might start with a dash.

Example:

unset VAR # Removes the variable VAR

User Interface and Desktops

  1. xrandr - Configure and Set Display Properties

The xrandr command is used to set screen resolution, rotation, and display layout for X Window System displays. Flags: - ```--output : Specifies the display/output to configure (e.g., --output HDMI-1). - --mode : Sets the resolution for the specified display (e.g., --mode 1920x1080). - --rotate : Rotates the display (options: normal, left, right, inverted). - --brightness : Adjusts brightness (range from 0.0 to 1.0). - --off: Disables the specified output.

Example: xrandr --output HDMI-1 --mode 1920x1080 --rotate normal

  1. xdotool - Simulate Keyboard and Mouse Input

xdotool allows automation of mouse and keyboard actions in X Window System environments. It’s useful for simulating user interactions with the desktop. - key <'keysequence'> : Simulates pressing keys (e.g., xdotool key Ctrl+Alt+T to open a terminal)

  • mousemove <'x'> <'y'> Moves the mouse pointer to specified coordinates.

  • click button> :Simulates a mouse click (e.g., click 1 for left-click).

  • type <'text'>: Types out the specified text as if from the keyboard.

  • windowmove < 'window' > <'x'> <'y'>: Moves a window to specific coordinates.

Example: xdotool key Alt+Tab switches between open applications.

  1. gsettings - Configure GNOME Settings

The gsettings command is used for configuring GNOME desktop settings and is useful for modifying desktop, window, and appearance configurations. Flags: - get : Retrieves the current value of a GNOME setting. - set : Sets a value for a GNOME setting. - list-schemas: Lists all available schemas (i.e., setting categories). - list-keys : Lists all available keys for a given schema. - reset : Resets a setting to its default value.

Example: gsettings set org.gnome.desktop.interface gtk-theme 'Adwaita-dark' changes the GTK theme.

  1. xkill - Forcefully Close a Window

xkill is a command used to forcefully close unresponsive windows in X Window environments. It terminates the X server connection to the specified client. - (no flags): Starts xkill in interactive mode, where you click the window you want to kill. - -id : Kills a window by specifying its window ID. - -all: Kills all clients (use with caution, as this ends the X session). - -display : Specifies the display on which to run xkill. - --help: Displays help information about the command.

Example: xkill -id 0x04000007 kills a window by its ID.

  1. wmctrl - Interact with Window Manager

The wmctrl command is used for controlling windows and interacting with the window manager. This command is useful for managing open windows on the deskto Flags: - -l: Lists all open windows with details such as window ID and title. - -c : Closes a specified window. - -r -e : Resizes and moves a window to specified geometry (e.g., 0,100,100,400,300). - -s : Switches to a specified workspace. - -a : Activates (focuses) a window with the specified title.

Example: wmctrl -r "Terminal" -e 0,100,100,800,600 moves and resizes a terminal window.

NETWORKING FUNDAMENTALS

  1. ping

    • Purpose: Tests connectivity between devices by sending ICMP packets. Flags: - -c [count]: Specify the number of packets to send. - -i [interval]: Set the interval between packets (in seconds). - -s [size]: Specify the packet size. - -t [TTL]: Set Time-to-Live for the packets. - -q: Quiet output (only summary).

  2. ifconfig (Linux) / ipconfig (Windows)

    • Purpose: Displays or configures network interface settings. Flags for ifconfig: - up: Activates the network interface. - down: Deactivates the network interface. - -a: Display all interfaces, even inactive ones. - netmask [address]: Set a netmask for the interface. - mtu [size]: Set the Maximum Transmission Unit size.

  3. netstat

    • Purpose: Displays network connections, routing tables, and interface statistics. Flags: - -a: Show all active connections and listening ports. - -n: Show addresses numerically. - -r: Display the routing table. - -t: Show only TCP connections. - -u: Show only UDP connections.

  4. traceroute (Linux) / tracert (Windows)

    • Purpose: Shows the path packets take to reach a destination. Flags: - -m [max_ttl]: Set the maximum number of hops. - -q [queries]: Specify the number of queries per hop. - -w [timeout]: Set the timeout per probe. - -f [first_ttl]: Set the starting TTL. - -I: Use ICMP echo requests instead of UDP packets.

  5. nslookup

    • Purpose: Queries DNS to obtain domain name or IP address mapping. Flags: - -type=[record_type]: Specify the DNS record type (A, MX, NS, etc.). - -timeout=[seconds]: Set the timeout for a DNS query. - -retry=[attempts]: Number of times to retry a failed query. - -debug: Show detailed output of the DNS response. - -port=[port]: Specify the DNS server port (default is 53).

SECURITY

  1. ssh (Secure Shell)

    • Purpose: Establishes a secure connection to a remote machine. Flags: - -p [port]: Specify the port to connect to. - -i [identity_file]: Specify the identity file (private key) for authentication. - -C: Enable compression to speed up data transfer. - -v: Enable verbose mode for debugging. - -L [local_port:remote_host:remote_port]: Set up port forwarding.

  2. iptables (Linux firewall)

    • Purpose: Configures rules for traffic filtering and network packet control. Flags: - -A [chain]: Append a rule to a specified chain (INPUT, OUTPUT, FORWARD). - -D [chain]: Delete a rule from a specified chain. - -I [chain] [rule_number]: Insert a rule at a specific position in a chain. - -j [target]: : Specify the target action (ACCEPT, DROP, REJECT). - -s [source]: Specify the source IP address.

  3. openssl

    • Purpose: Manages SSL/TLS encryption, creates keys, certificates, and performs cryptographic operations. Flags: - genrsa: Generate an RSA private key. - req -new: Create a new certificate signing request (CSR). - x509 -in [file]: Convert a certificate to X.509 format. - -aes256: Specify AES-256 encryption for key generation. - -verify: Verify an SSL certificate.

  4. nmap (Network Mapper)

    • Purpose: Scans networks for open ports and services; useful for vulnerability assessment. • #### Flags: - -sS: Perform a stealth (SYN) scan. - -p [port_range]: Specify a range of ports to scan. - -O: Detect the operating system of the target. - -A: Enable OS detection, version detection, script scanning, and traceroute. - -v: Enable verbose output.

  5. chmod(Change Mode)

    • Purpose: Modifies file and directory permissions, enhancing file security. Flags: - -R: Apply permissions recursively to all files and directories. - +x: Add execute permissions. - +w: Add write permissions. - +r: Add read permissions. - --reference=[file]: Use another file’s permissions as a reference.

ADMINISTRATIVE TASKS

  1. ps (Process Status)

    • Purpose: Displays information about active processes. Flags: - -e: Show all processes. - -f: Full-format listing with more details. - -u [user]: Show processes for a specific user. - -aux: Show all processes from all users, including root. - -o [format]: Specify output format (e.g., pid, user, %cpu).

  2. top

    • Purpose: Real-time display of active processes and resource usage. Flags: - -d [seconds]: Set the delay between screen updates. - -u [user]: Show processes for a specific user. - -p [pid]: Monitor a specific process by PID. - -n [count]: Specify the number of updates before exiting. - -b: Batch mode for non-interactive output (good for logging).

  3. kill

    • Purpose: Terminates processes by PID. Flags: - -9: Forcefully kill a process (SIGKILL). - -15: Gracefully terminate a process (SIGTERM, default). - -l: List all available signal types. - -s [signal]: Specify a signal to send to the process. - -p: Print the process ID without sending a signal.

  4. systemctl (System Control)

    • Purpose: Controls and manages system services and units. Flags: - start [service]: Start a specified service. - stop [service]: Stop a specified service. - restart [service]: Restart a specified service. - status [service]: Show the status of a specified service. - enable [service]: Enable a service to start on boot.

  5. crontab

    • Purpose: Schedules recurring tasks or jobs. Flags : - -e: Edit the current user’s cron jobs. - -l: List all cron jobs for the current user. - -r: Remove all cron jobs for the current user. - -u [user]: Specify a user for which to list, edit, or remove jobs (requires sudo). - -i: Prompt before deleting the user’s cron jobs.

# ESSENTIAL SYSTEM SERVICES

  1. systemctl (Systemd Control)

    • Purpose: Controls and manages services and units in systems using systemd. Flags: - start [service]: Start a specified service. - stop [service]: Stop a specified service. - restart [service]: Restart a specified service. - status [service]: Show the status of a specified service. - enable [service]: Enable a service to start at boot.

  2. service (Legacy Service Management)

    • Purpose: Starts, stops, or restarts services, mainly used on older Linux systems. Flags: - start [service]: Start a specified service. - stop [service]: Stop a specified service. - restart [service]: Restart a specified service. - status [service]: Show the status of a specified service. - reload [service]: Reload the configuration of a running service.

  3. journalctl (Systemd Journal)

    • Purpose: Views and manages logs created by systemd’s journaling service. Flags: - -u [service]: Show logs for a specific service. - -f: Follow log output in real time. - -p [priority]: Filter logs by priority (e.g., err, warn, info). - --since [time]: Display logs since a specific time. - --until [time]: Display logs until a specific time.

  4. chkconfig (Service Configuration)

    • Purpose: Manages runlevel settings for services on older Linux systems. Flags: - --list: List all services and their runlevel settings. - --add [service]: Add a service to chkconfig management. - --del [service]: Remove a service from chkconfig management. - --level [levels]: Specify runlevels for the service. - [service] on|off: Enable or disable a service at boot.

  5. update-rc.d (Service Runlevel Management)

    • Purpose: Configures service start and stop behavior on Debian-based systems. Flags: - defaults: Enable default start and stop links for a service. - remove: Remove a service from the startup list. - [service] disable: Disable a specified service. - [service] enable: Enable a specified service. - [service] start [level]: Start the service at a specified runlevel.

  6. crontab (Cron Job Scheduler)

• Purpose: Schedules recurring tasks or jobs on the system. Flags:

  • -e: Edit the cron jobs for the current user.

    • -l: List all cron jobs for the current user.
    • -r: Remove all cron jobs for the current user.
    • -u [user]: Specify a user to manage cron jobs for (requires sudo).
      • -i: Prompt before deleting cron jobs.
  • netstat (Network Statistics)

• Purpose: Displays network connections, routing tables, and network interface statistics. Flags: - -a: Show all active connections and listening ports. - -t: Display only TCP connections. - -u: Display only UDP connections. - -l: Show only listening ports. - -p: Show PID and program name associated with each connection.

  1. ntpdate (Network Time Protocol)

    • Purpose: Synchronizes the system clock with NTP servers. Flags: - -u: Use an unprivileged port for outgoing connections. - -q: Query time server without setting the clock. - -b: Forcefully reset the time, using step rather than slew. _ -d: Enable debugging output. - [server]: Specify the NTP server to use for synchronization.