Linux Commands Frequently Used by Linux Sysadmins – Part 3

Last week and a week ago, I published Part 1 and Part 2 of this five-part series titled: Linux Commands Frequently Used by Linux Sysadmins, Those two articles took us a little deeper into what I believe are about 50 to 100 commands that are frequently used by Linux Sysadmins and power users. Also, see Part 4 and Part 5.

Let’s jump into Part 3 with another set of commands and command-line tools that are often used for file transfer, file manipulation, network troubleshooting, and other administrative tasks performed by Linux systems. In this and future series, I will group related commands as closely as possible and also add a table of contents to interconnect all five parts of this series.

1. rsync – Remote file transfer and syncing.

Rsync (Remote Sync) is an open-source tool for file syncing between both local and remote systems. Back in 2016, I was task assigned With establishment A global CDN-backed mirror for Linux distros and other repositories: EvoWise CDN (this project heavily depends on rsync Hundreds of terabytes of files to be sure are always in-sync. Over time, more distros have introduced their own global CDN supported mirrors; However, there are still a handful of multi-distro and multi-software mirrors. Here is an example of using rsync Commands to backup files remotely:

rsync -avze ssh /path/to/directory1/ user@IP_or_hostname:/remote/backup/directory1/

To download from a remote directory, reverse the order of commands:

rsync -avze ssh user@IP_or_hostname:/remote/backup/directory1/ /path/to/directory1/

Rs Sync is a whole topic in itself. As such, let’s revisit this order in its entirety at a later date. In the meantime, the best place to start would be to read this documentation And cheat sheets,

2. tar, gzip, b2zipAnd zip file manipulation.

tar (tape archive) is an archiving utility.

To remove from a collection use: (with options x = remove, v = verb, f = file):

tar - xvf archive.tar

To create an archive from files or directories, use: (with option c = create)

tar -cvf archive.tar file1 file2 file3

To create a compressed archive, use: (with option z to compress with gzip)

tar -cvzf archive.tar file1 file2 file3

To show all files placed in archive (with option) t = list):

tar -tvf archive.tar

gzip Stands for GNU Zip. It is used for file compression and decompression.

To create a compressed file, use:

gzip file1

To decompress a file, use:

gunzip file1.gz

As a collection created using tar will not be compressed without additional options; this can be done using gzip,

Use to combine files into a compressed archive (with the option z = gzip):

tar -cvzf archive.tar.gz file1 file2

resulting archive.tar.gz

To decompress and extract files from a gzip archive, use:

tar -xvzf archive.tar.gz

bzip2 Similar to gzip. It just uses a different compression algorithm.

To create a compressed file, use:

bzip2 file1

To decompress a file, use:

bunzip2 file1.bz2

Use to combine files into a compressed archive (with the option j = bzip2):

tar -cvjf archive.tar.bz2 file1 file2

resulting archive.tar.bz2

Apex decompress and extract files from a bzip2 archive use:

tar -xvjf archive.tar.bz2

zip Used for packaging and compressing (for archiving) files.

To combine individual files into a compressed archive, use:

zip archive.zip file1 file2

To combine entire directories into a single compressed archive:

zip -r archive.zip directory1 directory2 directory3

To decompress and extract files or directories from a ZIP archive, use:

unzip archive.zip

To show all files stored in an archive, use:

unzip -l archive.zip

3. locate – Search files in Linux.

In part 1, we talked about using find And grep, Locate uses a background process that runs periodically to locate and store your system’s files in its database. Its only advantage in this is… speed!

On some distros, Ubuntu, for example, you have to manually install:

sudo apt-get install locate

To discover file usage (with option i = ignore case):

locate -i filename

for example:

hydn@ubuntu:~$ sudo locate -i firewall
/etc/fail2ban/action.d/firewallcmd-allports.conf
/etc/fail2ban/action.d/firewallcmd-common.conf
/etc/fail2ban/action.d/firewallcmd-ipset.conf
/etc/fail2ban/action.d/firewallcmd-multiport.conf
...

The database will be updated daily through cron. However, if you need to update it manually, you can use:

sudo updatedb

4. ps – Information about currently running processes.

ps-ox |  low

In Part 1, we saw pstree, a more visual alternative to the ps command. a way to use ps One is to use the following to get more information about running processes:

ps aux | less

a The option will list all users’ processes except group leaders and processes that are not associated with Terminal.

u The option provides detailed information about each process.

x option will list all processes when used together a the option.

To show a process tree:

ps axjf | less

To show information about threads, use:

ps -eLf | less
ps axms | less

To see each process running as root in user format, use:

ps -U root -u root u

To show only the process ID of syslogd, use:

ps -C syslogd -o pid=

To show only the name of PID 411, use:

ps -q 411 -o comm=

The above examples are man ps,

5. Using bash script.

A bash script is a plain-text file that contains a series of commands. These are the commands we usually type in the command-line (ie, rsync ... either cp ...), but would like to save time by not typing commands manually every time, or, we would like to schedule those commands to be run later using cron.

To create a bash script, place #!/bin/bash at the top of the file. Here’s a simple bash script to run a backup:

#!/bin/bash
rsync -avze ssh /path/to/directory1/ user@IP_or_hostname:/remote/backup/directory1/
echo "Remote backup for $(date) " | mail -s "backup complete" user@youremail

Once you type or paste it into a new file, you can save it as scriptname.sh. In this case, Remotebackup.sh. Then, change the permissions of the file to make it executable:

chmod +x remotebackup.sh

To execute/run the script from the current directory, you type:

./remotebackup.sh

Or you can schedule a bash script to be run using corn, as discussed in the next section.

See more Ubuntu’s Beginner Bashscripting,

6. cron – Schedule scheduled tasks to run.

cron Daemon is a built-in Linux tool that periodically runs scheduled tasks (commands or shell scripts) at certain times, dates or intervals. Sysadmins typically use cron to automate system maintenance and administration tasks. For example, by using cron to run rsync At night.

Here a. is an example of cron A single-line entry is used to run the backup script every night at 2 o’clock:

0 2 * * * ~/myscripts/remotebackup.sh

To get started, read cron setup guide created by Ubuntu And red hat more references cron man page, there are also online cron expression generator,

7. nmcli – Network Management.

NetworkManager is a set of tools to manage network connectivity on your Linux system. It works for wired, wireless, and even Bluetooth connections.

To show all available network devices use:

nmcli d

for example:

NMCLI D

Red Hat has published a great to networking guide nmcli,

8. ping – Send ICMP ECHO_REQUEST to the network host.

ping (packet internet grouper) command is used to check network connectivity between server and other host. You can enter the IP address or URL, and the ping command then sends a data packet to the specified address with a “ping” message and waits for a response from the destination server/host. The time taken to receive this response package is reported. This time is called latency. Low-latency = faster connection response.

ping [hostname/ip]

for example:

ping example

Use -c Flag to specify the number of ping packets to send. for example:

ping -c 5 IP_ADDRESS

9. traceroute – Verifies route packets are routed to a specified host.

traceroute Checks the route that the packet takes to reach a specified host. It uses the Time-to-Live (TTL) field of the IP protocol and tries to receive an ICMP TIME_EXCEEDED response from each gateway along the path to the host. (Source: man tracer) traceroute network latency can help find the source of delays, outages and other network routing issues.

tracer example

Also, have a look mtr (my tracer),

10. nslookup – Interactively query Internet Name Servers (NS).

nslookup (Name Server Lookup) is a command used to collect information from the Domain Name System (DNS). with nslookupsysadmins can query domain name or IP address information.

To view the A record for a domain, use:

nslookup haydenjames.io

To find the authoritative server of a domain to see its NS records, use:

nslookup -type=ns ubuntu.com

To view the MX records for a domain, use:

nslookup -query=mx redhat.com

To see the SOA (beginning of authority) of a domain, use:

nslookup -query=soa debian.com

To show a list of DNS records for a domain, use:

nslookup -type=any mysql.com

To see the rDNS (reverse DNS) of a domain, use:

nslookup [domain_IP]

See also, host And dig Command.

Additional Tip: check out interpretshell.com To match command-line arguments with their help text.

that’s it for now. I hope you enjoy part 3. share please, to subscribeBookmark, and leave any comments or suggestions you may have.

Next – Linux Commands Frequently Used by Linux Sysadmins – Part 4 >

Leave a Comment