Linux OS Management Commands

Linux OS Management Commands

01.07.2022
Author: HostZealot Team
2 min.
1149

When it comes to Linux, most people immediately recall the famous meme from the cult movie "The Hangover", in which Zach Galifianakis appears surrounded by complex mathematical formulas. As if only the chosen ones were able to master the art of Linux management, and for ordinary mortals, this is something incomprehensible. By "the chosen ones" we mean bearded programmers who are able to sort an array with random numbers using the "bubble" method with one eye, and who are able to count linear algorithms in their minds.

All this, of course, is overblown hyperbole, but in fact, managing the Linux operating system will not cause any problems even for a beginner. All you need is to study the basic commands of the Linux terminal, understand their meaning and bookmark this article in case you need to refresh your knowledge. It will take a little practice to understand the logic of the OS, and then everything will go like clockwork. So, let's go.

Basic Linux commands for network management

Let's start with the IP command, a standard tool needed by any self–respecting network administrator. This command is used both to configure new PCs and to systematically eliminate network problems that may appear over time. The IP command allows you to:

  • get information about network addresses;
  • manage traffic routing;
  • output data about all network devices, interfaces, and tunnels.

Its syntax looks like this:

ip <OPTIONS> <OBJECT> <COMMAND>

The most significant is the keyword <OBJECT>, where you can substitute a variety of keys:

  • address — the protocol address (IPv4 or IPv6) on the device.
  • tunnel — IP tunnel.
  • route — routing table entry.
  • rule — a rule in the routing policy database.
  • vrf — control of virtual routing devices and traffic redirection.
  • xfrm — IPsec policy parameters.

For clarity, here are some examples of the correct use of the IP command in the daily life of the sysadmin.

  • [root@server ~]# ip address show – show in the terminal the IP addresses assigned to the interface on the server;
  • [root@server ~]# ip address add 192.168.1.254/24 dev enps03 – assign an IP address to the interface;
  • [root@server ~]# ip address del 192.168.1.254/24 dev enps03 – remove IP address from the interface;
  • [root@server ~]# ip link set eth0 up – change the interface status, in our case we enable eth0;
  • [root@server ~]# ip link set eth0 down – disable eth0 interface status;
  • [root@server ~]# ip link set eth0 promisc on – switch eth0 to network packet reception mode;
  • [root@server~]# ip route add default via 192.168.1.254 dev eth0 – add the default route used by all addresses through the local gateway available on the eth0 device;
  • [root@server ~]# ip route delete 192.168.1.0/24 via 192.168.1.254 – delete the route for 192.168.1.0/24 that uses gateway 192.168.1.254 for access.

There are also many other commands, we have only given the most common variants of them.

There are also a number of other important network commands:

  • MTR is a program that functions in command-line mode, is needed to diagnose networks, it is actively used to eliminate existing problems. It has the syntax "mtr <options> hostname/IP". The mtr command allows you to diagnose the route and connected devices – for example, if the server response time increases or if the number of lost packets increases.
  • Tcpdump – this utility allows you to capture and analyze data packets, it can be installed on the server using the command [root@server ~]# dnf install -y tcpdump. The utility's capabilities even allow you to filter traffic and "grab" only those packets that come from a specific host. For example, to capture packets coming from the address 7.7.7.7, you can use the following command: [root@server ~]# tcpdump -i eth0 -c 10 host 7.7.7.7.
  • Netstat – this tool is used to get information about all network connections and routing tables. By default, it may not be present in the system, then the utility will need to be installed using the command [root@server ~]# dnf install net-tools. It is often used without any parameters, unchanged: [root@server ~]# netstat.
  • Ping – this tool helps to check at the IP level the possibility of communication of individual TCP/IP systems. Allows you to diagnose network integrity problems, and is extremely simple and easy to use.
  • Nslookup – This Linux terminal command is used to perform DNS queries and obtain similar information about IP addresses and domains. For example, using the command [root@server ~]#nslookup hostzealot.com you can get the A-record of the specified domain.

Now let's move on to other categories of useful Linux commands.

Linux commands for viewing documentation

Reference information and documentation can be accessed using the following commands:

  • Whatis – display a brief description of the program;
  • Whereis – show the full path to the executable file;
  • File – allows you to identify the file type or its extension;
  • Program_name —help – get detailed information about the specified program or utility;
  • Whoami – display the user's UID.

Basic Linux commands for network management

There are 4 most important commands for managing processes:

  • KILL / XKILL / PKILL / KILLALL – different variations of the same command that allows you to "kill" processes. Only with nuances. For example, after the "Kill" command, you need to add the PID of the process, and for "xkill" it is enough to click on the desired window to complete the work. "killall" and "pkill" fit in with the process name. Use it depending on the situation.
  • PS / PGREP – allows you to get the identifier (PID) of various processors on the server. You can add the -e option to display the PID of a specific process.
  • TOP / HTOP – display processes. Convenient for monitoring.
  • TIME – shows the execution time of the process. In fact, it is a stopwatch. It is useful to assess the lag of your algorithm implementation from the standards.

linux os management commands

Basic Linux commands for network management

Here we have two key teams:

  • USERADD / USERDEL / USERMOD – needed for adding, deleting, and changing user accounts. They are not needed so often, they are most often used at the initial stage of server configuration.
  • PASSWD – using this command, you can replace the password of the specified account. As a superuser, you can freely reset any passwords, delete them and change them at your discretion.

Linux user environment commands

  • SU / SUDO – allows you to run the program on behalf of a specific user. The difference between SU and SUDO is that the first command is executed with switching to another user, and the second only executes the command on his behalf. SUDO is used more often, it is considered safer.
  • DATE – display the date and time, it can also be used to format the data display as you like, set a different time format, etc.
  • ALIAS is an interesting command that allows you to synonymize other Linux commands. That is, you can create new ones, group old ones, or simply change the names of existing ones. A cool thing for shortening long and hard-to-remember commands.
  • UNAME – displays key information about the system, it is recommended to use with the -a parameter.
  • UPTIME – shows the time of continuous operation of the system. It is used to find out when the server was last restarted.
  • SLEEP – allows you to turn off the computer or server after a certain time.

Linux console commands for working with text

  • LESS – needed to view long text that does not fit on the screen. Useful when the terminal does not support scrolling.
  • HEAD / TAIL. The first command displays the first 10 lines from the file, the second shows the "tail", that is, the last 10 lines of it. You can change the number of rows displayed using the -n option.
  • GREP – helps to find the text according to a given template.
  • SORT – sorts the text strings according to the specified criteria. For example, the -n option allows sorting by numeric values.
  • WC is a useful tool that allows you to count words, strings, bytes, and characters in an object.
  • DIFF – used to compare two files line by line. Moreover, an important advantage of this command is that only different rows are displayed, while matches are ignored.

Basic Linux commands for network management

Perhaps one of the most important and frequently used Linux console command sets:

  • LS – directory browsing, used with the -l (List) and -a (All) options.
  • CAT – allows you to quickly create a file and put text in it. Use the > redirect operator to redirect text to a file.
  • CD – transition from the current directory to the specified one. When entered without parameters, it returns to the home directory.
  • PWD – displays the current directory.
  • MKDIR – creates a new directory. It is often used in conjunction with the -p option to create the entire structure of subdirectories, even if they have not yet been created.
  • FILE – displays the file type.
  • CP – copies a file or directory from the "Source File" or "Source Directory" parameter to the file or directory specified by the "Target File" or "Target Directory" parameter.
  • LN – useful for creating hard or symbolic links to files. Facilitates access to certain files and directories in the future.
  • RM – is used to delete files and folders. It is used to restore order in the system.
  • MV – moves or renames files/directories. For Linux, these two types of operations do not differ, since renaming implies, in fact, moving the file to the same folder, but with a different name.

This concludes our analysis of Linux commands and tools, which are important for every self-respecting system administrator. Thanks for your attention!

Related Articles