Thank you for all the likes, kind words, and support you’ve given us in the first two parts of our Linux commands series.
In the first article, we covered commands for users who are new to Linux and need essential knowledge to get started.
In the second article, we discussed commands that are useful for users at a middle level, helping them manage their own systems effectively.
In this article, we’ll explore the commands needed to administer a Linux server.
41. ip Command
The “ip command” is a networking tool that is used to manage network settings such as configuring IP addresses, managing interfaces, setting up routing tables, troubleshooting network issues, and much more.
Check Active Network Interfaces in Linux
To check active network interfaces on a Linux system, you can use the following command, which will list all network interfaces along with their state, their assigned IP addresses, and other relevant information.
ip addr show
How to Enable/Disable Network Interfaces in Linux
To disable or enable a network interface on a Linux system, you can use the following commands:
sudo ip link set <interface_name> down sudo ip link set <interface_name> up
The “down” command disables a network interface, preventing it from sending or receiving data. Conversely, the “up” command enables the interface, allowing it to actively send and receive data.
Set a Static IP Address in Linux
To assign a static IP address to a network interface in Linux, you can use the following command:
sudo ip address add <ip_address>/<subnet_mask> dev <interface_name>
For example, to assign the IP address 192.168.1.100 with a subnet mask of 24 (equivalent to 255.255.255.0) to the interface eth0, you would use:
sudo ip address add 192.168.1.100/24 dev eth0
42. ss Command
The ‘ss command‘ displays various network-related information such as network connections, routing tables, interface statistics, masquerade connections, multicast memberships, etc.
List Active Network Ports in Linux
To list active network ports in Linux, you can use the following command, which will list all active TCP and UDP sockets that are in the listening state, along with their associated port numbers.
sudo ss -tuln
Here’s what each option means:
-t
– Show TCP sockets.-u
– Show UDP sockets.-l
– Show only listening sockets.-n
– Show numerical addresses instead of resolving them to hostnames.
43. nslookup Command
The ‘nslookup command‘ is a network utility program used to obtain information about domain names, IP addresses, and other DNS records. It allows users to look up information such as the IP address associated with a domain name, or the domain name associated with an IP address.
Find the IP Address of a Website
To perform a DNS lookup for the domain “google.com“, use the following command, which will show the IP address(es) associated with the domain, along with other DNS information such as the authoritative name server(s) for the domain.
nslookup google.com
If the nslookup command is not found, you need to install it using the following appropriate command for your specific Linux distribution.
sudo apt install dnsutils [On Debian, Ubuntu and Mint] sudo yum install dnsutils [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] sudo emerge -a sys-apps/dnsutils [On Gentoo Linux] sudo apk add dnsutils [On Alpine Linux] sudo pacman -S dnsutils [On Arch Linux] sudo zypper install dnsutils [On OpenSUSE] sudo pkg install dnsutils [On FreeBSD]
Find Domain’s MX Records
To query the Mail Exchanger (MX) record for a domain, you can use the following syntax.
nslookup -type=mx google.com
Find Domain’s NS Records
To query the Name Server (NS) records for a domain, you can use the following syntax.
nslookup -type=ns google.com
Find Domain’s DNS Records
To find all DNS records for a domain, you can use the following syntax.
nslookup -type=any google.com
Find Domain’s SOA Records
To query the Start of Authority (SOA) record for a domain, you can use the following syntax.
nslookup -type=SOA google.com
44. dig Command
The ‘dig command‘ (stands for domain information groper) is a commonly used network tool for querying DNS nameservers for information about host addresses, mail exchanges, nameservers, and related information.
This tool can be used from any Linux (Unix) or Macintosh OS X operating system. The most typical use of dig is to simply query a single host.
dig google.com
45. uptime Command
The ‘uptime command‘ is the most useful tool that displays the information about your system’s current uptime and load average over different time intervals.
uptime
46. wall Command
One of the most important commands for administrators is the ‘wall‘ command which is used to broadcast important notifications or announcements to all users currently logged into the system.
wall "we will be going down for maintenance for one hour sharply at 03:30 pm"
47. mesg Command
The “mesg” command is used to control whether other system users can send messages to your terminal.
To allow other users to send messages to your terminal, use:
mesg y
To disallow other users from sending messages to your terminal, use:
mesg n
By default, most systems have the “mesg” permission set to "y"
, allowing other users to send messages to your terminal.
48. write Command
The “write” command is used to send messages to another user who is logged into the same system.
write john
You can then type your message and press "Ctrl+D"
to send it.
49. talk Command
The “talk” command is used for interactive communication between two users logged into the same system.
talk tecmint
If the talk command is not installed, use the following appropriate command for your specific Linux distribution.
sudo apt install talk [On Debian, Ubuntu and Mint] sudo yum install talk [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] sudo emerge -a sys-apps/talk [On Gentoo Linux] sudo apk add talk [On Alpine Linux] sudo pacman -S talk [On Arch Linux] sudo zypper install talk [On OpenSUSE] sudo pkg install talk [On FreeBSD]
50. w Command
What makes the ‘w‘ command seem funny? Surprisingly, it’s not a joke at all. Despite being just one letter long, the ‘w‘ command is quite meaningful.
It combines the functionality of both the ‘uptime‘ and ‘who‘ commands, providing information about system uptime and currently logged-in users, all with just a single keystroke!
w
51. rename Command
The ‘rename command‘, as its name implies, is used to rename files. It allows users to rename specified files by replacing the first occurrence found in the file name.
For example, if you want to rename multiple files with similar patterns or prefixes, the ‘rename‘ command offers a convenient way to quickly rename them in batch.
rename 's/file_//' file_*.txt
52. top Command
The ‘top command‘ displays real-time information about system processes, including CPU usage, memory usage, and other system metrics.
top
53. mkfs.ext4 Command
The ‘mkfs.ext4 command‘ is used to create a new ext4 file system on the specified device. It’s important to note that if the wrong device is specified, the entire block will be wiped and formatted.
Therefore, it is highly recommended not to run this command unless you fully understand its implications and are certain of the device you are targeting. Misuse of this command can lead to data loss or corruption.
Here’s an example of how you can use the mkfs.ext4 command to create an ext4 file system on a specified device:
sudo mkfs.ext4 /dev/sdb1
54. vi/nano and emacs Commands
vi is a text editor that is part of the Unix and Linux operating systems that allows users to create, edit, and save text files.
vi myfile.txt
nano is a simple and user-friendly text editor that is ideal for beginners or those who prefer a straightforward editing experience.
nano myfile.txt
emacs is a powerful and extensible text editor with advanced features that offers a wide range of functionalities beyond basic text editing.
emacs myfile.txt
55. rsync Command
The ‘rsync command‘ is used for copying files, and it includes a handy '-P'
switch that shows a progress bar during file transfers. If you have rsync installed, you can create a simple alias to make copying files easier.
alias cp='rsync -aP'
Now, when you use the ‘cp command‘ in the terminal, it will actually use rsync with the '-aP'
options, giving you a progress bar during file copying.
In addition, keeping and maintaining backups is a crucial yet often tedious task for system administrators. Rsync is a great tool (among several others) that can be used in the terminal to create and manage backups efficiently.
56. free Command
Monitoring memory and system resources is crucial for administrators, and the ‘free command‘ is a helpful tool for this purpose, as it provides information about the amount of free and used memory in the system.
free free -k free -m free -g
57. mysqldump Command
The ‘mysqldump command‘ is used to create backups of MySQL databases. It allows users to dump all or specific database data into a specified file.
For example, the following command creates a backup of all databases and saves it to a file named ‘backupfile.sql‘.
mysqldump -u root -p --all-databases > /home/ravi/backupfile.sql
58. mkpasswd Command
The ‘mkpasswd command‘ is used to generate hard-to-guess, random passwords of specified lengths. It’s particularly useful for creating secure passwords for various purposes.
For example, the following command generates a random password of 10 characters, such as “zI4+Ybqfx9“.
mkpasswd -l 10
“`
Note that the "-l"
option is used to specify the length of the password, which is commonly used in scripting languages to generate random passwords for various purposes.
To use the “mkpasswd” command, you may need to install the “expect” package using the following appropriate command for your specific Linux distribution.
sudo apt install expect [On Debian, Ubuntu and Mint] sudo yum install expect [On RHEL/CentOS/Fedora and Rocky/AlmaLinux] sudo emerge -a sys-apps/expect [On Gentoo Linux] sudo apk add expect [On Alpine Linux] sudo pacman -S expect [On Arch Linux] sudo zypper install expect [On OpenSUSE] sudo pkg install expect [On FreeBSD]
59. paste Command
The “paste” command is used to merge lines of files. It takes lines from multiple input files and concatenates them horizontally, with each line separated by a delimiter.
paste File1.txt File2.txt
60. lsof Command
The ‘lsof command‘ stands for “list open files” and displays all the files that your system has currently opened. It’s very useful to figure out which processes uses a certain file, or to display all the files for a single process.
lsof
This is not the end. A System Administrator does a lot of tasks to provide you with such a nice interface on which you work. System Administration is actually an art of learning and implementing in a very perfect way.
We will try to provide you with all the other necessary information that a Linux professional must learn. Linux itself is a process of continuous learning.
Your kind words are always appreciated, as they encourage us to put in more effort to provide you with knowledgeable articles.
47 and 48 are mixed up
How to find out network interface uptime by a standard base system tools?
Have a look at this thread, I belieave it may answer your question.
https://superuser.com/questions/617141/how-can-i-get-information-about-an-network-interface-uptime
When executed “mkpasswd” command with
-l
option, I get below error.Without
-l
option it works.@Praneeth,
Thanks for sharing the tip, it seems you’re tried these instructions on Ubuntu based distro, so seems some difference options and arguments replaced or changed in the latest version of mkpasswd package..
nice content.
$wall “hello world”
wall: will not read hello world – use stdin.
good..helped me soo muchh..:):):) Thank u Avishek kumar
Pleased to know that @ karthikeyan
very good, helped me a lot! :) good job, guys!
Thanks for the feedback @ Rondinelli
Respect Bro .
Thanks @ Z C :)
Good concise tutorial, thanks.
welcome @ cory
Yeah, except ifconfig is going away for the more feature-complete ip command. ip pretty much has the same syntax setup as git, but can let you do anything and everything you’d want, from basic interface up/down commands, to configuring vlans and bridged connections that you’d normally only be able to do on an enterprise-grade router.
“54. Command: vi/emac/nano”
First of all, it is spelled “emacs” NOT “emac”. Secondly, where is your explanation of the editor?
Unfortunately, all your explanations are too simplified to be usefull.
“man” should be the the first command explained in the first section, not in the second!
Sorry for that typo, corrected now.
I notice you explain deprecated commands like ifconfig and nslookup. you should at least cover their replacement comnands (ip, ss, host, etc..) as well.
They are either easier to use or in some cases the same flags are used and they do a better job of output.
examples:
ifconfig -> ip addr show (or shorthand “ip a sh”)
nslookup myhost -> host myhost
netstat -anp -> ss -anp
There are way more but you get the idea. :-)
Sorry, we forget to mention “ifconfig” replacement command “ip”. Here is the article on same. ip command examples.
There seems to be something missing from 59. Command: paste
I finally did a paste file1 file2>file3
and I got the desired result.
I didn’t see that explanation in this tutorial.
Cheers
Rick
Just be careful that you don’t issue “ifconfig eth0 down” over a SSH connection to a remote box. You might end up needing 2hr of driving just to issue one command from the console. Not that I’ve ever done this. :-)
Also, a couple typos:
s/eht0/eth0/g
s/Query Start of Autory/Query Start of Authority/
s@Command: vi/emac/nano@Command: vi/emacs/nano@
well said @ Gumnos