System Information Linux command.
System Information Linux command.
Command: uname
Definition:
The uname command in Linux is used to display basic system information, such as the kernel name,
version, and other details about the operating system.
Pattern to Use:
uname [options]
Options:
Examples:
Output Breakdown
i. Linux
Indicates the operating system kernel name.
ii. app01
The hostname of the system.
iii. 5.14.0-505.el9.x86_64
The kernel version and release number:
a. 5.14.0 is the kernel version.
b. 505 is the release number.
c. el9 indicates the distribution (Enterprise Linux 9).
d. x86_64 specifies the architecture (64-bit).
iv. #1 SMP PREEMPT_DYNAMIC
a. #1: Build version of the kernel.
b. SMP: Symmetric Multi-Processing enabled, meaning the kernel
supports multiple CPUs/cores.
c. PREEMPT_DYNAMIC: Dynamic preemption mode for responsiveness.
v. Thu Sep 5 07:54:07 UTC 2024
The date and time when the kernel was built.
vi. x86_64 x86_64 x86_64
a. The first x86_64: Machine hardware name.
b. The second x86_64: Processor type.
c. The third x86_64: Hardware platform.
vii. GNU/Linux
Indicates the operating system distribution is based on GNU/Linux.
The uname command is especially useful for scripts and debugging to retrieve specific system details.
Command: top
Definition:
The top command in Linux is used to display real-time information about running processes, including
their resource usage, such as CPU, memory, and runtime. It is a dynamic, interactive tool for monitoring
system performance.
Pattern to Use:
top [options]
Options:
4. q — Quits top.
Examples:
Pattern to Use:
ps [options]
Options:
10. --sort [key] — Sorts processes based on a specific field (e.g., %cpu).
Examples:
Command: ps -e --sort=-%cpu
Output: Lists all processes, sorted by CPU usage in descending order.
Command: df
Definition:
The df (Disk Filesystem) command in Linux is used to display information about the disk space usage of
file systems. It shows details such as total size, used space, available space, and the mount point of file
systems.
Pattern to Use:
df [options] [file|directory]
Options:
1. No arguments — Displays disk space usage for all mounted file systems.
Examples:
Command: du
Definition:
The du (Disk Usage) command in Linux is used to estimate and display the disk space used by files and
directories. It provides a summary of disk usage for each directory and its contents.
Pattern to Use:
du [options] [file|directory]
Options:
1. No arguments — Displays disk usage of the current directory and its subdirectories.
10. -B [size] — Displays disk usage with a specific block size (e.g., 1M, 1G).
Examples:
Options:
8. -s [seconds] — Continuously displays memory usage, updating at the specified interval (in
seconds).
9. -c [count] — Specifies the number of times the memory usage is displayed when using the -s
option.
10. --si — Displays memory in powers of 1000 (e.g., 1K = 1000 bytes, 1M = 1000KB).
Examples:
Command: uptime
Definition:
The uptime command in Linux is used to display how long the system has been running, the number of
users currently logged in, and the system load averages for the past 1, 5, and 15 minutes.
Pattern to Use:
uptime [options]
Options:
1. No arguments — Displays the current uptime, number of users, and system load averages.
2. -p — Displays the uptime in a more human-readable, "pretty" format (e.g., "up 5 days, 3 hours").
Examples:
Pattern to Use:
hostname [options] [hostname]
Options:
Examples:
Command: lsof
Definition:
The lsof (List Open Files) command in Linux is used to list all open files and the processes that opened
them. It is useful for identifying files that are currently in use by processes, network connections, and the
status of mounted file systems.
Pattern to Use:
lsof [options]
Options:
2. -a — Combines multiple conditions (e.g., listing files that are both opened and belong to a
specific user).
3. -c [command] — Lists open files for processes that match the specified command.
7. -n — Shows network addresses in numeric form (IP addresses and port numbers).
10. -d [fd] — Lists open files associated with a specific file descriptor (e.g., stdin, stdout).
Examples:
Command: env
Definition:
The env command in Linux is used to display or modify the environment variables for the current
session. It can be used to set or clear environment variables, as well as to execute commands with a
modified environment.
Pattern to Use:
env [options] [COMMAND [ARGUMENTS]]
Options:
Examples:
Example:
Command: env MYVAR=hello echo $MYVAR
Output: Displays hello, as the MYVAR is set to hello just for the execution of echo.
Example:
Command: env -u PATH
Output: Removes the PATH environment variable.
Command: export
Definition:
The export command in Linux is used to set environment variables and make them available to child
processes. It allows variables to be passed to subprocesses, making it essential for setting environment
variables that need to be inherited by programs or scripts executed from the shell.
Pattern to Use:
export [variable_name[=value]]
Options:
1. No arguments — Displays a list of all environment variables that have been exported.
Examples:
Example:
Command: export MYVAR=hello && echo $MYVAR
Output: Displays hello as the MYVAR environment variable is set and passed to the echo command.
Command: echo
Definition:
The echo command in Linux is used to display a line of text or variables to the terminal. It is useful for
printing strings, variables, and the output of commands.
Pattern to Use:
echo [options] [string]
Options:
Escape Sequences:
\n — Newline.
\t — Horizontal tab.
\r — Carriage return.
\\ — Backslash.
\b — Backspace.
\v — Vertical tab.
Examples:
Line1
Line2