Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
September 6, 2022 11:59 am GMT

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, theres 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

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

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

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

mv [Source] [Destination]

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

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

rm filename

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

Directory Operations

5.cd - change your current directory

cd filename

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
  • Move a level up
cd ..
  • Return to the previous directory
cd -

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

pwd

The pwd command stands for print working directory, and it outputs the absolute path of the directory youre in.

7.mkdir - Create(make) a new directory

mkdir filename

To create folders in the shell, you use the mkdir command. Just specify the new folders name, ensure it doesnt exist, and youre ready to go.

8.dirname - print a path without its final path

dirname [OPTION] NAME

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

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

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

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]

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

The which command outputs the full path of shell commands. If it cant recognise the given command, itll 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

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

htop is an interactive process viewer that lets you manage your machines resources directly from the terminal. In most cases, it isnt installed d by default, so make sure to read more about it on its download page.

15.ps - list process

ps

With ps, you can take a look at the processes your current shell session is running. It prints useful information about the programs youre running, like process ID, TTY (TeleTYpewriter), time, and command name.

Network

16.dig

dig [server] [name] [type]

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

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)

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

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

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

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.comping 8.8.8.8

ping is the most popular networking terminal utility used to test network connectivity. ping has a ton of options, but in most cases, youll use it to request a domain or IP address

23.ip

ip [ OPTIONS ] OBJECT { COMMAND | help }

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

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

Cat, short for concatenate, lets you create, view, and concatenate files directly from the terminal. Its mainly used to preview a file without opening a graphical text editor:

26.echo

echo message

The echo command displays defined text in the terminal its that simple

Wrapping Up!
It can take some time to learn Linux commands, but once you master the basics, it becomes your best ally, and you wont 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/

Original Link: https://dev.to/codewithtee/20-essential-terminal-and-linux-commands-for-every-user-1c7o

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To