Hostinger Linux Commands
Hostinger Linux Commands
Linux is a family of open-source Unix operating systems based on the Linux Kernel. They include Ubuntu,
Fedora, Debian, openSUSE, and Red Hat. Using Linux to manage a Virtual Private Server (VPS) is common
practice.
When operating Linux, you need to use a shell – a program that gives you access to the operating system’s
services. Most Linux distributions use a graphical user interface (GUI), making them beginner-friendly.
However, we recommend utilizing the command-line interface (CLI) because it’s quicker and offers more control.
Tasks that require multiple steps on the GUI can be done in a matter of seconds by entering commands into the
CLI.
So if you want to use Linux, learning the common utilities or commands will go a long way. This article will
discuss the 40 basic commands to help you use your Linux distro effectively.
2. pwd command
3. cd command
4. ls command
5. cat command
6. cp command
7. mv command
8. mkdir command
9. rmdir command
10. rm command
15. df command
16. du command
38. su command
40. ps command
A command may contain an option or a parameter. In some cases, it can still run without them. These are the
three most common parts of a command:
Option or flag modifies a command’s operation. To invoke it, use hyphens (–) or double hyphens (—).
Although the steps may differ depending on your Linux distribution, the Terminal application is usually found in
the Utilities section.
1. sudo command
Short for superuser do, sudo is one of the most popular basic Linux commands that lets you perform tasks that
require administrative or root permissions.
When using sudo, the system will prompt users to authenticate themselves with a password. Then, the Linux
system will log a timestamp as a tracker. By default, every root user can run sudo commands for 15
minutes/session.
If you try to run sudo in the command line without authenticating yourself, the system will log the activity as a
security event.
sudo
2. pwd command
Use the pwd command to find the path of your current working directory. Simply entering pwd will return the full
current path – a path of all the directories that starts with a forward slash (/). For example, /home/username.
pwd [option]
Running this command without an option will take you to the home folder. Keep in mind that only users with
sudo privileges can execute it.
cd Photos.
If you want to switch to a completely new directory, for example, /home/username/Movies, you have to enter
cd followed by the directory’s absolute path:
cd /home/username/Movies
4. ls command
The ls command lists files and directories within a system. Running it without a flag or parameter will show the
current working directory’s content.
To see other directories’ content, type ls followed by the desired path. For example, to view files in the
Documents folder, enter:
ls /home/username/Documents
Here are some options you can use with the ls command:
5. cat command
Concatenate, or cat, is one of the most frequently used Linux commands. It lists, combines, and writes file
content to the standard output. To run the cat command, type cat followed by the file name and its extension.
For instance:
cat filename.txt.
6. cp command
Use the cp command to copy files or directories and their content. Take a look at the following use cases.
To copy one file from the current directory to another, enter cp followed by the file name and the destination
directory. For example:
cp filename.txt /home/username/Documents
To copy files to a directory, enter the file names followed by the destination directory:
To copy the content of a file to a new file in the same directory, enter cp followed by the source file and the
destination file:
cp filename1.txt filename2.txt
To copy an entire directory, pass the -R flag before typing the source directory, followed by the destination
directory:
cp -R /home/username/Documents /home/username/Documents_backup
TUTORIALS Cart
7. mv command
The primary use of the mv command is to move and rename files and directories. Additionally, it doesn’t
produce an output upon execution.
Simply type mv followed by the filename and the destination directory. For example, you want to move
filename.txt to the /home/username/Documents directory:
mv filename.txt /home/username/Documents.
mv old_filename.txt new_filename.txt
8. mkdir command
Use the mkdir command to create one or multiple directories at once and set permissions for each of them. The
user executing this command must have the privilege to make a new folder in the parent directory, or they may
receive a permission denied error.
mkdir Music
To make a new directory called Songs inside Music, use this command:
mkdir Music/Songs
-p or –parents create a directory between two existing folders. For example, mkdir -p Music/2020/Songs
will make the new “2020” directory.
-m sets the file permissions. For instance, to create a directory with full read, write, and execute
permissions for all users, enter mkdir -m777 directory_name.
9. rmdir command
To permanently delete an empty directory, use the rmdir command. Remember that the user running this
command should have sudo privileges in the parent directory.
For example, you want to remove an empty subdirectory named personal1 and its main folder mydir:
rmdir -p mydir/personal1
10. rm command
The rm command is used to delete files within a directory. Make sure that the user performing this command has
write permissions.
Remember the directory’s location as this will remove the file(s) and you can’t undo it.
rm filename
For example, enter the following command to create an HTML file named Web in the Documents directory:
touch /home/username/Documents/Web.html
Moreover, adding the -i argument will turn off case sensitivity, so you can search for a file even if you don’t
remember its exact name.
To look for content that contains two or more words, use an asterisk (*). For example:
locate -i school*not
The command will search for files that contain the words school and note, whether they use uppercase or
lowercase letters.
For example, you want to look for a file called notes.txt within the home directory and its subfolders:
Once the grep command finds a match, it prints all lines that contain the specific pattern. This command helps
filter through large log files.
For example, you want to search for the word blue in the notepad.txt file:
15. df command
Use the df command to report the system’s disk space usage, shown in percentage and kilobyte (KB). Here’s
the general syntax:
df [options] [file]
For example, enter the following command if you want to see the current directory’s system disk space usage in
a human-readable format:
df -h
16. du command
If you want to check how much space a file or a directory takes up, use the du command. You can run this
command to identify which part of the system uses the storage excessively.
TUTORIALS Cart
Remember, you must specify the directory path when using the du command. For example, to check
/home/user/Documents enter:
du /home/user/Documents
Adding a flag to the du command will modify the operation, such as:
-h informs the last modification date of the displayed folders and files.
For instance, you want to view the first ten lines of note.txt, located in the current directory:
head note.txt
-n or –lines prints the first customized number of lines. For example, enter head -n 5 filename.txt to
show the first five lines of filename.txt.
For example, you want to show the last ten lines of the colors.txt file:
tail -n colors.txt
Programmers often use the diff command to alter a program instead of rewriting the entire source code.
For example, you want to compare two text files – note.txt and note_update.txt:
For instance, you want to create a new TAR archive named newarchive.tar in the /home/user/Documents
directory:
-x extracts a file.
Check out the more practical examples to know more about the other functions.
For example, the owner is currently the only one with full permissions to change note.txt. To allow group
members and others to read, write, and execute the file, change it to the -rwxrwxrwx permission type, whose
numeric value is 777:
To check the status of jobs in the current shell, simply enter jobs to the CLI.
After knowing what signal to use and the program’s PID, enter the following syntax:
There are 64 signals that you can use, but these two are among the most commonly used:
SIGTERM requests a program to stop running and gives it some time to save all of its progress. The
system will use this by default if you don’t specify the signal when entering the kill command.
SIGKILL forces programs to stop, and you will lose unsaved progress.
For example, the program’s PID is 63773, and you want to force it to stop:
For example, you want to know whether you can connect to Google and measure its response time:
ping google.com
The wget command retrieves files using HTTP, HTTPS, and FTP protocols. It can perform recursive downloads,
which transfer website parts by following directory structures and links, creating local versions of the web pages.
For example, enter the following command to download the latest version of WordPress:
wget https://wordpress.org/latest.zip
uname [option]
The top command can also help you identify and terminate a process that may use too many system resources.
history [option]
System calls
Library calls
Games
Special files
Miscellaneous
man [command_name]
For example, you want to access the manual for the ls command:
man ls
man 2 ls
For example, you can display the text Hostinger Tutorials by entering:
-E displays the default option and disables the interpretation of backslash escapes.
32. zip, unzip commands
TUTORIALS Cart
Use the zip command to compress your files into a ZIP file, a universal format commonly used on Linux. It can
automatically choose the best compression ratio.
The zip command is also useful for archiving files and directories and reducing disk usage.
For example, you have a file named note.txt that you want to compress into archive.zip in the current directory:
On the other hand, the unzip command extracts the zipped files from an archive. Here’s the general format:
unzip archive.zip
hostname [option]
For example, enter the following command to know your computer’s IP address:
hostname -i
When you use the useradd command, it performs some major changes:
Edits the /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow files for the newly created accounts.
passwd the_password_combination
For example, to add a new person named John, enter the following command simultaneously:
useradd John
passwd 123456789
userdel username
Running the apt-get command requires you to use sudo or root privileges.
apt-get [options]
These are the most common commands you can add to apt-get:
The nano command denotes keywords and can work with most languages. To use it, enter the following
command:
nano [filename]
vi uses two operating modes to work – insert and command. insert is used to edit and create a text file. On the
other hand, the command performs operations, such as saving, opening, copying, and pasting a file.
vi [filename]
jed has a drop-down menu interface that allows users to perform actions without entering keyboard
combinations or commands. Like vi, it has modes to load modules or plugins to write specific texts.
alias Name=String
For example, you want to make k the alias for the kill command:
alias k=’kill’
unalias [alias_name]
38. su command
The switch user or su command allows you to run a program as a different user. It changes the administrative
account in the current log-in session. This command is especially beneficial for accessing the system through
SSH or using the GUI display manager when the root user is unavailable.
When executed without any option or argument, the su command runs through root privileges. It will prompt you
to authenticate and use the sudo privileges temporarily.
Here are some acceptable options to use:
TUTORIALS
-p or –preserve-environment keeps the same shell environment, consisting HOME, SHELL, USER, and
Cart
LOGNAME.
-l or –login runs a login script to switch to a different username. Executing it requires you to enter the
user’s password.
Compared to the top command, htop has many improvements and additional features, such as mouse
operation and visual indicators.
htop [options]
40. ps command
The process status or ps command produces a snapshot of all running processes in your system. The static
results are taken from the virtual files in the /proc file system.
Executing the ps command without an option or argument will list the running processes in the shell along with:
Press the Tab button to autofill after entering a command with an argument.
Use Ctrl + C to terminate a running command.
When executing multiple commands in a single line, use (;) to separate them. Alternatively, use && to only
allow the next command to run if the previous one is successful.
Expert Tip
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.
Paulius M.
TUTORIALS Web Hosting Monitoring Tech Lead Cart
Conclusion
Linux commands let you perform basic and administrative tasks quickly and effectively from the Terminal. With
it, you’ll have more flexibility over your system and the ability to access features that are not always available
through a graphical user interface.
Learning basic Linux commands is essential to interact with your machine, primarily if you use a Virtual Private
Server (VPS). In most cases, each utility consists of three parts – a command name, a flag or option, and a
parameter or argument.
This article has discussed 40 common commands, such as apt-get to install a package, nano to manipulate a
file, htop to monitor current processes, and ls to view a directory.
We hope this article has helped you learn the basic Linux commands. If you have any questions or suggestions,
please leave them in the comments section below.
One of the most commonly used Linux command is the cat command (short for concatenate).
This command helps you create, view and combine files, as well as redirect the output (the
contents of the whole file).
There are 100+ commands that are shared by Linux and other similar operating systems.
TUTORIALS THE AUTHOR Cart
Artūras B.
Artūras is an experienced Technical Content Writer. Bringing in a lot of knowledge about
WordPress and web hosting to the team, he strives to write pristine content about any IT related
subject. He also loves dogs.
Related tutorials
25 Common Linux Bash Script Bash Variables: Useful What Is Crontab Syntax:
Examples to Get You Started Methods for Working with Understanding Crontab on
Variables in Bash Linux + Helpful Examples
Bash or Bourne-again shell is one of the
most popular shells and command Any programming language comes with Automation is one of the key aspects of
languages for Linux VPS enthusiasts. It its own set of variables. They are an any system, whether a physical or virtual
was first released in 1989 and was... essential part of any system and are private server (VPS). If automation is set
needed to run even the most simple... up correctly, it can save...
By Ignas R.
By Ignas R. By Ignas R.
Vimal
July 30 2019 REPLY
GOOD
Sunny
December 20 2019 REPLY
Adrian
May 24 2020 REPLY
xmax
July 08 2020 REPLY
Man, you're a lifesaver! REALLY helpful to see all useful commands with their switches all in one place.
Tomislav T.
September 06 2020
Sina
August 17 2020 REPLY
TUTORIALS
Thanks art That was Very Very Helpful!
Cart
Hasan Murtaza
August 17 2020 REPLY
Thanks
boe
August 23 2020 REPLY
thanks
happy
August 31 2020 REPLY
Mehmood Qazi
September 20 2020 REPLY
Very helpful
Tomislav T.
November 11 2020
krikor bedrossian
October 17 2020 REPLY
Vakarė
February 02 2021
Happy to help!
Ravichandran VN
November 17 2020 REPLY
Thanks for sharing the valuable information.
TUTORIALS Cart
dhruv
November 23 2020 REPLY
Vakarė
February 09 2021
Happy it helped!
ugesh
December 12 2020 REPLY
kamyogi
December 23 2020 REPLY
Thank you very much Art. Very useful. It has changed a bit my attitude towards Linux.
Nizor
January 11 2021 REPLY
ajay
January 27 2021 REPLY
Benji
February 27 2021 REPLY
Ulita Dso'za
May 08 2021 REPLY
Bethwel Ombewa
July 07 2021 REPLY
Grammy R. Codeislow
July 11 2021 REPLY
Your documentation is incredibly useful. Thanks for taking the time to make this.
r
August 27 2021 REPLY
for a guy starting to learn linux this is very very very helpful.
Vakarė
September 20 2021
G. Williams
August 27 2021 REPLY
Awesome tips, been too long with MS...school was a while ago now Linux PC my gift to me, using a new OS after 40 yrs isn't
easy. I know I can swing it.
Vakarė
September 20 2021
gayle williams
September 15 2021 REPLY
Akash Jaiwal
December 11 2021 REPLY
Great, all commands are useful. Thanks a lot to given description of all commands
the kid
December 20 2021 REPLY
Tamanna yadav
February 06 2022 REPLY
Hassan Raza
March 17 2022 REPLY
rotke
April 06 2022 REPLY
Thanks, there were few commands I didn't know : locate and jobs, I used find and ps. I will tray them out, thanks.
Bill Zaffos
May 20 2022 REPLY
This is very good for me because, I don't live in Linux but only frequent it. I catch myself thinking 'What is that command?'
However, may I suggest some very important commands (in my opinion) that you missed. They are apt-get update & apt-get
upgrade. I was told to always include these when ever I'm in terminal mode. If in the terminal, mount & unmount comes in
handy when deeding information from a USB drive, but then, you would need the blkid, or maybe not.
Vakarė
May 24 2022
Hi there! This is a good point - apt-get update and apt-get upgrade are commonly used before installing any
application. If you're simply editing some files or navigating your server, it's not that important, but surely won't
hurt 😊
Leave a reply
Comment*
Name*
TUTORIALS Cart
Email*
By using this form you agree that your personal data would be processed in accordance with our Privacy Policy.
Submit
We are a web hosting provider on a mission to bring success to everyone who goes online. We do it by constantly improving server technology, providing
professional support, and making the web hosting experience seamless.
And More
eCommerce Hosting
Roadmap
Contact Us
Blog
Student Discount
LEGAL
Privacy Policy
Terms of Service
© 2004-2022 hostinger.com - Premium Web Hosting, Cloud, VPS & Domain Registration Services. Prices are listed without VAT