Tomanage a Linux remote machine like a virtual private server (VPS), system administrators commonly use a command-line interface (CLI). While some Linux distributions offer a graphical user interface (GUI), commands are more efficient and flexible with a CLI.
For example, you can replace specific entries in multiple files using a single command, which takes time in a GUI. However, using bash shell can be tricky since Linux has many commands for various tasks.
To run Linux commands in a remote server, connect via SSH using PuTTY or Terminal. Alternatively, Hostinger VPS hosting users can leverage our built-in Browser terminal to run the commands directly from their web browsers.
The global regular expression or grep command lets you find a word by searching the content of a file. This Linux command prints all lines containing the matching strings, which is useful for filtering large log files.
The script contains the searched regular expression pattern, the replacement string, and subcommands. Use the s subcommand to replace matching patterns or d to delete them.
The locate command lets you find a file in the database system. Add the -i option to turn off case sensitivity and an asterisk (*) to find content with multiple keywords. For example:
The ps command creates a snapshot of all running processes in your system. Executing it without an option or argument will list the running processes in the shell with the following information:
There are 64 signals for terminating a program, but SIGTERM and SIGKILL are the most common. SIGTERM is the default signal that lets the program save its progress before stopping. Meanwhile, SIGKILL forces programs to stop and discard unsaved progress.
You can use an absolute time in a 24-hour format or a relative one like +5 to schedule it in five minutes. The message is a notification sent to logged-in users about the system shutdown.
Running it without arguments displays information about all network interfaces in your system. To check a specific interface, add its name as an argument without an option. For a more specific task, use the following options:
Did you know that you can edit a text file with Linux commands using SSH? Instead of editing a file locally and uploading it via FTP, you can edit the file instantly on your account using the vim or nano command.
Hostinger offers a GPT-powered VPS AI Assistant that lets you easily generate Linux commands to manage your server. It is available in all VPS plans and accessible from the VPS overview side menu in hPanel.
Since there are many Linux commands with various syntaxes, remembering them can be difficult. To help you easily find a utility, download our must-have free Linux Commands Cheat Sheet PDF here:
How to Configure and Manage Ubuntu Firewall with the UFW Command
How to Install and Use the Linux Screen Command
How to List Users in Ubuntu with Linux Commands
How to Change Password in Linux
We will be running these commands on a Ubuntu server, but you can follow along on any modern Linux distribution. You can set up a Ubuntu server for this tutorial by following our guide to Initial Server Setup on Ubuntu.
As you can see in the above image, using the command by itself without any arguments will give us an output with all the files and directories in the directory. The command offers a lot of flexibility in terms of displaying the data in the output.
While working within the terminal, moving around within directories is pretty much a necessity. The cd command is one of the important Linux commands you must know, and it will help you navigate through directories. Just type cd followed by directory, as shown below.
The -s flag creates a symbolic link (also known as a symlink or soft link) to a file or directory. A symbolic link is a special type of file that acts as a shortcut or pointer to another file or directory.
Note: Say you have a text file. If you make a symbolic link to that file, the link is only a pointer to the original file. If you delete the original file, the link will be broken, as it no longer has anything to point to.
A hard link is a mirror copy of an original file with the exact same contents. Like symbolic links, if you edit the contents of the original file, those changes will be reflected in the hard link. If you delete the original file, though, the hard link will still work, and you can view and edit it as you would a normal copy of the original file.
As you can see in the above example, the cat command, when used on our New-File, prints the contents of the file. At the same time, when we use echo command, it simply prints whatever follows after the command.
The less command is used when the output printed by any command is larger than the screen space and needs scrolling. The less command allows the user to break down the output and scroll through it with the use of the enter or space keys.
The grep command is a powerful and versatile text search tool in Linux and Unix-based operating systems. It can search for specific patterns or strings in one or more files and filter the output of other commands.
When outputting large files, the head and tail commands come in handy. These commands display the beginning or end of a file, respectively. They are commonly used to quickly view the contents of a file without having to open it in a text editor.
The diff, comm, and cmp commands are all used to compare files in Linux and Unix-based operating systems. These commands can be used to identify differences between two files, merge changes, and perform other file comparison tasks.
The cmp command is used to compare two files and display the first byte that is different between them. It can be used to identify differences between binary files or to check for corruption in files.
All three of these commands are essential tools for working with files in Linux and Unix-based operating systems. By understanding how to use the diff, comm, and cmp commands effectively, you can identify differences between files, merge changes, and perform other file comparison tasks.
The sort command is used to sort lines in a text file or standard input in Linux and Unix-based operating systems. It can be used to sort lines in ascending or descending order and to perform other sorting operations, such as sorting by fields or using a custom sorting order.
By default, the sort command sorts lines in ASCII collating sequence, which can lead to unexpected results when sorting numbers or special characters. To sort numbers in numerical order, you can use the -n option.
The sort command is a powerful and flexible tool for working with text files in Linux and Unix-based operating systems. By understanding how to use the sort command effectively, you can sort lines in text files, sort lines based on specific fields, and perform other sorting operations.
The ssh command in Linux and Unix-based operating systems establishes a secure shell connection to a remote server. The command provides a secure encrypted connection between the local and remote servers, allowing users to run commands and transfer files securely.
The service command in Linux is used to manage system services, which are long-running processes that are started at boot time and run in the background. These services are responsible for providing various system functionalities, such as networking, database management, and user authentication.
Now, obviously, localhost is just one hop (the network interface itself). You can try this same command with any other domain name or IP address to see all the routers your data packets pass through to reach the destination.
If you want to download a file from within the terminal, the wget command is one of the handiest command-line utilities available. It is one of the important Linux commands you should know when working with source files.
When you specify the link for download, it has to directly be a link to the file. If the file cannot be accessed by the wget command, it will simply download the webpage in HTML format instead of the actual file that you wanted.
Why do we need UFW when we have IPTables? Because IPTables is pretty difficult for a newbie. UFW makes things extremely easy. See the below example where we are trying to allow port 80 for our webserver.
Getting yourself well versed with the package manager of your distribution will make things much easier for you in the long run. So even if you have a GUI based package management tool installed, try an make use of the CLI based tool before you move on to the GUI utility. Add these to your list of Linux commands you must know.
This is the quote displayed when a sudo-enabled user(sudoer) first uses the sudo command to escalate privileges. This command is equivalent to logging in as root (based on what permissions you have as a sudoer).
This command was created to convert and copy files from multiple file system formats. In the current day, the command is simply used to create bootable USB for Linux but there still are some things important you can do with the command.
The top command in Linux is a system monitoring tool that displays real-time information about system processes and resource usage. It provides a dynamic, real-time view of system activity, including CPU usage, memory usage, and process information.
Linux has a worldwide market share of 4.05% on desktops, but over 90% of all cloud infrastructure and hosting services run in this operating system. For this reason alone, it is crucial to be familiar with popular Linux commands.
An argument or parameter is the input we give to a command so it can run properly. In most cases, the argument is a file path, but it can be anything you type in the terminal.
3a8082e126