Last week, I published part 1 of this five-part series entitled: Linux Commands frequently used by Linux Sysadmins. That first article scratched the surface of what I believe are 50 to 100 commands used often by Linux Sysadmins and power users. Also, see Part 3, Part 4, and Part 5.
Let’s jump into another set of commands and command-line tools often used for analysis, troubleshooting, and Linux system administration. Listed below are some of the commands I’ve used over the past week. In this and future series, I will group related commands together as much as possible and add a table of contents to interlink all five parts.
1. Command-line Linux system monitoring.
Very often, it’s useful to view Linux system performance. He’s a shortlist for quickly accessing system performance details via the command line.
uptime– shows system uptime and load average.
top– shows an overall system view.
vmstat– shows system memory, processes, interrupts, paging, block I/O, and CPU info.
htop– interactive process viewer and manager.
dstat– view processes, memory, paging, I/O, CPU, etc., in real-time. All-in-one for vmstat, iostat, netstat, and ifstat.
iftop– network traffic viewer. Ex:
iftop -i eth0
nethogs– network traffic analyzer.
iotop– interactive I/O viewer. Get an overview of storage r/w activity.
iostat– for storage I/O statistics.
netstat– for network statistics.
ss– utility to investigate sockets.
Here are some related articles I’ve written in the past covering command-line system monitoring tools:
top– Here’s how to customize it.
atop– For Linux server performance analysis.
nmon– htop and top Alternatives:
htop– Quick Guide & Customization.
bashtop– the ‘cool’ top alternative.
ssh – secure command-line access to remote Linux systems.
Other than my Homelab, most of my Sysadmin related work is performed remotely. With clients’ server locations in the Americas, Europe, Asia, and Australia. Access command line on a remote server; you can use the
ssh -i [key_file] [user]@[hostname/ip] -p [port]
-i identity_file, selects a file from which the identity (private key) for public-key authentication is read.
-p port, is used to select which port to connect to on the remote host.
ssh -i path/to/key_file root@ip_address -p 2222
SSH can also be run securely on a graphical desktop using terminal emulators such as Terminator.
In Part 3, we will take a look at using
sudo – execute commands with administrative privilege.
sudo (Super User DO) command in Linux is regularly used as a prefix to commands which only the superuser (root) has permission to run. If you are not logged in with the root user, you can use the
sudo command to preface a command in order to run that command with root privileges. For example:
$ sudo apt install terminator
Once you run a
sudo command, as a security precaution, you will be prompted to enter the password of the current non-root user session. (not the root password)
cd – Directory navigation.
cd command allows you to change directories. To navigate into the root directory, use:
Navigate to your home directory use:
Navigate up one directory level:
Navigate to the previous directory (or back):
To navigate to a multi-level directory use:
pwd command shows your current directory location. pwd stands for “print working directory”. Also, see the
ls command from part 1.
hydn@ubuntu:~$ pwd /home/hydn
Print the current directory, and resolve all symlinks (i.e. show the “physical” path):
cp – Copying files and folders
cp command will create a copy of a file for you. For example:
cp file1 file1_backup
This command will create a copy of “file1” named “file1_backup”, and “file1” will remain unmodified.
To copy a directory and it’s contents use the command with
cp -r directory1 directory1_copy
Recursively means copying the directory and all its files and subdirectories and all their files and subdirectories and so on.
mv – moving files and folders.
The mv command is used to move a file from its location to a different location or rename it. For example:
mv file1 file0
This will rename the “file1” to “file0”.
mv file1 /home/user/Desktop/
will move “file1” to your Desktop directory, but it will not rename it.
To move AND rename, you can specify a new file. For example:
mv file1 /home/user/Desktop/file0
You can substitute
~ in place of /home/user/ which is faster for home directory related commands. For example:
mv file1 ~/Desktop/
When using the
sudo command or logged in as root, then
~ will be the home directory of root.
7. Removing files and folders.
rm command to remove/delete a file in a directory. For example:
rmdir command to delete an empty directory.
rm -r to delete a directory and all of its contents recursively:
rm -r /path/to/dir/
You can also create an empty file with
touch command or
Or create a new directory you can use the
In Part 5, we will look at creating and editing files with
man – for reading system reference manuals.
The man command displays a manual for any terminal commands we need help or info. All man pages include but are not limited to the following standard sections: Name, Synopsis, Description, Examples, and See Also.
apropos – Search man page names and descriptions.
apropos command searches the man page names and descriptions. It can be used to find what commands to use for a certain job.
For example, search for available commands related to the firewall:
10. Search your package manager for available packages.
If you’d like to search for packages not already installed on your system, you can use the following commands to search for packages using your Linux distro’s package manager:
apt search [keyword]
apt-cache search [keyword]
hydn@ubuntu:~$ apt-cache search "nginx web" nginx-core - nginx web/proxy server (standard version) fcgiwrap - simple server to run CGI applications over FastCGI libnginx-mod-http-dav-ext - WebDAV missing commands support for Nginx libnginx-mod-http-ndk - Nginx Development Kit module nginx-extras - nginx web/proxy server (extended version) nginx-full - nginx web/proxy server (standard version) nginx-light - nginx web/proxy server (basic version)
dnf search [keyword]
zypper se [keyword]
That’s it for now. If you’ve found part 2 useful, please share, subscribe, bookmark, and leave a comment or suggestions below.