3
# gunzip Command * The `gunzip` command decompresses files compressed by the `gzip` command. * It replaces files ending with `.gz`, `-gz`, `.z`, `-z`, or `_z` (case- insensitive) that begin with the correct magic number with an uncompressed file without the original extension. * It recognizes `.tgz` and `.taz` as shorthands for `.tar.gz` and `.tar.Z` respectively. * Examples: * Uncompress a file: `gunzip filename.gz` * Recursively uncompress content inside a directory: `gunzip -r directory_name/` * Uncompress all `.tgz` files in the current directory: `gunzip -S .tgz *` * List compressed and uncompressed sizes, compression ratio, and uncompressed name: `gunzip -l file_1 file_2` * Syntax: `gunzip [ -acfhklLnNrtvV ] [-S suffix] [ name ... ]` * Flags: * `-c`, `--stdout`: Write to standard output, keep original files unchanged. * `-h`, `--help`: Give help information. * `-k`, `--keep`: Keep (don't delete) input files. * `-l`, `--list`: List compressed file contents. * `-q`, `--quiet`: Suppress all warnings. * `-r`, `--recursive`: Operate recursively on directories. * `-S`, `--suffix=SUF`: Use suffix SUF on compressed files. * `--synchronous`: Synchronous output (safer if system crashes, but slower). * `-t`, `--test`: Test compressed file integrity. * `-v`, `--verbose`: Verbose mode. * `-V`, `--version`: Display version number. # hostnamectl Command * The `hostnamectl` command is used to control the Linux system hostname and related settings. * It helps to change the hostname without manually editing the `/etc/hostname` file. * Syntax: `$ hostnamectl [OPTIONS...] COMMAND ...` * Commands: * `status`: Check the current hostname settings. * `set-hostname NAME`: Set system hostname. * `set-icon-name NAME`: Set icon name for host. * Examples: * View current hostnames: `$ hostnamectl` or `$ hostnamectl status` * Change the static hostname: `$ hostnamectl set-hostname myhostname --static` (may require root access) * Set a transient hostname: `$ hostnamectl set-hostname myotherhostname --transient` * Set the pretty hostname: `$ hostnamectl set-hostname "prettyname" --pretty` # iptables Command * The `iptables` command is used to set up and maintain tables for the Netfilter firewall for IPv4 in the Linux kernel. * It matches packets with rules defined in tables and takes specified actions. * Syntax: `iptables --table TABLE -A/-C/-D... CHAIN rule --jump Target` * Example: * Append to a chain: `iptables [-t table] --append [chain] [parameters]` * Drop all traffic on any port: `iptables -t filter --append INPUT -j DROP` * Flags: * `-C`: Check if a rule is present in the chain (returns 0 if exists, 1 if not). * `-A`: Append to the chain provided in parameters. # netstat Command * `netstat` (Network Statistics) displays current network connections, networking protocol statistics, and other interfaces. * Check if installed: `netstat –v` * Install if not present: `sudo apt install net-tools` * Use Cases: * Show routing table details: `netstat -nr` * Show statistics for network interfaces: `netstat -i` * List networks, states, and ports: `netstat -tunlp` * List all TCP port connections: `netstat -at` * List all UDP port connections: `netstat -au` * List all active connections: `netstat -l` # lsof Command * The `lsof` command shows file information of files opened by running processes (List Open Files). * An open file may be a regular file, directory, etc. * Syntax: `lsof [-OPTION] [USER_NAME]` * Examples: * Show all files opened by all active processes: `lsof` * Show files opened by a particular user: `lsof -u [USER_NAME]` * List processes with opened files under a specified directory: `lsof +d [PATH_TO_DIR]` * Options: * `-i [tcp/udp/:port]`: List network connections (optionally filtered by protocol/port). * `-i4`: List processes with IPv4 connections. * `-i6`: List processes with IPv6 connections. * `-c [PROCESS_NAME]`: List files of a particular process by name. * `-p [PROCESS_ID]`: List files opened by a specified process ID. * `-p ^[PROCESS_ID]`: List files NOT opened by a specified process ID. * `+d [PATH]`: List processes with opened files under a directory. * `+R`: List files opened by parent process ID. * Help: `man lsof` # bzip2 Command * The `bzip2` command compresses and decompresses files into a single file, reducing storage space. * Syntax: `bzip2 [OPTIONS] filenames ...` * Each file is replaced by a compressed version with the `.bz2` extension. * Options: * `-d`, `--decompress`: Decompress compressed file. * `-f`, `--force`: Force overwrite an existing output file. * `-h`, `--help`: Display help message and exit. * `-k`, `--keep`: Enable compression but keep the original input file. * `-L`, `--license`: Display license terms and conditions. * `-q`, `--quiet`: Suppress non-essential warning messages. * `-t`, `--test`: Check integrity of the specified `.bz2` file without decompressing. * `-v`, `--verbose`: Display details for each compression operation. * `-V`, `--version`: Display the software version. * `-z`, `--compress`: Enable file compression, but deletes the original input file (default). * Examples: * Force compression (deletes original): `bzip2 -z input.txt` * Force compression and retain original: `bzip2 -k input.txt` * Force decompression: `bzip2 -d input.txt.bz2` * Test integrity of compressed file: `bzip2 -t input.txt.bz2` * Show compression ratio: `bzip2 -V input.txt` # service Command * The `service` command runs a System V init script in a predictable environment. * It removes most environment variables and sets the current working directory to `/`. * Syntax: `service [SCRIPT] [COMMAND] [OPTIONS]` * The `SCRIPT` parameter specifies a System V init script in `/etc/init.d/SCRIPT`. * Supported `COMMAND` values depend on the script (at least `start` and `stop` should be supported). * `service --full-restart` runs the script twice, with `stop` then `start`. * `service --status-all` runs all init scripts with the `status` command in alphabetical order. * Examples: * Check the status of all running services: `service --status-all` * Run a script: `service SCRIPT-Name start` # vmstat Command * The `vmstat` command monitors system performance, showing information about memory, disk, processes, CPU scheduling, paging, and block IO (Virtual Memory Statistics Report). * The initial report shows averages since the last reboot. * `vmstat`: Displays virtual memory statistics. * `free`: Free space not being used. * `si`: Memory swapped in per second in kB. * `so`: Memory swapped out per second in kB. * `vmstat -a`: Shows active and inactive memory. * `vmstat -d`: Shows disk statistics. # mpstat Command * The `mpstat` command reports processor-related statistics, displaying CPU usage and performance. * It numbers processors starting with CPU 0. * Syntax: `mpstat [options] [ []]` * Options: * `-A`: Display all detailed statistics. * `-h`: Display mpstat help. * `-I`: Display detailed interrupts statistics. * `-n`: Report summary CPU statistics based on NUMA node placement. * `-N`: Indicate the NUMA nodes for which statistics are reported. * `-P`: Indicate the processors for which statistics are reported. * `-o`: Display statistics in JSON format. * `-T`: Display topology elements in the CPU report. * `-u`: Report CPU utilization. * `-v`: Display utilization statistics at the virtual processor level. * `-V`: Display mpstat version. * `-ALL`: Display detailed statistics about all CPUs. * Examples: * Display processor and CPU statistics: `mpstat` * Display processor number of all CPUs: `mpstat -P ALL` * Get all information the tool may collect: `mpstat -A` * Display CPU utilization by a specific processor: `mpstat -P 0` * Display CPU usage with a time interval: `mpstat 1 5` (prints 5 reports with 1-second interval) # ncdu Command * `ncdu` (NCurses Disk Usage) is a curses-based version of the `du` command for visualizing disk space usage. * Examples: * Quiet Mode: `ncdu -q` * Omit mounted directories: `ncdu -q -x` * Syntax: `ncdu [-hqvx] [--exclude PATTERN] [-X FILE] dir` * Flags: * `-h`: Print a small help message. * `-q`: Quiet mode (updates screen less frequently). * `-v`: Print version. * `-x`: Only count files and directories on the same filesystem. * `--exclude PATTERN`: Exclude files matching PATTERN. * `-X FILE`, `--exclude-from FILE`: Exclude files matching patterns in FILE (newline-separated). # uniq Command * The `uniq` command reports or filters out repeated lines in a file. * It detects adjacent duplicate lines and deletes them. * It filters input file data and writes the filtered data to the output file. * Examples: * Omit repeated lines: `uniq kt.txt` * Count line repetitions: `uniq -c kt.txt` * Print repeated lines: `uniq -d kt.txt` * Print unique lines: `uniq -u kt.txt` * Skip N fields: `uniq -f 2 kt.txt` * Skip N characters: `uniq -s 5 kt.txt` * Case-insensitive comparison: `uniq -i kt.txt` * Syntax: `uniq [OPTION] [INPUT[OUTPUT]]` * Flags: * `-c`: Count repetitions. * `-d`: Print only repeated lines. * `-i`: Case-insensitive comparison. * `-f N`: Skip N fields. * `-s N`: Skip N characters. * `-u`: Print only unique lines. * `-z`: End line with NULL byte. * `-w N`: Compare N characters. * `--help`: Display help. * `--version`: Display version. # RPM Command * RPM (RPM Package Manager) is used to build, install, query, verify, update, and erase software packages. * Packages consist of archives of files and metadata. * Two types: binary packages (for installation) and source packages (containing source code). * Basic modes: Query, Verify, Signature Check, Install/Upgrade/Freshen, Uninstall, Initialize Database, Rebuild Database, Resign, Add Signature, Set Owners/Groups, Show Querytags, Show Configuration. * General Options: * `-?`, `--help`: Print usage message. * `--version`: Print version number. * `--quiet`: Print minimal output (errors only). * `-v`: Print verbose information. * `-vv`: Print debugging information. * `--rcfile FILELIST`: Read configuration files. * `--pipe CMD`: Pipe output to command CMD. * `--dbpath DIRECTORY`: Use database in DIRECTORY. * `--root DIRECTORY`: Use the filesystem tree rooted at DIRECTORY. * `-D`, `--define='MACRO EXPR'`: Define MACRO with value EXPR. * `-E`, `--eval='EXPR'`: Print macro expansion of EXPR. * Querying and Verifying Packages: * `rpm {-q|--query} [select-options] [query-options]` * `rpm {-V|--verify} [select-options] [verify-options]` * `rpm --import PUBKEY ...` * `rpm {-K|--checksig} [--nosignature] [--nodigest] PACKAGE_FILE ...` * Installing, Upgrading, Removing Packages: * `rpm {-i|--install} [install-options] PACKAGE_FILE ...` * `rpm {-U|--upgrade} [install-options] PACKAGE_FILE ...` * `rpm {-F|--freshen} [install-options] PACKAGE_FILE ...` * `rpm {-e|--erase} [--allmatches] [--nodeps] [--noscripts] [--notriggers] [--test] PACKAGE_NAME ...` * Miscellaneous: * `rpm {--initdb|--rebuilddb}` * `rpm {--addsign|--resign} PACKAGE_FILE...` * `rpm {--querytags|--showrc}` * `rpm {--setperms|--setugids} PACKAGE_NAME` * Query-options verify-options install-options have a lot of possible values to use. Please refer to the original documentation. # scp Command * `scp` (secure copy) securely copies files and directories between two locations. * Files and passwords are encrypted. * Ways to copy: * Local to remote. * Remote to local. * Between two remote systems from the local system. * Examples: * Local to remote: `scp /home/documents/local-file root@{remote-ip-address}:/home/` * Remote to local: `scp root@{remote-ip-address}:/home/remote-file /home/documents/` * Remote to remote: `scp root@{remote1-ip-address}:/home/remote-file root@{remote2-ip-address}/home/` * Syntax: `scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2` * Options: * `-P`: Specifies the remote host SSH port. * `-p`: Preserves file modification and access times. * `-q`: Suppress progress meter and non-error messages. * `-C`: Compresses the data. * `-r`: Recursively copy directories. * Requires SSH key or password authentication. * Colon (`:`)distinguishes between local and remote locations. * Requires read permissions on source and write permissions on target. * Overwrites files without warning. * Use `screen` or `tmux` for large transfers. # sleep Command * The `sleep` command creates a dummy job to delay execution. * It pauses execution for a specified amount of time (seconds by default). * Syntax: `sleep NUMBER[SUFFIX]...` * Suffixes: * `s`: seconds * `m`: minutes * `h`: hours * `d`: days * The command delays for the sum of values if multiple `NUMBER` and `SUFFIX` are entered. * Options: * `--help`: Display help. * `--version`: Output version information. # split Command * The `split` command splits a file into smaller files. * Examples: * : `split filename.txt` * Split into 200-line segments with prefix "file": `split -l 200 filename file` * Split into 40-byte segments with prefix "file": `split -b 40 filename file` * Verbose mode: `split filename.txt --verbose` * Syntax: `split [options] filename [prefix]` * Flags: * `-a N`, `--suffix-length=N`: Generate suffixes of length N. * `--additional-suffix=SUFFIX`: Append SUFFIX to file names. * `-b SIZE`, `--bytes=SIZE`: Put SIZE bytes per output file. * `-C SIZE`, `--line-bytes=SIZE`: Put at most SIZE bytes of records per output file. * `-d`: Use numeric suffixes. * `--numeric-suffixes[=FROM]`: Same as -d, but allow setting the start value. * `-x`: Use hex suffixes. * `--hex-suffixes[=FROM]`: Same as -x, but allow setting the start value. * `-e`, `--elide-empty-files`: Do not generate empty output files with '-n'. * `--filter=COMMAND`: Write to shell COMMAND; file name is $FILE. * `-l NUMBER`, `--lines=NUMBER`: Put NUMBER lines/records per output file. * `-n CHUNKS`, `--number=CHUNKS`: Generate CHUNKS output files. * `-t SEP`, `--separator=SEP`: Use SEP instead of newline as the record separator. * `-u`, `--unbuffered`: Immediately copy input to output with '-n r/...' . * `--verbose`: Print a diagnostic just before each output file is opened. * `--help`: Display this help and exit. * `--version`: Output version information and exit. * `SIZE` argument is an integer and optional unit (e.g., 10K = 10*1024). Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000). * `CHUNKS` options: * `N`: Split into N files. * `K/N`: Output Kth of N to stdout. * `l/N`: Split into N files without splitting lines. * `l/K/N`: Output Kth of N to stdout without splitting lines. * `r/N`: Like 'l' but use round robin distribution. * `r/K/N`: Likewise but only output Kth of N to stdout. # stat Command * The `stat` command displays file or filesystem status. * Syntax: `stat [OPTION] [FILE]` * Examples: * Basic usage: `stat file.txt` * Display total size in bytes: `stat file.txt -c %s` * Flags: * `-L`, `--dereference`: Follow links. * `-f`, `--file-system`: Display file system status instead of file status. * `-c FORMAT`, `--format=FORMAT`: Specify the format. * `-t`, `--terse`: Print information in terse form. * `--cached=MODE`: Specify how to use cached attributes (always, never, or default). * `--printf=FORMAT`: Like --format, but interpret backslash escapes. * `--help`: Display the help and exit. * `--version`: Output version information and exit. * Format Sequences: * `%a`: Permission bits in octal * `%A`: Permission bits and file type in human-readable form * `%d`: Device number in decimal * `%D`: Device number in hex * `%F`: File type * `%g`: Group ID of owner * `%G`: Group name of owner * `%h`: Number of hard links * `%i`: Inode number * `%m`: Mount point * `%n`: File name * `%N`: Quoted file name with dereference if symbolic link * `%s`: Total size, in bytes * `%u`: User ID of owner * `%U`: User name of owner * `%w`: Time of file birth, human-readable; - if unknown * `%x`: Time of last access, human-readable * `%y`: Time of last data modification, human-readable * `%z`: Time of last status change, human-readable # useradd Command * The `useradd` command adds or updates user accounts. * Examples: * Add a new user: `useradd NewUser` * Add a user with a specific home directory: `useradd -d /home/NewUser NewUser` * Add a user with a specific ID: `useradd -u 1234 NewUser` * Syntax: `useradd [OPTIONS] NameOfUser` * Flags: * `-d /path/to/directory`: Set the user's login directory. * `-u ID`: Set the user's ID. * `-g GroupID`: Create a user with specific group ID. * `-M`: Create a user without a home directory. * `-e DATE`: Create a user with an expiry date (YYYY-MM-DD). * `-c COMMENT`: Add a comment for the user. * `-s /path/to/shell`: Change the user's login shell. * `-p PASSWORD`: Set an unencrypted password for the user. # userdel Command * The `userdel` command deletes a user account and related files. * Examples: * Delete a user: `userdel userName` * Force removal even if logged in: `userdel -f userName` * Delete user and home directory: `userdel -r userName` * Syntax: `userdel [OPTIONS] userName` * Flags: * `-f`: Force removal even if the user is logged in. * `-r`: Remove the files in the user's home directory, the home directory itself, and the user's mail spool. * `-Z`: Remove any SELinux user mapping. # usermod Command * The `usermod` command modifies user account properties. * Requires superuser (root) privileges. * Syntax: `usermod [options] USER` * Options: * `-a`: Add user to a secondary group. * `-c`: Add a comment field for the user account. * `-d`: Modify the directory for an existing user account. * `-g`: Change the primary group for a user. * `-G`: Add supplementary groups. * `-l`: Change the existing user login name. * `-L`: Lock system user account. * `-m`: Move the contents of the home directory to a new directory. * `-p`: Create an un-encrypted password. * `-s`: Create a specified shell for new accounts. * `-u`: Assign UID for the user account. * `-U`: Unlock any locked user. * Examples: * Add a comment: `sudo usermod -c "This is test user" test_user` * Change home directory: `sudo usermod -d /home/sam test_user` * Change expiry date: `sudo usermod -e 2021-10-05 test_user` * Change group: `sudo usermod -g sam test_user` * Change login name: `sudo usermod -l test_account test_user` * Lock a user: `sudo usermod -L test_user` * Unlock a user: `sudo usermod -U test_user` * Set an unencrypted password: `sudo usermod -p test_password test_user` * Create a shell: `sudo usermod -s /bin/sh test_user` * Change the user ID: `sudo usermod -u 1234 test_user` # ionice Command * The `ionice` command sets or gets process I/O scheduling class and priority. * Syntax: * `ionice [options] -p ` * `ionice [options] -P ` * `ionice [options] -u ` * `ionice [options] ` * Scheduling Classes: * Idle: Only gets disk time when no other program needs it. `ionice -c 3` * Best Effort: Default scheduling class with priority 0-7 (lower is higher). `ionice -c 2 -n 0` * `io_priority = ( cpu_nice + 20 ) / 5` (kernels after 2.6.26 with CFQ I/O scheduler) * Real Time: Given first access to disk. Requires care to avoid starving other processes. `ionice -c 1 -n 0` * Options: * `-c, --class`: Scheduling class (0: none, 1: realtime, 2: best-effort, 3: idle). * `-n, --classdata`: Priority (0..7) in the specified scheduling class. * `-p, --pid ...`: Act on these already running processes. * `-P, --pgid ...`: Act on already running processes in these groups. * `-t, --ignore`: Ignore failures. * `-u, --uid ...`: Act on already running processes owned by these users. * `-h, --help`: Display this help. * `-V, --version`: Display version. * Examples: * `ionice`: Shows class and priority of current process. * `ionice -p 101`: Shows class and priority of process with PID 101. * `ionice -c2 -n0 -p2`: Set process 2 as best-effort with highest priority. * `ionice /bin/ls`: Get priority and class info of `/bin/ls`. * `ionice -n4 -p2`: Set priority 4 of process with pid 2 * `ionice -c0 -n4 -p2 -t`: Ignore failure when setting class data for none class. # du Command * The `du` command retrieves disk space usage information for a directory(Disk Usage). * Syntax: `du [OPTION]... [FILE]...` or `du [OPTION]... --files0-from=F` * Examples: * Estimated size of subdirectories in current directory: `du` * Estimated size of subdirectories in specified directory: `du {PATH_TO_DIRECTORY}` * Flags: * `-a`, `--all`: Includes information for both files and directories * `-c`, `--total`: Provides a grand total at the end of the list of files/directories * `-d N`, `--max-depth=N`: Provides information up to N levels from the directory where the command was executed * `-h`, `--human-readable`: Displays file size in human-readable units, not in bytes * `-s`, `--summarize`: Display only the total filesize instead of a list of files/directories # ping Command * The `ping` (Packet Internet Groper) command checks network connectivity between host and server/host. * Takes IP address or URL as input and sends a data packet to the specified address to get a response. * Latency: The time it takes to get the response. * Uses ICMP(Internet Control Message Protocol) to send an ICMP echo message. * Syntax: * `ping [option] [hostname]` or `[IP address]` * Examples: * To get ping version installed on your system type the following command: `sudo ping -v` * To check the google.com host availability type the following command: `ping google.com` * Controlling the number of pings that yout want to send to a specific host is done using the `-c` option. As follows `ping -c 5 google.com` * The default ping packet has a default size. In orden to controll the number of bytes of the ping, the following comamdn can be used: `ping -s 40 -c 5 google.com` * To change the time interval: By default ping wait for 1 sec to send next packet we can change this time by using `-i` option. As follows: `ping -i 2 google.com` # rsync Command * The `rsync` command securely copies files from one server to another over SSH. * Faster than `scp` and can resume interrupted transfers. * Transfer Files from local server to remote * `cd /var/www/html` * `rsync -avz user@your-remote-server.com:/home/user/dir/` * Explanation about the parameters * `-a`: Recursion and preserve file permissions * `-v`: Increases the amount of information you are given during the transfer * `-z`: Compresses the file data as it is sent to the destination machine reducing the amount of data being transmitted -- something that is useful over a slow connection. * In order to use a different port to conenct with SSH, the folloing syntax can be used `rsync -avz -e 'ssh -p 1234' user@your-remote-server.com:/home/user/dir/` * Transfer Files remote server to local * `rsync -avz your-user@your-remote-server.com:/home/user/dir/ /home/user/local-dir/` * In order to use a different port to connect with SSH, the folloing syntax can be used `rsync -avz -e 'ssh -p 2510' your-user@your-remote-server.com:/home/user/dir/ /home/user/local-dir/` * Transfer only missing files If you would like to transfer only the missing files you could use the `--ignore-existing` flag * `rsync -avz --ignore-existing user@your-remote-server.com:/home/user/dir/` # dig Command * `dig` - DNS lookup utility * `dig` command is a flexible tool for interrogating DNS name servers. * It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. * The dig is a network administration command-line tool for querying the Domain Name System. * `dig google.com` * The system will list all google.com DNS records that it finds, along with the IP addresses. * `dig google.com ANY` * Syntax: dig [server] [name] [type] [q-type] [q-class] {q-opt} {global-d-opt} host [@local-server] {local-d-opt} [ host [@local-server] {local-d-opt} [...]] * Flags: * domain is in the Domain Name System. * q-class is one of (in,hs,ch,...) [default: in] * q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a] (Use ixfr=version for type ixfr) * q-opt is one of: -4 (use IPv4 query transport only) -6 (use IPv6 query transport only) -b address[#port] (bind to source address/port) -c class (specify query class) -f filename (batch mode) * d-opt is of the form +keyword[=value], where keyword is: +[no]aaflag (Set AA flag in query (+[no]aaflag))+ +[no]aaonly (Set AA flag in query (+[no]aaflag)) +[no]additional (Control display of additional section) # whois Command * `whois` command in Linux is to find out information about a domain, such as the owner of the domain, the owner’s contact information, and the nameservers that the domain is using. * Examples: * The basic usage is `whois {Domain_name}` * The `-H` option omits the lengthy legal disclaimers that many domain registries deliver along with the domain information, like in the following comand. * `whois -H {Domain_name}` * Syntax: `whois [ -h HOST ] [ -p PORT ] [ -aCFHlLM