Essential Linux Commands for System Information
Table of Contents
- Introduction
- Identifying the System
- Network Information
- Process Information
- User Information
- Environment Variables
- Block Devices
- USB Devices
- Open Files
- Conclusion
Introduction
This document provides a concise overview of essential Linux commands used to gather system information, focusing on identifying the system, network status, processes, users, and connected devices. Each command is illustrated with a simple example and a brief description of its output. Note that the exact output may vary depending on your system configuration.
Identifying the System
This section covers commands that provide basic system identification information.
id command
The id command displays the user and group IDs of the currently logged-in user.
Example:
1
id
Sample Output:
1
uid=1000(sreeju) gid=1000(sreeju) groups=1000(sreeju),4(adm),20(dialout),27(sudo),29(audio),30(dip),46(plugdev),113(lpadmin),128(sambashare)
This shows the user ID (uid), group ID (gid), and other groups the user belongs to.
hostname command
The hostname command displays the system’s hostname.
Example:
1
hostname
Sample Output:
1
mylinuxbox
This shows the name assigned to the system on the network.
uname command
The uname command provides system information, including the kernel name, node name, kernel release, kernel version, machine hardware name, and processor type. uname -r shows only the kernel release, and uname -a shows all information.
Example:
1
2
uname -r
uname -a
Sample Output:
1
2
5.15.0-76-generic
Linux mylinuxbox 5.15.0-76-generic #83-Ubuntu SMP Fri Sep 1 11:16:54 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Network Information
This section focuses on commands used to obtain network-related information.
ifconfig command
The ifconfig command (often replaced by ip) displays network interface configuration.
Example:
1
ifconfig
Sample Output: (Output will vary based on interfaces)
1
2
3
4
5
6
7
8
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.100 netmask 255.255.255.0 broadcast 192.168.1.255
inet6 fe80::a00:27ff:fe57:670c prefixlen 64 scopeid 0x20<link>
ether 00:16:3e:57:67:0c txqueuelen 1000 (Ethernet)
RX packets 123456 bytes 67890123 (67.8 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 789012 bytes 123456789 (123.4 MB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Shows details about the network interface, including IP address, MAC address, and statistics.
ip command
The ip command is a more modern and powerful alternative to ifconfig. ip addr shows interface addresses.
Example:
1
ip addr
Sample Output: (Output will vary based on interfaces)
1
2
3
4
5
6
7
8
9
10
11
12
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:16:3e:57:67:0c brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::a00:27ff:fe57:670c/64 scope link
valid_lft forever preferred_lft forever
netstat command
The netstat command displays network connections, routing tables, interface statistics, masquerade connections, and multicast memberships. netstat -tulpn shows TCP connections.
Example:
1
netstat -tulpn
Sample Output: (Output will vary based on active connections)
1
2
3
4
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1234/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 4567/cupsd
ss command
The ss command is a more modern and efficient alternative to netstat. ss -tulpn provides similar information to netstat -tulpn.
Example:
1
ss -tulpn
Sample Output: (Output will vary based on active connections)
1
2
3
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 *:22 *:* users:(("sshd",pid=1234,fd=3))
LISTEN 0 128 127.0.0.1:631 *:* users:(("cupsd",pid=4567,fd=4))
Process Information
This section covers commands for viewing running processes.
ps command
The ps command displays information about currently running processes. ps aux shows a comprehensive list.
Example:
1
ps aux
Sample Output: (Output will be extensive, showing many processes)
1
2
3
4
5
6
7
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 40924 3068 ? Ss 15:36 0:00 /sbin/init splash
root 2 0.0 0.0 0 0 ? S 15:36 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? I< 15:36 0:00 [rcu_gp]
root 4 0.0 0.0 0 0 ? I< 15:36 0:00 [rcu_par_gp]
...many more processes...
sreeju 1234 0.0 0.1 123456 12345 ? Ss 15:40 0:01 /usr/bin/gnome-terminal -d
User Information
This section covers commands for viewing logged-in users.
who command
The who command displays who is currently logged in.
Example:
1
who
Sample Output:
1
sreeju pts/0 2023-10-27 15:40 (mylinuxbox)
Environment Variables
This section covers displaying environment variables.
env command
The env command lists all current environment variables.
Example:
1
env
Sample Output: (Output will vary greatly depending on the environment)
1
2
3
4
HOME=/home/sreeju
TERM=xterm-256color
SHELL=/bin/bash
...many more variables...
Block Devices
This section covers listing block devices.
lsblk command
The lsblk command lists block devices (hard drives, SSDs, partitions).
Example:
1
lsblk
Sample Output: (Output will vary depending on the system’s storage configuration)
1
2
3
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 232.9G 0 disk
└─sda1 8:1 0 232.9G 0 part /
USB Devices
This section covers listing USB devices.
lsusb command
The lsusb command lists USB devices connected to the system.
Example:
1
lsusb
Sample Output: (Output will vary depending on connected USB devices)
1
2
3
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 004: ID 046d:c52b Logitech, Inc. Unifying Receiver
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Open Files
This section covers listing open files.
lsof command
The lsof command lists open files. This can be useful for troubleshooting applications or identifying which processes are using specific files.
Example:
1
lsof | head -n 10
Sample Output: (Output will be extensive, showing many open files - head limits to 10 lines)
1
2
3
4
5
6
7
8
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
systemd 1 root cwd DIR 8,3 4096 2 /
systemd 1 root rtd DIR 8,3 4096 2 /
systemd 1 root txt REG 8,0 128768 2 /lib/systemd/systemd
kthreadd 2 root txt REG 8,0 128768 2 /lib/systemd/systemd
rcu_gp 3 root txt REG 8,0 128768 2 /lib/systemd/systemd
rcu_par_gp 4 root txt REG 8,0 128768 2 /lib/systemd/systemd
...more open files...
Conclusion
These commands provide a foundation for gathering crucial system information in Linux. Understanding their usage is essential for system administration, troubleshooting, and general system management. Remember to consult the man pages (man command_name) for each command to explore advanced options and detailed usage information.