Basic Linux Commands Everyone Must Know

Hey developers! This article is devoted to those people who are NOT afraid of the Black Screen of Death. In this article, we will be looking at some basic Linux commands everyone must know. Especially for those who are involved in Cloud Services or generally from an IT background.  

So, open up your console or terminal, and let’s go through this Linux commands cheat sheet.

*Note: These commands are Linux Bash Script commands and would not work on Windows CMD. 

Prerequisite

General Commands

1. man Manual pages

With the man command, you can retrieve the information in the manual and display it as text output on your screen. 

2. passwd  

Change your login password. Depending on a privilege, one can change user’s and group passwords as well as real name, login shell, etc. 

‘q’ is used to quit the manual

3. date

Displays dates in various formats 

%D – Display date as mm/dd/yy
%Y – Year (e.g., 2020)
%m – Month (01-12)
%B – Long month name (e.g., November)
%b – Short month name (e.g., Nov)
%d – Day of month (e.g., 01)
%j – Day of year (001-366)
%u – Day of week (1-7)
%A – Full weekday name (e.g., Friday)
%a – Short weekday name (e.g., Fri)
%H – Hour (00-23)
%I – Hour (01-12)
%M – Minute (00-59)
%S – Second (00-60)

4. cal

Calendar, for a month and for an entire year. Years range: 1 9999 (but not 0) 

5. clear

Clears the terminal screen.

6. sleep

“Sleeping” is doing nothing for some time. Usually used for delays in shell scripts 

7. time

It works in conjunction with another command. The time command will execute your normal command but then calculates and displays the time it took to complete it. 

8. which

Displays a path name of a command. Searches a path environmental variable for the command and displays the absolute path. 

To find which tcsh and bash are actually in use, type: 

9. whereis

Display all locations of a command (or some other binary, man page, or source file). Searchers all directories to find commands that match whereis argument 

10. alias / unalias 

Removes alias. Requires an argument.

11. history and ! 

Display a history of recently used commands. 

12. whoami

Display a history of recently used commands. 

13. df

df stands for disk free. It fetches details, of all the mounted disks in the system, about their used and available space. 

-a, -all : includes pseudo, duplicate and inaccessible file systems.
-h, -human-readable : print sizes in power of 1024
-H, -si: print sizes in power of 1000
-i, -inodes : list inode information instead of block usage
-l, -local : limit listing to local file systems
-P, -portability : use POSIX output format
-T, -print-type : print file system type

14. exit / logout 

Exit from your login session.  

15. shutdown

Causes the system to shut down or reboot cleanly. May require superuser privileges, so just use sudo before the commands 

Commands for Files & Directories

1. ls

In Linux, a folder is called a directory. To list all the content of a directory we use the Linux ls command as follows: 

2. cat

It is used to display and concatenate files. 

3. head / tail

Head shows the top 10 lines of the content. 

Tails shows the last 10 lines of the content. 

4. more / less

To display contents of large files, page by page or scroll, line by line up and down. It is interactive.  

Use the following screen navigation commands while viewing large log files.
1. CTRL+F
forward one window
2. CTRL+B
backward one window
3. CTRL+D
forward half window
4. CTRL+U
backward half window

In a smaller chunk of data, where you want to locate particular error, you may want to navigate line by line using these keys:
1. j – navigate forward by one line
2. k – navigate backward by one line

5. touch 

Is used to create files.

6. cp 

Copies files / directories 

Useful option: -i to prevent overwriting existing files and prompt the user to confirm 

Both files must be in the same working directory. If they are in various directories, the absolute path must be given 

7. mv

Moves or renames files/directories. 

8. rm

This is a Linux delete file command. To removes file(s) and/or directories, we use the Linux rm command. 

9. find

This is a Linux find command which looks up a file in a directory tree. 

10. mkdir

Creates a directory. 

11. rmdir

This is Linux remove directory command. It removes or deletes a directory.

12. cd

Changes your current directory to a new one.

13. pwd

Displays personal working directory, i.e. your current directory.  

14. grep

Searches its input for a pattern. The pattern can be a simple substring or a complex regular expression. If a line matches, it’s directed to STDOUT; otherwise, it’s discarded. 

15. pipes

What’s a pipe?

  • Is a method of inter-process communication (IPC)
  • In shells a ‘|’ symbol used
  • It means that the output of one program (on one side of a pipe) serves as an input for the program on another end.
  • A set of “piped” commands is often called a pipeline

16. nano

There are a few text editor tools in Linux. I personally prefer the nano tool. Type in the following command to open a file in edit mode: 

If it is not letting you save it, then open the file with sudo command.

And that’s all! 

Again, these commands will only work on a LINUX terminal. And a common way to run Linux with Windows is to start a Virtual Machine using VMware. 

I hope this article helped you with Basic Linux Commands Everyone Must Know. You may also want to read about How to add Users, Groups and Assign Permissions in Linux. Please like, and leave your reviews in the comment section below.

Have a great one! 

One reply on “Basic Linux Commands Everyone Must know”

  • student
    14 October, 2022 at 12:06 PM

    v helpful

Comments are closed.