DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for 20+ Essential Terminal and Linux Commands for every User
Tabassum Khanum
Tabassum Khanum

Posted on • Updated on

20+ Essential Terminal and Linux Commands for every User

What Is Linux?
Linux is an operating system's kernel. You might have heard of UNIX. Well, Linux is a UNIX clone. But it was actually created by Linus Torvalds from Scratch. Linux is free and open-source, that means that you can simply change anything in Linux and redistribute it in your own name! There are several Linux Distributions, commonly called β€œdistros”.

  • Ubuntu Linux
  • Red Hat Enterprise Linux
  • Linux Mint
  • Debian
  • Fedora

Linux is Mainly used in servers. About 90% of the internet is powered by Linux servers. This is because Linux is fast, secure, and free! The main problem of using Windows servers are their cost. This is solved by using Linux servers. The OS that runs in about 80% of the smartphones in the world, Android, is also made from the Linux kernel. Most of the viruses in the world run on Windows, but not on Linux!

Linux Shell or β€œTerminal”
A shell is a program that receives commands from the user and gives it to the OS to process, and it shows the output. Linux's shell is its main part. Its distros come in GUI (graphical user interface), but basically, Linux has a CLI (command line interface). In this tutorial, we are going to cover the basic commands that we use in the shell of Linux.

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.

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.

CLI stands for command line interface. It is a program that allows users to type text commands instructing the computer to do specific tasks.

WHY Command Line?

a. More control over your Machine
We can run commands to change permissions, view hidden files, interact with database, start server, manage processes, etc.

b. It's Faster?
Once you learn the basic commands and commit to memory, you can perform tasks much faster than you could using a GUI. There is a bit of learning curve, but it's 100% worth it!

c. It's Available Everywhere
The commands you'll learn run on Linux & Mac machines out of the cox, but with a little work they will also run on Windows!

List of Linux Commands

Basic File Operations

1.ls - list files in the directory

ls
Enter fullscreen mode Exit fullscreen mode

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.

2.cp - copy a file

cp file_to_copy.txt new_file.txt
Enter fullscreen mode Exit fullscreen mode

To use the cp command, just type it along with the source and destination files.

3.mv - rename ("move") a file

mv [Source] [Destination]
Enter fullscreen mode Exit fullscreen mode

You use the mv command to move (or rename) files and directories through your file system.

4.rm - Delete("remove") a file

rm filename
Enter fullscreen mode Exit fullscreen mode

The rm command in Linux helps you delete files and directories. Be careful while using it, though, because it’s very difficult (yet not impossible) to recover files deleted this way.

Directory Operations

5.cd - change your current directory

cd filename
Enter fullscreen mode Exit fullscreen mode

Once you have a folder, you can move into it using the cd command. cd means change directory. You invoke it specifying a folder to move into. You can specify a folder name, or an entire path.

There are some tricks with the cd command that can save you a lot of time when playing around with it:

  • Go to the home folder
cd
Enter fullscreen mode Exit fullscreen mode
  • Move a level up
cd ..
Enter fullscreen mode Exit fullscreen mode
  • Return to the previous directory
cd -
Enter fullscreen mode Exit fullscreen mode

6.pwd - print the name of the your current directory

pwd
Enter fullscreen mode Exit fullscreen mode

The pwd command stands for β€œprint working directory,” and it outputs the absolute path of the directory you’re in.

7.mkdir - Create(make) a new directory

mkdir filename
Enter fullscreen mode Exit fullscreen mode

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.

8.dirname - print a path without its final path

dirname [OPTION] NAME
Enter fullscreen mode Exit fullscreen mode

dirname is a command in Linux which is used to remove the trailing forward slahes β€œ/” from the NAME and prints the remaining portion. If the argument NAME does not contains the forward slash β€œ/” then it simply prints dot β€œ.”.

File creation and editing

9.vim - Text editor, extension of unix vi

vim
Enter fullscreen mode Exit fullscreen mode

vim is a very popular file editor, especially among programmers. It's actively developed and frequently updated, and there's a big community around it.
It lets you edit plain text files using efficient keybindings.

vi in modern systems is just an alias for vim, which means vi improved.

You start it by running vi on the command line.

File Properties

10.touch - change the timestamps of the directories and files

touch filename
Enter fullscreen mode Exit fullscreen mode

If the file already exists, it opens the file in write mode, and the timestamp of the file is updated.

11.chmod - change protection mode of files and directories

chmod +x script
Enter fullscreen mode Exit fullscreen mode

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.

Read more about chmod command

File Location

12.find - locate files in a directory hierarchy.

find [flags] [path] -name [expression]
Enter fullscreen mode Exit fullscreen mode

The find command can be used to find files or folders matching a particular search pattern. It searches recursively.

which - locate executable in your search path

which python

#/usr/bin/python
Enter fullscreen mode Exit fullscreen mode

The which command outputs the full path of shell commands. If it can’t recognise the given command, it’ll throw an error.

Suppose you have a command you can execute, because it's in the shell path, but you want to know where it is located.

You can do so using which. The command will return the path to the command specified.

File text Manipulation

13.grep - find lines in a file that match a regular expression

grep "word" filename
Enter fullscreen mode Exit fullscreen mode

grep stands for global regular expression print. 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.

Viewing Process

14.htop

htop
Enter fullscreen mode Exit fullscreen mode

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.

15.ps - list process

ps
Enter fullscreen mode Exit fullscreen mode

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.

Network

16.dig

dig [server] [name] [type]
Enter fullscreen mode Exit fullscreen mode

dig command stands for Domain Information Groper. It is used for retrieving information about DNS name servers. It is basically used by network administrators. It is used for verifying and troubleshooting DNS problems and to perform DNS lookups.

Web Browesing

17.wget - download web pages and files

wget filename
Enter fullscreen mode Exit fullscreen mode

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.

check

18.ssh

ssh user_name@host(IP/Domain_name)
Enter fullscreen mode Exit fullscreen mode

ssh stands for β€œSecure Shell”. It is a protocol used to securely connect to a remote server/system. ssh is secure in the sense that it transfers the data in encrypted form between the host and the client. It transfers inputs from the client to the host and relays back the output. ssh runs at TCP/IP port 22.

Controlling Processes

19.kill - killing a process(or send it a signal)

kill firefox
Enter fullscreen mode Exit fullscreen mode

Linux processes can receive signals and react to them.

That's one way we can interact with running programs.

The kill program can send a variety of signals to a program.

shutdowns

20.shutdown

shutdown now
Enter fullscreen mode Exit fullscreen mode

the shutdown command lets you power off your machine. However, it also can be used to halt and reboot it.

Users and Their Environment

21.printenv

printenv
Enter fullscreen mode Exit fullscreen mode

The printenv command, used to print the values of environment variables

In any shell there are a good number of environment variables, set either by the system, or by your own shell scripts and configuration.

Host Information

22.ping

ping google.com

ping 8.8.8.8
Enter fullscreen mode Exit fullscreen mode

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

23.ip

ip [ OPTIONS ] OBJECT { COMMAND | help }
Enter fullscreen mode Exit fullscreen mode

ip command in Linux is present in the net-tools which is used for performing several network administration tasks. IP stands for Internet Protocol. This command is used to show or manipulate routing, devices, and tunnels. It is similar to ifconfig command but it is much more powerful with more functions and facilities attached to it. ifconfig is one of the deprecated commands in the net-tools of Linux that has not been maintained for many years. ip command is used to perform several tasks like assigning an address to a network interface or configuring network interface parameters.

24.man
To see the manual page of the mkdir command, type:

man mkdir
Enter fullscreen mode Exit fullscreen mode

Another essential Linux command is man. It displays the manual page of any other command (as long as it has one).

25.cat

cat filename
Enter fullscreen mode Exit fullscreen mode

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:

26.echo

echo message
Enter fullscreen mode Exit fullscreen mode

The echo command displays defined text in the terminal β€” it’s that simple

27.sudo

sudo command
Enter fullscreen mode Exit fullscreen mode

The sudo command allows you to run programs with the security privileges of another user (by default, as the superuser). It prompts you for your personal password and confirms your request to execute a command by checking a file, called sudoers, which the system administrator configures. Using the sudoers file, system administrators can give certain users or groups access to some or all commands without those users having to know the root password. It also logs all commands and arguments so there is a record of who used it for what, and when.

Wrapping Up!
It can take some time to learn Linux commands, but once you master the basics, it becomes your best ally, and you won’t regret choosing it as your daily driver.
In this blog i only covered 30-ish common commands but we still have a lot more helpful Linux commands. I recommend you to don't just stop here and check out more resources:

  1. LINUX Commands - https://api.daily.dev/r/LXA3HnkWq
  2. freecampcode - https://www.freecodecamp.org/news/learn-the-50-most-used-linux-terminal-commands/
  3. Linux for Beginners - https://www.crio.do/blog/linux-for-beginners/

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.