LINUX CLI COMMANDS
Most Linux distributions have a graphical user interface that allows you to open programs by just clicking on the program's icon in the Apps menu. However, there are situations where you may want to run a program from the Terminal. The Terminal is a powerful tool that allows you to run programs and manage your Linux system using keyboard commands.
Linux has a worldwide market share of 2.68% 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.
According to the 2020 StackOverflow survey, Linux is the most-used operating system by professional developers, with an impressive 55.9% of the market share. It isn’t just a coincidence. Linux is free and open-source, has better security than its competitors, and boasts a powerful command line that makes developers and power users more effective. You also have access to a powerful package manager and a bunch of development tools like DevKinsta.
What Is a Linux Command?
A Linux command is a program or utility that runs on the command line. A command line is an interface that accepts lines of text and processes them into instructions for your computer. Linux commands are executed on Terminal by pressing Enter at the end of the line. You can run commands to perform various tasks, from package installation to user management and file manipulation.
Any graphical user interface (GUI) is just an abstraction of command-line programs. For example, when you close a window by clicking on the “X,” there’s a command running behind that action.
A
flag is a way we can pass options to the command you run. Most Linux
commands have a help page that we can call with the flag
-h
. Most of the time, flags are
optional.
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.
You can
invoke flags using hyphens (-
)
and double hyphens (--
),
while argument execution depends on the order in which you pass them to the
function.
Here’s what a Linux command’s general syntax looks like:
CommandName [option(s)] [parameter(s)]
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:
- CommandName is the rule that you want to perform.
- Option or flag modifies a command’s operation. To invoke it, use hyphens (–) or double hyphens (--).
- Parameter or argument specifies any necessary information for the command.
Keep in mind that all Linux commands are case-sensitive.
check out CLI tutorial.
How To Run A Program From The Command Line On Linux
The 40 Most-Used Linux Commands
The 50 Most Useful Linux Commands To Run In The Terminal
How To Use Linux List Services
HOW TO RUN A PROGRAM FROM THE COMMAND LINE ON LINUX
This wikiHow teaches you how to run a program from the Terminal in Linux.
Method 1
Running a Program From the Terminal
1 Press Ctrl+Alt+T to open the Terminal. You can open the Terminal using the keyboard shortcut on most Linux distributions. The keyboard shortcut is Ctrl + Alt + T. You can also click the Terminal icon in your Apps menu. It generally has an icon that resembles a black screen with a white text cursor.
2 Type the name of the program and press ↵ Enter. Unlike the Windows command-line (CMD), you do not need to type out the full directory path or change directories for most programs in Linux. As long as a program is in your user "$PATH" variable, Linux will search $PATH for the program and launch it automatically.
- For example, if you want to run Firefox from the Terminal, you would simply type firefox and press Enter.
- Type -h or --help after the program name to display the help menu for that program. Many programs have additional command modifiers you can use to launch the program in a specific way. For example, you can launch a website in a web browser by typing the web browser name followed by the web address and press Enter to launch that website in the web browser (i.e. firefox www.wikihow.com.
- If you receive a message that says you don't have permission to run a program or access is denied, type sudo before the program name and press Enter. The "sudo" command allows regular users to run Terminal commands with administrative privileges or root access.
- If you want to run a C or C++ program from the Terminal, you will first need to complie the program before you can launch it from the Terminal.
Method 2
Running a Program Outside the $PATH Variable
1 Press Ctrl+Alt+T to open the Terminal. You can open the Terminal using the keyboard shortcut on most Linux distributions. The keyboard shortcut is Ctrl + Alt + T. You can also click the Terminal icon in your Apps menu. It generally has an icon that resembles a black screen with a white text cursor.
2 Type cd followed by a space and the location the program file is saved to. If the program launch file is saved to a location that is not in your $PATH variable, then you will need to navigate to that location inside the Terminal. You can do so using the "cd" command. For example, if you have folder for Python programs saved in your "Documents" folder, you can navigate to it in the Terminal by typing cd ~/Documents/Python or something similar, and then press Enter.
3 Type chmoda+x [filename] and press ↵ Enter. Replace "filename" with the actual launch file of the program. The "chmoda+x" command tells Linux the file is an executable file.[1]
4 Type "./" followed by the launch filename ane press ↵ Enter. This launches the program. For example, if you have a Python file called "Helloworld.py", you would type ./helloworld.py to launch the file.[2]
Method 3
Adding a Directory to your $PATH Variable
1 Press Ctrl+Alt+T to open the Terminal. If you cannot run a program by simply typing the program's name, you may need to add the directory that the program is installed in to your $PATH variable. You can do this from the Terminal as well. Use the keyboard shortcut to open the Terminal if you haven't already done so.
2 Type the command to export the programs directory to the $PATH variable. To do so, type export PATH=$PATH:[path/to/program] and press Enter. Replace "[path/to/program]" with actual directory tree the program is installed in. This will only last until the end of your current session.
- For example, if you have a program installed in the "bin" directory of your "Home" folder, you would type export PATH=$PATH:$Home/bin and press Enter. This will temporarily add the "$Home/bin" directory to your $PATH variable.
- You can see which directories are currently added to your $PATH variable by typing the command echo $PATH and pressing Enter.
3 Type nano ~/.bashrc and press ↵ Enter. This opens the ".bashrc" file in a text editor that is based in the Terminal. You can use this file to permanently add the directory to your $PATH variable.
4 Add the "export PATH" command to the file. To do so, scroll down to the bottom of the file using the mouse wheel and type export PATH=$PATH:[path/to/program] at the bottom. Replace "[path/to/program]" with the actual directory tree the program is installed in.
5 Press Ctrl+X. This exits the text editor. It will ask if you want to save the file.
6 Press Y and press ↵ Enter. This confirms that you want to save and exit the text editor. You will be returned to the standard command prompt in the Terminal.
7 Type source ~/.bashrc and press ↵ Enter. This loads the updated $PATH variable into your current session.[4]
8 Type the name of the program and press ↵ Enter. With the program's directory now added to your $PATH variable, you should be able to launch the program by simply typing the program name and pressing Enter.
Method 4
Installing and Uninstalling a Program in the Terminal
1 Press Ctrl+Alt+T to open the Terminal. In addition to launching programs from within the Terminal, you can also install and uninstall programs from within the Terminal. Use the keyboard shortcut to open the Terminal if you haven't already done so.
2 Type sudo apt install [app_name] and press ↵ Enter (Debian). Replace "[app_name]" with the actual name of the program you want to install. This command works in Debian-based Linux distributions, such as Ubuntu, and Mint.
3 Type sudo apt remove [app_name] and press ↵ Enter (Debian). Replace "[app_name]" with the name of the app you want to uninstall. This command works in Debian-based Linux distributions, such as Ubuntu, and Mint.
4 Type sudodnf install [app_name] and press ↵ Enter (Red Hat). Replace "[app_name]" with the actual name of the program you want to install. This command works for Red Hat Linux distributions such as RHEL, Fedora, and CentOS.
5Type sudodnf remove [app_name] and press ↵ Enter (Red Hat). Replace "[app_name]" with the name of the app you want to uninstall. This command works for Red Hat Linux distributions such as RHEL, Fedora, and CentOS.[5]
6 Type the name of the program and press ↵ Enter. Once the program is installed, you can launch the program by simply typing the program's name and pressing Enter in the Terminal.
Travis Boylls Run-a-Program-from-the-Command-Line-on-Linux
THE 40 MOST-USED LINUX COMMANDS
1.
ls
Command
ls
is probably the first command every Linux user typed in their terminal. It
allows you to list the contents of the directory you want (the current directory
by default), including files and other nested directories.
ls
It has
many options, so it might be good to get some help by using the
--help
flag. This flag returns all the flags you can use with ls.
For
example, to colorize the output of the
ls
command, you can use the following:
ls--color=auto
The colorized ls command.
Now the
ls
command output is colorized, and you can appreciate the difference between a
directory and a file.
But typing
ls
with the color flag would be inefficient; that’s why we use the
alias
command.
2.
alias
Command
The
alias
command lets you define temporary aliases in your shell session. When creating
an alias, you instruct your shell to replace a word with a series of commands.
For
example, to set
ls
to have color without typing the
--color
flag every time, you would use:
aliasls="ls --color=auto"
As you can
see, the
alias
command takes one key-value pair parameter:
alias
NAME="VALUE"
.
Note that the value must be inside quotes.
If you
want to list all the aliases you have in your shell session, you can run the
alias
command without argument.
alias
The alias
command.
3.
unalias
Command
As the
name suggests, the
unalias
command aims to remove an
alias
from the already defined aliases. To remove the previous
ls
alias, you can use:
unaliasls
4.
pwd
Command
The
pwd
command stands for “print working directory,” and it outputs the absolute path
of the directory you’re in. For example, if your username is “john” and you’re
in your Documents directory, its absolute path would be:
/home/john/Documents
.
To use it,
simply type
pwd
in the terminal:
pwd
# My result: /home/kinsta/Documents/linux-commands
5.
cd
Command
The cd
command is highly popular, along with
ls
.
It refers to “change directory” and, as its
name suggests, switches you to the directory you’re trying to access.
For instance, if you’re inside your Documents directory and you’re trying to access one of its subfolders called Videos, you can enter it by typing:
cd Videos
You can also supply the absolute path of the folder:
cd /home/kinsta/Documents/Videos
There are
some tricks with the
cd
command that can save you a lot of time when playing around with it:
I. Go to the home folder
cd
II. Move a level up
cd..
III. Return to the previous directory
cd -
6.
cp
Command
It’s so easy to copy files and folders directly in the Linux terminal that sometimes it can replace conventional file managers.
To use the
cp
command, just type it along with the source and destination files:
cp file_to_copy.txt new_file.txt
You can also copy entire directories by using the recursive flag:
cp-rdir_to_copy/ new_copy_dir/
Remember
that in Linux, folders end with a forward slash (/
).
7.
rm
Command
Now that you know how to copy files, it’ll be helpful to know how to remove them.
You can
use the
rm
command to remove files and directories. Be careful while using it, though,
because it’s very difficult (yet not impossible) to recover files deleted this
way.
To delete a regular file, you’d type:
rm file_to_copy.txt
If you
want to delete an empty directory, you can use the recursive (-r
) flag:
rm-rdir_to_remove/
On the other hand, to remove a directory with content inside of it, you need to use the force (-f) and recursive flags:
rm-rfdir_with_content_to_remove/
Info
Be careful with this — you can erase a whole day of work by misusing these two flags!
8.
mv
Command
You use
the
mv
command to move (or rename) files and directories through your file system.
To use this command, you’d type its name with the source and destination files:
mvsource_filedestination_folder/
mv command_list.txt commands/
To utilize absolute paths, you’d use:
mv /home/kinsta/BestMoviesOfAllTime ./
…where
./
is the directory you’re currently in.
You also
can use
mv
to rename files while keeping them in the same directory:
mv old_file.txt new_named_file.txt
9.
mkdir
Command
To create
folders in the shell, you use the
mkdir
command. Just specify the new folder’s name, ensure it doesn’t exist, and you’re
ready to go.
For example, to make a directory to keep all of your images, just type:
mkdir images/
To create
subdirectories with a simple command, use the parent (-p
)
flag:
mkdir-p movies/2004/
10.
man
Command
Another
essential Linux command is
man
.
It displays the manual page of any other command (as long as it has one).
To see the
manual page of the
mkdir
command, type:
manmkdir
You could
even refer to the
man
manual page:
manman
The manual page of “man.”
11.
touch
Command
The
touch
command allows you to update the access and modification times of the specified
files.
For example, I have an old file that was last modified on April 12th:
Old date.
To change
its modification date to the current time, we need to use the
-m
flag:
touch-mold_file
Now the date matches today’s date (which at the time of writing was August 8th).
New date
Nonetheless, most of the time, you won’t use
touch
to modify file dates, but rather to create new empty files:
touchnew_file_name
12.
chmod
Command
The
chmod
command lets you change the
mode of a file (permissions) quickly. It has a lot of options available with
it.
The basic permissions a file can have are:
- r (read)
- w (write)
- x (execute)
One of the
most common use cases for
chmod
is to make a file executable by the user. To do this, type
chmod
and the flag
+x
,
followed by the file you want to modify permissions on:
chmod +x script
You use
this to make scripts executable, allowing you to run them directly by using the
./
notation.
13.
./
Command
Maybe the
./
notation isn’t a command itself, but it’s worth mentioning in this list. It lets
your shell run an executable file with any interpreter installed in your system
directly from the terminal. No more double-clicking a file in a graphical file
manager!
For
instance, with this command, you can run a
Python script or a program only available in .run format, like
XAMPP. When running an executable, make sure it has executable (x)
permissions, which you can modify with the
chmod
command.
Here’s a
simple Python script and how we would run it with the
./
notation:
#! /usr/bin/python3
# filename: script
fori
inrange(20):
print(f"This is a cool script {i}")
Here’s how we’d convert the script into an executable and run it:
chmod +x script
./script
14.
exit
Command
The
exit
command does exactly what its name suggests: With it, you can end a shell
session and, in most cases, automatically close
the terminal you’re using:
exit
15.
sudo
Command
This command stands for “superuser do,” and it lets you act as a superuser or root user while you’re running a specific command. It’s how Linux protects itself and prevents users from accidentally modifying the machine’s filesystem or installing inappropriate packages.
Sudo is commonly used to install software or to edit files outside the user’s home directory:
sudoaptinstall gimp
sudocd /root/
It’ll ask you for the administrator’s password before running the command you typed after it.
16.
shutdown
Command
As you may
guess, the
shutdown
command lets you power off your machine. However, it also can be used to halt
and reboot it.
To power off your computer immediately (the default is one minute), type:
shutdown now
You can also schedule to turn off your system in a 24-hour format:
shutdown20:40
To cancel
a previous
shutdown
call, you can use the
-c
flag:
shutdown-c
17.
htop
Command
htop
is an interactive process viewer that lets you manage your machine’s resources
directly from the terminal. In most cases, it isn’t installed d by default, so
make sure to read more about it
on its download page.
The “htop” interface.
18.
unzip
Command
The unzip command allows you to extract the content of a .zip file from the terminal. Once again, this package may not be installed by default, so make sure you install it with your package manager.
Here, we’re unpacking a .zip file full of images:
unzip images.zip
19.
apt
,
yum
,
pacman
commands
No matter which Linux distribution you’re using, it’s likely that you use package managers to install, update, and remove the software you use every day.
You can access these package managers through the command line, and you’d use one or another depending on the distro your machine is running.
The following examples will install GIMP, a free and open source software usually available in most package managers:
1. Debian-based (Ubuntu, Linux Mint)
sudoaptinstall gimp
2. Red Hat-based (Fedora, CentOS)
sudoyum
installgimp
3. Arch-based (Manjaro, Arco Linux)
sudopacman
-Sgimp
20.
echo
Command
The
echo
command displays defined text in the terminal — it’s that simple:
echo"Cool message"
he echo command
Its primary usage is to print environmental variables inside those messages:
echo"Hey $USER"
# Hey kinsta
21.
cat
Command
Cat
,
short for “concatenate,” lets you create, view, and concatenate files directly
from the terminal. It’s mainly used to preview a file without opening a
graphical text editor:
cat long_text_file.txt
The cat command.
22.
ps
Command
With
ps
,
you can take a look at the processes your current shell session is running. It
prints useful information about the programs you’re running, like process ID,
TTY (TeleTYpewriter), time, and command name.
ps
The ps command.
In case
you want something more interactive, you can use
htop
.
23.
kill
Command
It’s
annoying when a program is unresponsive, and you can’t close it by any means.
Fortunately, the
kill
command solves this kind of problem.
Simply
put,
kill
sends a TERM or kill signal to a process that terminates it.
You can kill processes by entering either the PID (processes ID) or the program’s binary name:
kill533494
killfirefox
Be careful
with this command — with
kill
,
you run the risk of accidentally deleting the work you’ve been doing.
24.
ping
Command
ping
is the most popular networking terminal utility used to test network
connectivity.
ping
has a ton of options, but in most cases, you’ll use it to request a domain or
IP address:
ping google.com
ping8.8.8.8
25.
vim
Command
vim
is a free and open source terminal text editor that’s in used since the ’90s. It
lets you edit plain text files using efficient keybindings.
Some people consider it difficult to use — exiting Vim is one of the most-viewed StackOverflow questions — but once you get used to it, it becomes your best ally in the command line.
To fire up Vim, just type:
All Kinsta hosting plans include 24/7 support from our veteran WordPress developers and engineers. Chat with the same team that backs our Fortune 500 clients. Check out our plans!
vim
The vim text editor.
26.
history
Command
If you’re
struggling to remember a command,
history
comes in handy. This command displays an enumerated list with the commands
you’ve used in the past:
history
The history command.
27.
passwd
Command
passwd
allows you to
change the passwords of user accounts. First, it prompts you to enter your
current password, then asks you for a new password and confirmation.
It’s similar to any other change of password you’ve seen elsewhere, but in this case, it’s directly in your terminal:
passwd
The passwd command
Be careful while using it — you don’t want to mess up your user password!
28.
which
Command
The
which
command outputs the full path of shell commands. If it can’t recognize the given
command, it’ll throw an error.
For example, we can use this to check the binary path for Python and the Brave web browser:
which python
# /usr/bin/python
which brave
# /usr/bin/brave
29.
shred
Command
If you
ever wanted a file to be almost impossible to
recover,
shred
can help you with this task. This command overrides the contents of a file
repeatedly, and as a result, the given file becomes extremely difficult to
recover.
Here’s a file with little content in it:
File to shred.
Now, let’s
have
shred
do its thing by typing the following command:
shred file_to_shred.txt
Overwritten content.
If you
want to delete the file right away, you can use the
-u
flag:
shred
-ufile_to_shred.txt
30.
less
Command
less
(opposite of
more) is a program that lets you inspect files backward and forward:
less large_text_file.txt
The less command.
The neat
thing about
less
is that it includes more and
vim
commands in its interface. If you need something more interactive than
cat
,
less
is a good option.
31.
tail
Command
Similar to
cat
,
tail
prints the contents of a file with
one major caveat: It only outputs the last lines. By default, it prints the last
10 lines, but you can modify that number with
-n
.
For example, to print the last lines of a large text file, you’d use:
tail long.txt
The tail command.
To view only the last four lines:
tail-n4 long.txt
tail four lines.
32.
head
Command
This one
is complementary to the
tail
command.
head
outputs the first 10 lines of a text file, but you can set any number of lines
you want to display with the
-n
flag:
head long.txt
head-n5 long.txt
The head command.
33.
grep
Command
Grep is one of the most powerful utilities for working with text files. It searches for lines that match a regular expression and print them:
grep"linux" long.txt
The grep command.
You can
count the number of times the pattern repeats by using the
-c
flag:
grep-c"linux" long.txt
# 2
34.
whoami
Command
The
whoami
command (short for “who am i”) displays the
username currently in use:
whoami
# kinsta
You would
get the same result by using
echo
and the environmental variable $USER:
echo$USER
# kinsta
35.
whatis
Command
whatis
prints a single-line description of any other command, making it a helpful
reference:
whatis python
# python (1) - an interpreted, interactive, object-oriented programming language
whatiswhatis
# whatis (1) - display one-line manual page descriptions
36.
wc
Command
Wc stands for “word count,” and as the name suggests, it returns the number of words in a text file:
wc long.txt
# 37 207 1000 long.txt
Let’s breakdown the output of this command:
- 37 lines
- 207 words
- 1000 byte-size
- The name of the file (long.txt)
If you
only need the number of words, use the
-w
flag:
wc-w long.txt
207 long.txt
37.
uname
Command
uname
(short
for “Unix name”) prints the operative system information, which comes in handy
when you know your current Linux version.
Most of
the time, you’ll be using the
-a
(–all) flag, since the default output isn’t that useful:
uname
# Linux
uname-a
# Linux kinstamanjaro 5.4.138-1-MANJARO #1 SMP PREEMPT Thu Aug 5 12:15:21 UTC 2021 x86_64 GNU/Linux
38.
neofetch
Command
Neofetch is a CLI (command-line interface) tool that displays information about your system — like kernel version, shell, and hardware — next to an ASCII logo of your Linux distro:
neofetch
The neofetch command.
In most machines, this command isn’t available by default, so make sure to install it with your package manager first.
39.
find
Command
The
find
command searches for
files in a directory hierarchy based on a regex expression. To use it,
follow the syntax below:
find[flags
][path
]-name[expression
]
To search for a file named long.txt in the current directory, enter this:
find ./
-name"long.txt"# ./long.txt
To search for files that end with a .py (Python) extension, you can use the following command:
find./
-typef
-name"*.py"./get_keys.py ./github_automation.py ./binarysearch.py
40.
wget
Command
wget
(World Wide Web get) is a utility to retrieve content from the internet. It has
one of the largest collections of flags out there.
Here’s how you would download a Python file from a GitHub repo:
wget https://raw.githubusercontent.com/DaniDiazTech/Object-Oriented-Programming-in-Python/main/object_oriented_programming/cookies.py
Daniel Diaz, https://kinsta.com/blog/linux-commands/
THE 50 MOST USEFUL LINUX COMMANDS TO RUN IN THE TERMINAL
Linux Commands for Navigating the Filesystem
As with every modern operating system, the Linux filesystem sits at the core of its fundamental design and paves the way for you to visualize and manipulate your system hierarchy. Learning to navigate the filesystem creatively will take your Linux skills to the next level.
1. pwd
pwd stands for Print Work directory – it shows the directory you’re currently in. This is one of the handiest Linux terminal commands that aims to make new user’s life peaceful by ensuring they don’t get lost in that seemingly cryptic terminal window.
2. ls
The ls command is probably one of the most widely used commands in the Unix world. It presents to you the contents of a particular directory – both files and directories. You will use this command alongside pwd to navigate your ways inside the mighty Unix filesystem.
3. cd
Short for Change Directory, the cd command is behind your movement from one directory to another. It’s one of the few Linux commands that you’re bound to use throughout your stint with the Linux system. This command makes life in front of the terminal less scary for beginners while providing a standard method to browse the entire filesystem of your device.
4. mkdir
Want to create a new folder through the terminal? The mkdir command is created for just this specific purpose. It lets you create folders anywhere you like in your Linux system – given you have got the necessary permission, of course!
5. rmdir
The arch rival of the mkdir command, the rmdir command allows you to delete specific folders from your system without any hassles. Although many utilize the rm command for this purpose, screwing up parameters or even a single character with rm can do things you wouldn’t even dream. So, stick with rmdir for now.
6. lsblk
Often you will find the need to list the available block devices of your Linux system. The lsblk is one of the most used Linux commands for this purpose. This handy terminal command will present you with a tree structure of your block devices and is used heavily by professional users.
7. mount
Contrary to Windows, whenever you plug in an SD card or a USB, chances are your distro won’t show them directly at the start. You need to mount it with your existing filesystem using the mount command. This Linux command is one of the most powerful terminal commands out there.
8. df
The df command is one of the most empowering Linux terminal commands that display essential information about the disk space on your filesystem. It is used widely by system administrators to monitor and analyze real-time server or network-oriented systems.
Linux Commands for Manipulating the System
System commands are essential to gain information about your Linux system. A significant number of powerful Linux commands are at your disposal for this task. Below we’re presenting a few to get you started.
9. uname
The uname command is an elementary Linux command for obtaining system information like name, version, and other system-specific details. You can quickly check your OS and kernel version with this command and can know for sure the instruction length of your machine.
10. ps
This is among other straightforward terminal commands that will allow you to visualize what processes are currently run by your machine. It’s a very elegant yet flexible mean to analyze system resources and will enable you to manipulate system processes natively through the terminal. This command is considered as one of the basic and best Linux monitoring tools available for Linux nerds.
11. kill
The kill command is a powerful way to stop processes that are stuck due to resource constraints. As you grow your Linux system skills, you will come to know the essence and importance of this command. Often presented in lists of funny Linux commands, the kill command is as mighty as its name.
12. service
The service command is the de-facto command to invoke system-wide services from the terminal. A powerful Linux terminal command for manipulating the system; you can leverage this command for running any System V init script directly from the terminal window.
13. batch
If you are looking for a neat tool that will run system services in a pre-defined schedule, the batch command is here for your redemption. Another powerful Linux command for writing automation shell scripts; this flexible little command can aid to your Linux productivity significantly.
14. shutdown
Feeling a bit lazy and don’t want to click a few GUI elements at the end of a long night? The shutdown command is here for empowering your Linux terminal commands skills to a whole new level. Just don’t type it now while reading this post!
Linux Commands for Taking Care of Your Files
Files sit at the heart of your Linux system. Almost everything you see on your system is some kind of a file and can be manipulated accordingly. Mastering the ways of managing your files is essential if you want to be a Linux guru.
15. touch
The touch command is an essential Linux command for creating a valid empty file. You can create files on the go in your terminal and fill them up later or in real-time – based on your requirements. It’s also the go-to command for changing the timestamps.
16. cat
Designed initially for concatenating multiple files, the cat command is used for numerous other purposes since. This is among other Linux commands you will use to create new files, view file contents in the terminal, and redirect output to another command-line tool or file.
17. head
The head command allows you to view the beginning of a file or piped data directly from the terminal. It’s one of the most widely used Linux commands by users who works heavily with text processing. Use this command whenever you are going through a lot of files in the terminal to increase your productivity.
18. tail
A compliment to the previous command, chances are you will use the tail command much more than the header commands. A basic Linux terminal command, tail, mixed with cat and echo can do things you wouldn’t even imagine.
19. cp
The cp command is just a short way of telling your machine to copy a file or directory from one folder to another. It is among other de-facto Linux commands you can’t live without. You can copy multiple files to a directory right from your terminal with this neat command.
20. mv
Short for a move, it’s a supplement to the cut operation you perform in the GUI. Just like cp, you can use the mv command to move either single or multiple files from one location to another. You can force this Linux command to transfer large files with the -f parameter.
21. comm
One of the original Unix commands that found its way to the Linux world, you can use comm to compare two files for common and distinct lines. This is an essential tool for many that need to process large amounts of files on the terminal.
22. less
Another most used Linux command, the less command, is widely popular due to the convenience it brings when viewing the contents of a file. Contrary to cat, the less command allows users to navigate within a file in both directions while not interrupting the terminal session.
23. ln
The ln command is one of the handiest Linux commands for creating symbolic links to some specific file. You can use this tiny yet flexible command to produce multiple instances of a symbolic link to a particular file or directory on your disk space.
24. cmp
If you want to compare two files and print the result to the standard output stream, the cmp command will let you do exactly so. This, alongside the comm command, is one of the most used Linux commands by users that process large volumes of text files on a regular basis.
25. dd
This is one of the most used Linux commands by veteran users to copy and convert files from one type to another. The exciting thing about this little yet powerful command is that you will often use it among other terminal commands when creating bootable live USB sticks.
26. alias
It is one of the most used Linux commands by system admins as it lets them replace a word by another string in files directly from the terminal. Among other functions, this is one of the best terminal commands through which you can customize the shell and manipulate the environment variables.
Funny Linux Commands to Explore When Bored
A lot of funny Linux commands are available to make your time in front of the terminal exciting. These terminal commands are funny in a way that they do things no one would imagine them to do. We highly encourage you to play with such funny Linux commands as they’ll redeem your boredom while providing deep insights into the Unix philosophy.
27. cal
Did you know Unix provides a handy little calendar tool right into the terminal? The cal command is one of those funny Linux commands that shows you the calendar in an ASCII text format. Type this command with parameters like month and year to get specified information right into the terminal.
28. fortune
This is one of my most favorite funny Linux commands. Just type it in the terminal and see for yourself! It shows out of the blue poignant, inspirational, or silly phrases that will definitely make you laugh out loud.
29. history
Want to check the history of your terminal sessions? The history command lets you do precisely this. When typed without any parameters, this will print out the bash history of your terminal session right in the tiny window. It’s not only among the most useful funny Linux commands you will use in the terminal but also provides a great insight into your terminal usage.
30. yes
Okay, you want some real funny Linux commands to try right now? Just open up a terminal type in yes, then some texts of your choosing and press enter. We’re pretty sure it’s among those terminal commands you will never forget ever since.
31. banner
Ever saw some great ASCII banners used by old school Unix legends and fall in love right away? The banner command is one of those funny Linux commands that will empower you to create your own personalized such banners. Just enter this command mixed with some texts in the terminal to get a feel.
32. rev
This is another funny terminal command for veteran Linux users. The rev command will take your input text and write them to the standard output, reversing each character! It’s one of those terminal commands you can use to make a cryptic yet subtle impression on your friends.
Most Used Linux Commands for Network Administrators
It is the power and flexibility Linux provides for networking that makes it the go-to solution for sysadmins worldwide. Linux is behind most of the computer networks that we’re familiar with today. As this guide is meant for beginners, we’re outlining only the most elementary terminal commands for networking.
33. wget
This is one of the best Linux commands network admins leverage to download files from the web right from the terminal. This is among those handy little terminal commands that can be used in scripts or cronjobs and provides users the ability to use the HTTP, HTTPS, and FTP internet protocol.
34. iptables
The iptables command invokes a terminal utility that lets system admins control the incoming and outgoing internet traffic on a particular host machine. It is among the most used Linux commands sysadmins use on a regular basis to define authentic traffics and for blacklisting suspicious or untrusted network requests.
35. traceroute
This command is widely used by security professionals who leverage this command with other terminal commands for determining the route a network packet takes on its way from one machine to another. This is a compelling network command by using which you can safeguard your computer from a number of harmful intruders.
36. cURL
cURL is a very powerful network tool that makes transferring files over a network a child’s play for even new Linux system users. This is one of those Linux commands designed to work without user interaction and is typically employed in network-related shell scripts.
Linux Commands for Search and Regular Expression
Linux provides a handful of flexible terminal commands for searching the machine effectively. You can combine such Linux terminal commands with powerful regular expression commands to gain information regarding a particular file or sequence in files pretty quickly.
37. find
The find command is one of the most used Linux commands to search for files from the terminal. This compelling yet flexible terminal command allows users to search for files based on certain criteria such as file permissions, ownership, modification date, size, etc.
38. which
The which command is pretty useful if all you are trying to search are executable files. This handy little terminal command takes specific parameters and searches for binary files in the $PATH system environment variable based on them very effectively.
39. locate
The locate command is one of those Linux commands that are used for finding the location of a specific file. It is one of the most straightforward terminal commands that you can leverage when not sure about the location of a particular file on your Linux machine.
40. grep
grep command is among the most powerful regular expression terminal commands you can use when searching for patterns inside large volumes of text files. It will take the pattern you’re looking for as input and search the specified files for that particular pattern.
41. sed
This is one of the most widely used Linux commands to manipulate each line of a file or stream by replacing specified parts. It is used heavily by users that deal with large volumes of text data and need to change them on the go.
Linux Commands That Deal With I/O And Ownership
Linux offers a robust set of terminal commands to set and manipulate the I/O streams and file or directory ownership. The Linux commands listed below will outline some of the most basic Linux terminal commands for such purposes.
42. clear
The clear command is handy to clear out your existing terminal screen. Often you will find the need to wipe out the terminal screen after some earlier Linux commands leave your terminal screen with a garbled output.
43. echo
The echo command is a very powerful command-line utility that lets you output a specific text to the terminal console. Type in echo followed by some texts within parentheses to find out for yourself. What’s more interesting for this command is that you can pipe the output to other terminal commands.
44. sort
The sort command is quite compelling at the things it does. Whenever you find the need to sort out a file in an alphabetical or reverse manner, utilize this command.
45. sudo
The sudo command is the holy grail of Linux commands. It lets non-privileged users access and modify files that require low-level permissions. Often you will use this command to access root from your regular user account.
46. chmod
The chmod command is among the most powerful Linux commands you will use to change or modify the access permissions of system files or objects. This command can take a very diverse set of parameters from users and, based on those changes, the file permission.
47. chown
The chown command is very much similar to the chmod command. But instead of changing access permissions, it enables users to change the ownership of a file or directory. Both the chmod and chown terminal commands require root privileges to run.
Miscellaneous Linux Commands For Everyday Use
The below terminal commands will help you increase productivity and decrease your workload. Use these commands whenever you see them dim fit for the context.
48. man
The man command stands for manual and is one of the most useful Linux commands you can get your hands on. This command, followed by the name of another command lists the manual or documentation page of that command. You will need to use this command often when determining how to use specific Terminal commands.
49. tar
The tar command is used for archiving files and extracting them. It is a very popular command for compressing files and can tackle such tasks very efficiently.
50. whatis
The whatis command traverses a set of databases with short descriptions provided by the user and prints out system commands that match them.
Mehedi Hasan Best-linux-commands-to-run-in-the-terminal/
40 ESSENTIAL LINUX COMMANDS
-
The 40 Most Commonly Used Linux Commands
- 1. sudo command
- 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
- 11. touch command
- 12. locate command
- 13. find command
- 14. grep command
- 15. df command
- 16. du command
- 17. head command
- 18. tail command
- 19. diff command
- 20. tar command
- 21. chmod command
- 22. chown command
- 23. jobs command
- 24. kill command
- 25. ping command
- 26. wget command
- 27. uname command
- 28. top command
- 29. history command
- 30. man command
- 31. echo command
- 32. zip, unzip commands
- 33. hostname command
- 34. useradd, userdel commands
- 35. apt-get command
- 36. nano, vi, jed commands
- 37. alias, unalias commands
- 38. su command
- 39. htop command
- 40. ps command
1. sudo command
Short for superuser do,sudois 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.
Here’s the general syntax:
sudo
You can also add an option, such as:
- -k or –reset-timestamp invalidates the timestamp file.
- -g or –group=group runs commands as a specified group name or ID.
- -h or –host=host runs commands on the host.
2. pwd command
Use the pwdcommand 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.
The pwdcommand uses the following syntax:
pwd [option]
It has two acceptable options:
- -L or –logical prints environment variable content, including symbolic links.
- -P or –physical prints the actual path of the current directory.
3. cd command
To navigate through the Linux files and directories, use the cd command. Depending on your current working directory, it requires either the full path or the directory name.
Running this command without an option will take you to the home folder. Keep in mind that only users with sudoprivileges can execute it.
Let’s say you’re in /home/username/Documents and want to go to Photos, a subdirectory of Documents. To do so, enter the following command:
cdPhotos.
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
Here are some shortcuts to help you navigate:
- cd ~[username] goes to another user’s home directory.
- cd .. moves one directory up.
- cd- moves to your previous directory.
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:
- ls -R lists all the files in the subdirectories.
- ls -a shows hidden files in addition to the visible ones.
- ls -lh shows the file sizes in easily readable formats, such as MB, GB, and TB.
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.
Here are other ways to use the cat command:
- cat > filename.txt creates a new file.
- cat filename1.txt filename2.txt > filename3.txt merges filename1.txt and filename2.txt and stores the output in filename3.txt.
- tac filename.txt displays content in reverse order.
6. cp command
Use the cpcommand 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 cpfollowed 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:
cp filename1.txt filename2.txt filename3.txt /home/username/Documents
To copy the content of a file to a new file in the same directory, enter cpfollowed 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
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.
You can also use the mv command to rename a file:
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.
Here’s the basic syntax:
mkdir [option] directory_name
For example, you want to create a directory called Music:
mkdir Music
To make a new directory called Songs inside Music, use this command:
mkdir Music/Songs
The mkdircommand accepts many options, such as:
- -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.
- -v prints a message for each created directory.
9. rmdir command
To permanently delete an empty directory, use the rmdir command. Remember that the user running this command should have sudoprivileges 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.
Here’s the general syntax:
rm filename
To remove multiple files, enter the following command:
rm filename1 filename2 filename3
Here are some acceptable options you can add:
- -i prompts system confirmation before deleting a file.
- -f allows the system to remove without a confirmation.
- -r deletes files and directories recursively.
11. touch command
The touch command allows you to create an empty file or generate and modify a timestamp in the Linux command line.
For example, enter the following command to create an HTML file named Web in the Documents directory:
touch /home/username/Documents/Web.html
12. locate command
The locate command can find a file in the database system.
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.
13. find command
Use the find command to search for files within a specific directory and perform subsequent operations. Here’s the general syntax:
find [option] [path] [expression]
For example, you want to look for a file called notes.txt within the home directory and its subfolders:
find /home -name notes.txt
Here are other variations when using find:
- find -name filename.txt to find files in the current directory.
- find ./ -type d -name directorynameto look for directories.
14. grep command
Another basic Linux command on the list is grepor global regular expression print. It lets you find a word by searching through all the texts in a specific file.
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:
grep blue notepad.txt
The command’s output will display lines that contain blue.
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
These are some acceptable options to use:
- df -m displays information on the file system usage in MBs.
- df -k displays file system usage in KBs.
- df -T shows the file system type in a new column.
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.
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:
- -s offers the total size of a specified folder.
- -m provides folder and file information in MB
- k displays information in KB.
- -h informs the last modification date of the displayed folders and files.
17. head command
The head command allows you to view the first ten lines of a text. Adding an option lets you change the number of lines shown. The head commandis also used to output piped data to the CLI.
Here’s the general syntax:
head [option] [file]
For instance, you want to view the first ten lines of note.txt, located in the current directory:
head note.txt
Below are some options you can add:
- -n or –linesprints the first customized number of lines. For example, enter head -n 5 filename.txt to show the first five lines of filename.txt.
- -c or –bytesprints the first customized number of bytes of each file.
- -q or –quiet will not print headers specifying the file name.
18. tail command
The tail command displays the last ten lines of a file. It allows users to check whether a file has new data or to read error messages.
Here’s the general format:
tail [option] [file]
For example, you want to show the last ten lines of the colors.txt file:
tail -n colors.txt
19. diff command
Short for difference, the diff command compares two contents of a file line by line. After analyzing them, it will display the parts that do not match.
Programmers often use the diff command to alter a program instead of rewriting the entire source code.
Here’s the general format:
diff [option] file1 file2
For example, you want to compare two text files – note.txt and note_update.txt:
diff note.txt note_update.txt
Here are some acceptable options to add:
- -c displays the difference between two files in a context form.
- -u displays the output without redundant information.
- -i makes the diff command case insensitive.
20. tar command
The tar command archives multiple files into a TAR file– a common Linux format similar to ZIP, with optional compression.
Here’s the basic syntax:
tar [options] [archive_file] [file or directory to be archived]
For instance, you want to create a new TAR archive named newarchive.tar in the /home/user/Documents directory:
tar -cvf newarchive.tar /home/user/Documents
The tar command accepts many options, such as:
- -x extracts a file.
- -t lists the content of a file.
- -u archives and adds to an existing archive file.
Check out the more practical examples to know more about the other functions.
21. chmod command
chmod is a common command that modifies a file or directory’s read, write, and execute permissions. In Linux, each file is associated with three user classes – owner, group member, and others.
Here’s the basic syntax:
chmod [option] [permission] [file_name]
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:
chmod 777 note.txt
This command supports many options, including:
- -c or –changesdisplays information when a change is made.
- -f or –silent suppresses the error messages.
- -v or –verbose displays a diagnostic for each processed file.
22. chown command
The chown command lets you change the ownership of a file, directory, or symbolic link to a specified username.
Here’s the basic format:
chown [option] owner[:group] file(s)
For example, you want to make linuxuser2 the owner of filename.txt:
chown linuxuser2 filename.txt
23. jobs command
A job is a process that the shell starts. The jobs command will display all the running processes along with their statuses. Remember that this command is only available in csh, bash, tcsh, and kshshells.
This is the basic syntax:
jobs [options] jobID
To check the status of jobs in the current shell, simply enter jobs to the CLI.
Here are some options you can use:
- -l lists process IDs along with their information.
- -n lists jobs whose statuses have changed since the last notification.
- -p lists process IDs only.
24. kill command
Use the kill command to terminate an unresponsive program manually. It will signal misbehaving applications and instruct them to close their processes.
To kill a program, you must know its process identification number (PID). If you don’t know the PID, run the following command:
psux
After knowing what signal to use and the program’s PID, enter the following syntax:
kill [signal_option] pid
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:
kill SIGKILL 63773
25. ping command
The ping command is one of the most used basic Linux commands for checking whether a network or a server is reachable. In addition, it is used to troubleshoot various connectivity issues.
Here’s the general format:
ping [option] [hostname_or_IP_address]
For example, you want to know whether you can connect to Google and measure its response time:
ping google.com
26. wget command
The Linux command line lets you download files from the internet using the wget command. It works in the background without hindering other running processes.
The wgetcommand 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.
To use it, enter the following command:
wget [option] [url]
For example, enter the following command to download the latest version of WordPress:
wget https://wordpress.org/latest.zip
27. uname command
The uname or unix name command will print detailed information about your Linux system and hardware. This includes the machine name, operating system, and kernel. To run this command, simply enter unameinto your CLI.
Here’s the basic syntax:
uname [option]
These are the acceptable options to use:
- -a prints all the system information.
- -s prints the kernel name.
- -n prints the system’s node hostname.
28. top command
The top command in Linux Terminal will display all the running processes and a dynamic real-time view of the current system. It sums up the resource utilization, from CPU to memory usage.
The top command can also help you identify and terminate a process that may use too many system resources.
To run the command, simply enter top into the CLI.
29. history command
With history, the system will list up to 500 previously executed commands, allowing you to reuse them without re-entering. Keep in mind that only users with sudoprivileges can execute this command. How this utility runs also depends on which Linux shell you use.
To run it, enter the command below:
history [option]
This command supports many options, such as:
- -c clears the complete history list.
- -doffset deletes the history entry at the OFFSET position.
- -a appends history lines.
30. man command
The man command provides a user manual of any commands or utilities you can run in Terminal, including the name, description, and options.
It consists of nine sections:
- Executable programs or shell commands
- System calls
- Library calls
- Games
- Special files
- File formats and conventions
- System administration commands
- Kernel routines
- Miscellaneous
To display the complete manual, enter:
man [command_name]
For example, you want to access the manual for the ls command:
man ls
Enter this command if you want to specify the displayed section:
man [option] [section_number] [command_name]
For instance, you want to see section 2 of the ls command manual:
man 2 ls
31. echo command
The echo command is a built-in utility that displays a line of text or string using the standard output. Here’s the basic syntax:
echo [option] [string]
For example, you can display the text Hostinger Tutorials by entering:
echo “Hostinger Tutorials”
This command supports many options, such as:
- -n displays the output without the trailing newline.
- -e enables the interpretation of the following backslash escapes:
- \a plays sound alert.
- \b removes spaces in between a text.
- \c produces no further output.
- -E displays the default option and disables the interpretation of backslash escapes.
32. zip, unzip commands
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.
To use it, enter the following syntax:
zip [options] zipfile file1 file2….
For example, you have a file named note.txt that you want to compress into archive.zip in the current directory:
zip archive.zip note.txt
On the other hand, the unzip command extracts the zipped files from an archive. Here’s the general format:
unzip [option] file_name.zip
So, to unzip a file called archive.zip in the current directory, enter:
unzip archive.zip
33. hostname command
Run the hostname command to know the system’s hostname. You can execute it with or without an option. Here’s the general syntax:
hostname [option]
There are many optional flags to use, including:
- -a or –alias displays the hostname’s alias.
- -A or –all-fqdns displays the machine’s Fully Qualified Domain Name (FQDN).
- -i or –ip-address displays the machine’s IP address.
For example, enter the following command to know your computer’s IP address:
hostname -i
34. useradd, userdel commands
Linux is a multi-user system, meaning more than one person can use it simultaneously. useraddis used to create a new account, while the passwdcommand allows you to add a password. Only those with root privileges or sudocan run the useradd command.
When you use the useraddcommand, it performs some major changes:
- Edits the /etc/passwd, /etc/shadow, /etc/group, and /etc/gshadow files for the newly created accounts.
- Creates and populates a home directory for the user.
- Sets file permissions and ownerships to the home directory.
Here’s the basic syntax:
useradd [option] username
To set the password:
passwdthe_password_combination
For example, to add a new person named John, enter the following command simultaneously:
useradd John
passwd 123456789
To delete a user account, use the userdel command:
userdel username
35. apt-get command
apt-get is a command line tool for handling Advanced Package Tool (APT) libraries in Linux. It lets you retrieve information and bundles from authenticated sources to manage, update, remove, and install software and its dependencies.
Running the apt-get command requires you to use sudo or root privileges.
Here’s the main syntax:
apt-get [options]
These are the most common commands you can add to apt-get:
- update synchronizes the package files from their sources.
- upgrade installs the latest version of all installed packages.
- check updates the package cache and checks broken dependencies.
36. nano, vi, jed commands
Linux allows users to edit and manage files via a text editor, such as nano, vi, or jed. nanoand vi come with the operating system, while jedhas to be installed.
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.
To use vi on a file, enter:
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.
To open the program, simply enter jedto the command line.
37. alias, unalias commands
alias allows you to create a shortcut with the same functionality as a command, file name, or text. When executed, it instructs the shell to replace one string with another.
To use the alias command, enter this syntax:
alias Name=String
For example, you want to make k the alias for the kill command:
alias k=’kill’
On the other hand, the unaliascommand deletes an existing alias.
Here’s what the general syntax looks like:
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.
Here’s the general syntax of the command:
su [options] [username [argument]]
When executed without any option or argument, the sucommand runs through root privileges. It will prompt you to authenticate and use the sudoprivileges temporarily.
Here are some acceptable options to use:
- -p or –preserve-environment keeps the same shell environment, consisting HOME, SHELL, USER, and LOGNAME.
- -s or –shell lets you specify a different shell environment to run.
- -l or –login runs a login script to switch to a different username. Executing it requires you to enter the user’s password.
39. htop command
The htopcommand is an interactive program that monitors system resources and server processes in real time. It is available on most Linux distributions, and you can install it using the default package manager.
Compared to the top command, htophas many improvements and additional features, such as mouse operation and visual indicators.
To use it, run the following command:
htop [options]
You can also add options, such as:
- -d or –delay shows the delay between updates in tenths of seconds.
- -C or –no-color enables the monochrome mode.
- -h or –help displays the help message and exit.
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 pscommand without an option or argument will list the running processes in the shell along with:
- The unique process ID (PID)
- The type of the terminal (TTY)
- The running time (TIME)
- The command that launches the process (CMD)
Here are some acceptable options you can use:
- -T displays all processes associated with the current shell session.
- -u username lists processes associated with a specific user.
- -A or -e shows all the running processes.
Artūras B. Hostinger Linux-commands
HOW TO USE LINUX LIST SERVICES
Linux Services
A service is a program that runs in the background outside the interactive control of system users as they lack an interface. This in order to provide even more security, because some of these services are crucial for the operation of the operating system.
On the other hand, in systems like Unix or Linux, the services are also known as daemons. Sometimes the name of these services or daemons ends with the letter d. For example, sshd is the name of the service that handles SSH.
So, let us start to work and list services in Linux.
How to List Services in Linux
Let’s look at a potential scenario. While running your Linux system, you can no longer access localhost. Chances are that the HTTP service was disabled, and causing the problem.
To troubleshoot issues like this one and many others, it’s good to know how to list all services in Linux.
Fortunately, CentOS and Ubuntu – two of the most popular operating systems in their areas – share systemd. That means that the commands we are going to present are compatible with both systems.
First, we have to connect to our server using SSH. If you’re having trouble, check out PuTTY tutorial.
Once inside, we need to be the root user to list service in Linux.
su
Now we can list all services in Linux. To do it, run the command:
sudosystemctl list-unit-files --type service --all
When the command is run, we will see all the services that are on the system. However, we will also see that some have a defined status. Let’s learn what all these mean.
- Enabled services are currently running. They usually have no problems.
- Disabled services are not active but can be activated at any time without a problem.
- Masked services won’t run unless we take that property away from them.
- Static services will only be used in case another service or unit needs it.
- Finally, there are services generated through a SysV or LSB initscript with systemd generator.
In case we want to know only the services that are active, we have to use a command together with grep, like so:
sudosystemctl | grep running
Managing Linux Services
Now it is time to learn how to manage a specific service. Note that each service represents software that works differently. In this tutorial, we will only show how to start, check the status of and stop services – the basic controls
To start a service on Linux, we need to run the following command:
sudosystemctl start [service_name]
If the service is correctly configured, it will start. Now, if we want to stop it, we will use the following command:
sudosystemctl stop [service_name]
Meanwhile, to check the status of a service we can use:
sudosystemctl status [service_name]
It is also possible to have a service run while the operating system is being loaded:
sudosystemctl enable [service_name]
Or remove it from the initial load:
sudosystemctl disable [service_name]
Finally, it is possible to verify which port is being used by a service. For this, we will use netstat.
To install it on Ubuntu, we just run:
sudo apt install netstat-nat
If we are using CentOS 7:
yum install net-tools
Then, we run the following command:
sudonetstat -plnt
The output will give us all the required network information.
Edward S. Hostinger Manage-and-list-services-in-linux/
HOW TO RUN MULTIPLE COMMANDS IN LINUX AT ONCE
On Linux, there are three ways to run multiple commands in a terminal:
- The Semicolon (;) operator
- The Logical OR (||) operator
- The Logical AND (&&) operator
All these methods require an operator. While any of these operators can run two or more shell commands at once, knowing which operator to use and when can help you in crafting effective commands. The following sections discuss both the purpose and the syntax to use these operators properly.
1. Using the Semicolon (;) Operator
Segmenting a chain of commands with the semicolon is the most common practice when you want to run multiple commands in a terminal. Part of the reason for this is the way the operator performs: it runs all the commands in the sequence irrespective of whether the previous command ran successfully or failed.
For instance, if there are two commands: command A and command B, using the semicolon operator in between them ensures that both the first and the second command get executed sequentially regardless of the output of the first command.
commandA ;
command B
So if you're in a situation where there’s a need to run two or more unrelated terminals commands such that the output status of the first command doesn't affect the execution of the latter, the semicolon operator is the way to go.
Example use case: To display the name of the current user and the system hostname:
whoami ; hostname
Bear in mind, though, that the shell executes these commands in the order in which you mention them. Here's what the output would look like:
2. Using the OR (||) Operator
The very definition of the word "or" is a giveaway here: when you run two commands using the OR operator, you tell the shell to execute only one command between the two.
Consider a scenario where you've used the OR operator with two commands: command A and command B. This is how the conjoined command would look like with the OR operator:
command A ||
command B
Here, command B will only execute if command A fails, i.e. when command A returns an error. Likewise, if command A runs successfully, command B won't execute.
Talking about its use case, you can use the OR operator when you need to run two related commands together such that the shell executes the next command only when the previous one fails.
Example use case: Let's assume you want to create a new file, say Document.txt, but before you do that, you want to make sure that a file with the same name doesn't already exist in the current directory. In such situations, you can run your commands in the following sequence:
find . -name Document.txt || touch Document.txt
Here, the find command will look up the present working directory for the Documents.txt file. If it finds the file, the command progression will stop—and the second command won't run.
On the other hand, if it doesn't find a matching file, the command to the right will execute, and a new file with the name Document.txt will get created in your present working directory.
3. Using the AND (&&) Operator
As you'd have probably guessed, the AND operator executes the next command in a sequence only when its previous command runs successfully.
To understand this better, consider a scenario where you wish to run two related commands such that you want the second command to run only if the first one returns a valid output. In this case, we can bind the commands together using the AND operator, referred to as &&, to get our desired result.
Example use case: One of the most common use-cases of the AND operator in Linux is to create a new directory and get into it right away. That way, you won't have to run the two commands individually to carry out the operation.
For the purpose of this guide, let's assume you want to create a new directory called Documents and immediately change your present working directory to it.
mkdir Documents &&
cd Documents
Here, the mkdir command will create a new directory named Documents in your present working directory. If it succeeds, it'll allow the cd command to execute.
Combining Multiple Operators to Meet Your Execution Criteria
Besides using operators individually in your commands, you can also group multiple operators together to fulfill your execution criteria. This comes in handy when you want to execute commands based on multiple conditions.
Consider a scenario where you want to execute two commands (command B and command C) only when command A fails. To do this, you'll need to use operators as shown in the notation below:
command A ||
command B &&
command C
Example use case: Let's say you want to determine whether a folder (named Document) exists in your current working directory and create it if it isn't there. In this case, instead of running separate commands to find the directory and create a new one, you can use the OR and AND operators together to perform the entire operation efficiently.
Here's how that would look like:
find . -name Document ||
echo "Directory not found" &&mkdir Document
In this command, find asks the shell to search for a folder named Document in the current working directory. If the directory isn't present, the terminal transfers the flow to the echo and mkdir commands, which print the specified string and create a new folder respectively.
Efficiently Running Terminal Commands in Linux
As you just saw, using operators in your commands can simplify a lot of command-line operations.
If you're someone who likes to handle different system operations on their computer through the terminal, knowing how to use these operators can be very helpful and will definitely assist you in running Linux commands more efficiently.
Similarly, if you’re just getting started—or less familiar—with Linux, learning different terminal commands is another step towards mastering the command-line interface.
YashWate Run-multiple-linux-commands-at-once/
BONUS TIPS AND TRICKS
Here are some tips and tricks you can use to manage the Linux system:
- Enter the clear command to clean the Terminal screen.
- Press the Tab button to autofill after entering a command with an argument.
- Use Ctrl + C to terminate a running command.
- Press Ctrl + Z to pause a working command.
- Use Ctrl + S to freeze your Terminal temporarily.
- Press Ctrl + Q to undo the Terminal freeze.
- Use Ctrl + A to move to the beginning of the line.
- Press Ctrl + E to bring you to the end of the line.
- 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.
LINUX COMMANDS CHEAT SHEET
Command |
Usage |
|
Lists the content of a directory |
|
Define or display aliases |
|
Remove
|
|
Prints the working directory |
|
Changes directory |
|
Copies files and directories |
|
Remove files and directories |
|
Moves (renames) files and directories |
|
Creates directories |
|
Displays manual page of other commands |
|
Creates empty files |
|
Changes file permissions |
|
Runs an executable |
|
Exits the current shell session |
|
Executes commands as superuser |
|
Shutdowns your machine |
|
Displays processes and resources information |
|
Extracts compressed ZIP files |
|
Package managers |
|
Displays lines of text |
|
Prints file contents |
|
Reports shell processes status |
|
Terminates programs |
|
Tests network connectivity |
|
Efficient text editing |
|
Shows a list of previous commands |
|
Changes user password |
|
Returns the full binary path of a program |
|
Overwrites a file to hide its contents |
|
Inspects files interactively |
|
Displays last lines of a file |
|
Displays first lines of a file |
|
Prints lines that match patterns |
|
Outputs username |
|
Shows single-line descriptions |
|
Word count files |
|
Displays OS information |
|
Displays OS and hardware information |
|
Searches for files that follow a pattern |
|
Retrieves files from the internet |
Download complete Linux commands cheat sheet
The Linux commands reference cheat sheet
Best Linux command cheat sheet
|
|
|
|
Home/ Info/ Products/ BIG TECH Metaverse Metaverse Vs. Virtual Reality PC Buyers Guide/ IEEE 802 Standards Social Media Platforms Technology Videos/ Computer & IT Certifications Processor Generations Memory SSD Vs. HDD HTML 5G Android Tips and Tricks STEM Business Intelligence Tools Web Intelligence Quantum Computing Artificial Intelligence (AI) Internet of Things (IOT) Windows Run Commands Mac Keyboard Shortcuts Linux CLi Commands Venus Project/ Computer Security and Law Techno Lingo Encyclopedias Search Engines Glossary Online Jobs Contact
Certified Enterprise Blockchain Professional (CEBP) Web 3.0 Satoshi Nakamoto Cryptocurrency Ethereum NFT Merkle Tree El-Salvador eNaira
AWS Certification Google Certification Oracle Certifications cisco certifications Huawei Certification Microsoft Certifications Linux Certification Business Certifications
Google-Cloud-Platform-Guide Amazon-Web-Services-Guide Global-Cloud-Infrastructure-Of-AWS Amazon-Web-Services-Cli-Guide AWS-Cloudformation Devops Microsoft-Azure Oracle-Cloud Digitalocean-Cloud Openstack-Cloud
Active Components Passive Components Test Electrical Components Electronics Classification
Web C++ JAVA Python Angular.js Scala
Copyright BICT Solutions Privacy Policy. | Terms and Conditions apply | All rights reserved.