A Primer to System Administration - Know Thy System
文章目录
General information
Use
uname
to get system information:uname -a
-a
for print all the information.
CPU information
- Use
nproc
to print the number of processing units available (GNU coreutils):
$ nproc
4
- Use
lscpu
to display CPU architecture information (util-linux).
Disk information
df
is a powerful command for displaying system disk.
df -h /path/to/directory
cat /proc/partitions/
andcat /proc/mounts
are also pretty handly solutions to check the partitions and mount disks.
Memory information
Just as same as disk,
cat /proc/meminfo
could easily check memory information (Thanks to Unix’s Everything is a file design concept).Alternatively, you can type
free -m
, which essentially is the same as check /meminfo.-m
for display in megabytes (as you expected, -g for gigabytes, -k for kilobytes.)
User activity information
last
command will display user’s info like terminal, time, date and so forth. To check one specific user’s activity,last username
is what you are looking for.
w
is a great but rarely know command. It will display who is logged on and what they are doing. It’ll show username, terminal, from IP, login time, idle time, JCPU and the command line of their current process. If you never heard it before, I strongly suggest you to have a try.uptime
: Tell how long the system has been running.ps
: a well known command for checking current processes, for instance, to list all zombie process:ps aux | awk '{ print $8 " " $2 }' | grep -w Z
where
ps aux
to show processes for all users, the process’s user, and also show the processes not attached to a terminal (check man page for more details), then awk to filter theSTAT
and PID field, use grep to select the line containsZ
(Zombie), now we get zombie processes pids. It’s easy to kill them bykill -9 {PID}
.
top/htop
: Better not to use non-builtin command(for security reasons), but if you do want to,htop
is a superior alternative totop
– dynamically display current tasks.
Network information
To get your own public IP, both
curl icanhazip.com
orcurl ifconfig.me
are easy ways to do that(previous one is much faster).ping
: Even my mother knows to useping
to check network connectivity.ifconfig
: A frequently used tool to view network interface information. BTW, I wrote a script to filter IP, MAC addresses and networks fromifconfig
(tested on Ubuntu, Fedora, OmniOS and FreeBSD).lsof
, aka list open files, is definitely a swiss army knife for analyzing network.lsof -i
for list all open Internet and X.25 network files. (The examples below are from Daniel Miessler’s blog, see reference)lsof -iTCP # Show only TCP connections lsof -i:80 # Show networking only relate to port 80 lsof [email protected] # Show connections with particular IP lsof -u username # Show given user's connections lsof -u ^username # Show connections except given user
ss -s
: display Currently Established, Closed, Orphaned and Waiting TCP sockets
You may Also interested in
- My previous post A Primer to System Administration - Users and groups
- If you found any grammar misusage or typos, please help me correct by pull request here.