Linux Commands frequently used by Linux Sysadmins - Part 2

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.

Linux commands examples part 2

Table of Contents

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:

2. 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 command.

The ssh command provides secure encrypted connections between local and remote hosts. ssh is used for terminal access, file transfers (sftp), and tunneling other applications.

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.

For example:

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.

Also, take a look at telnet and scp – Securely Copy Files Using SCP with examples.

In Part 3, we will take a look at using rsync.

3. sudo – execute commands with administrative privilege.

The sudo (Super User DO) command on 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)

See also Red Hat’s Gaining Privileges documentation.

4. cd – Directory navigation.

The cd command allows you to change directories. To navigate into the root directory, use:

cd /

Navigate to your home directory use:

cd

or

cd ~

Navigate up one directory level:

cd ..

Navigate to the previous directory (or back):

cd -

To navigate to a multi-level directory use:

cd /path/to/directory/

The pwd command shows your current directory location. pwd stands for “print working directory”. Also, see the ls command from part 1.

Example:

hydn@ubuntu:~$ pwd
/home/hydn

Print the current directory, and resolve all symlinks (i.e. show the “physical” path): pwd -P

5. cp – Copying files and folders

The 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 -r recursively:

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.

6. 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”.

Another example:

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.

Use the rm command to remove/delete a file in a directory. For example:

rm file1

Use the rmdir command to delete an empty directory.

rmdir /path/to/empty/dir/

Use 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 cat:

touch filename

Or create a new directory, you can use the mkdir command:

mkdir newdir/

In Part 5, we will look at creating and editing files with vi and nano.

8. 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.

man [command]

Example:

man ssh

9. apropos – Search man page names and descriptions.

The apropos command searches the man page names and descriptions. It can be used to find what commands to use for a certain job.

apropos [keyword]

For example, search for available commands related to the firewall:

apropos 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:

Ubuntu/Debian:

apt search [keyword]

or

apt-cache search [keyword]

For example:

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)

CentOS/Fedora/RHEL:

dnf search [keyword]

OpenSuse:

zypper se [keyword]

See also, 90 Linux commands frequently used by Linux sysadmins.

That’s it for now. If you’ve found part 2 useful, please share, subscribe, bookmark, and leave a comment or suggestions below.

< Previous – Linux Commands frequently used by Linux Sysadmins – Part 1
Next – Linux Commands frequently used by Linux Sysadmins – Part 3 >

Similar Posts