Basic Linux commands for Beginners 2022

Linux is a family of of open-source Unix-like operating systems based on the Linux kernel. Linux is an operating system kernel created and developed by Linus Torvalds. Linux being open source, it can be modified and used freely. There are many flavours of Linux which are popularly know as Linux Distributions. Some of the most popular distributions are

  • Debian
  • Fedora linux
  • Ubuntu
  • CentOS

Commercial distributions include Red Hat Enterprise Linux and SUSE Linux Enterprise.

Linux is mostly used in servers as its free, fast and secure and consumes less resources as compared to windows servers. Linux servers uses shell or terminal for processing user data or commands. Internet is powered by Linux servers as its virus free and secure. In this tutorial, we will learn some basic linux commands which are useful for Beginners.

Basic Linux Commands

1. tty – The tty command of terminal basically prints the name of the terminal connected to standard input. tty is short name of teletype, its’s popularly known as a terminal and it allows you to interact with the system by passing on the data (you input) to the system, and displaying the output produced by the system. It reveals the current terminal which is used by the user

[ved@arch ~]$ tty
/dev/pts/1

2. whoami – The whoami command finds the username associated with current effective user id. This is generally used to identify the currently logged in user in a shell. This command is also useful in shell scripts to identify the user id from which the script is running. In short, it reveals the currently logged-in user

[ved@arch ~]$ whoami 
ved

3. which – This command is used to locate the executable file associated with the given command by searching it in the path environment variable. It reveals where in the search path a program is located on the system

[ved@arch ~]$ which ls
/usr/bin/ls

4. echo – This command is used for displaying lines of text or string which are passed as
arguments on the command line. This is one of the basic command in linux and most commonly used in
shell scripts

[ved@arch ~]$ echo "Basic Linux Commands"
Basic Linux Commands

a. echo $PATH – This commands looks for executable specified by the PATH variable and dumps or prints the current path to STDOUT

[ved@arch ~]$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/var/lib/snapd/snap/bin

b. echo $PWD – dumps or prints the contents of the $PWD variable on the screen / STDOUT . PWD stands for present working directory in linux

[ved@arch ~]$ echo $PWD
/home/ved

c. echo $OLDPWD – dumps or prints the most recently visited directory on the system

[ved@arch ~]$ echo $OLDPWD 
/var

5. set – The set command displays and sets the names and values of shell and Linux environment variables

[ved@arch ~]$ set
BASH=/usr/bin/bash
BASHOPTS=checkwinsize:cmdhist:complete_fullquote:expand_aliases:extquote:force_fignore:globasciiranges:hostcomplete:interactive_comments:progcomp:promptvars:sourcepath
BASH_ALIASES=()
BASH_ARGC=([0]="0")
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
//Output omitted

6. clear – clear is a standard Unix computer operating system command that is used to clear the terminal screen

[ved@arch ~]$ clear

7. reset – resets the screen buffer or is used to initialize the terminal

[ved@arch ~]$ reset

8. history – This command allows us to view the history of the commands that we run in the terminal. You can set the maximum number of entries BASH should store as history in your . bashrc file. history command is one of the most basic linux commands used frequently

[ved@arch ~]$ history 
   24  Mar22-192316 kubectl get po
   25  Mar22-192324 kubectl describe pod nginx
   26  Mar22-192328 kubectl get po
   27  Mar22-192412 kubectl get po -o wide
   28  Mar22-192559 kubectl describe po
   29  Mar22-193225 kubectl get po –show-labels
   30  Mar22-193318 kubectl edit pod nginx
   31  Mar22-193330 sudo pacman -
   32  Mar22-193338 sudo pacman -S vi
   33  Mar22-193348 kubectl edit pod nginx

a. !516 – We can run any command from history command output by just adding exclamation(!) mark before the number . We have pwd command at 516 position which can be executed using below command

[ved@arch ~]$ !516
pwd
/home/ved

b. command history is maintained on a per-user basis via:

~/.bash_history

~ = users’s $HOME directory in the BASH shell

9. pwd – This command prints the working directory in which user is currently working

[ved@arch ~]$ pwd
/home/ved

10. cd – This command is used to change the current working directory in Linux and other Unix-like operating systems. It is one of the most basic and frequently used commands when working on the Linux terminal.

[ved@arch ~]$ cd /var/
[ved@arch var]$ 

a. ‘cd ‘ When we use cd command with no options, it changes directory to the $HOME directory of the user

[ved@arch var]$ cd
[ved@arch ~]$ pwd
/home/ved

b. ‘cd ~’ When we use ~ with cd command , working directory is changed to the $HOME directory of the user

[ved@arch var]$ cd ~
[ved@arch ~]$ pwd
/home/ved

c. ‘cd /’ This command changes to the root of the file system

[ved@arch ~]$ cd /
[ved@arch /]$ 

d. ‘cd Desktop/’ changes from the current directory to the relative directory ‘Desktop’

[ved@arch ~]$ cd Desktop/
[ved@arch Desktop]$ 

e. ‘cd ..’ changes us one-level up in the directory tree

[ved@arch Desktop]$ cd ..
[ved@arch ~]$ pwd
/home/ved

f. ‘cd ../..’ changes us two-levels up in the directory tree

[ved@arch ~]$ cd ../../
[ved@arch /]$ pwd
/

11. Arrow keys (up and down) navigates through your command history

[ved@arch /]$ cd ~

12. ls – This command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory

[ved@arch ~]$ ls
components.yaml            kubectl                         rancher-cluster.yml
daemonset.yaml             kubelet-error.png               rhel-download.png
Desktop                    kvm-start.sh                    rke
Documents                  kvm-stop.sh                     snap

a. ls / – lists the contents of the ‘/’ mount point on the std output.

[ved@arch ~]$ ls /
bin   dev  home  lib64  opt   rancher  run   snap  sys  usr
boot  etc  lib   mnt    proc  root     sbin  srv   tmp  var

b. ls -l – lists the contents of a directory in long format and also Includes: permissions, links, ownership, size, date, name

[ved@arch ~]$ ls -l
total 98272
-rw-r--r-- 1 ved  ved      4181 Feb 23 15:14 components.yaml
-rw-r--r-- 1 ved  ved       311 Mar 23 19:15 daemonset.yaml
drwxr-xr-x 1 ved  ved        20 Mar 15 19:49 Desktop
drwxr-xr-x 1 ved  ved        94 Mar 23 20:21 Documents
drwxr-xr-x 1 ved  ved      2180 Mar 26 17:28 Downloads

c. ls -ld /etc – lists properties of the directory ‘/etc’, and NOT the contents of ‘/etc’

[ved@arch ~]$ ls -ld /etc
drwxr-xr-x 1 root root 3476 Mar 26 18:58 /etc

d. ls -ltr – sorts chronologically from older to newer (newest file at the bottom)

[ved@arch ~]$ ls -ltr
total 98272
-rw-r--r-- 1 ved  ved      4684 Feb 23 15:14 high-availability.yaml.1
-rw-r--r-- 1 ved  ved      4181 Feb 23 15:14 components.yaml
drwxr-xr-x 1 ved  ved         0 Feb 28 00:05 Videos
drwxr-xr-x 1 ved  ved         0 Feb 28 00:05 Templates
drwxr-xr-x 1 ved  ved         0 Feb 28 00:05 Public
drwxr-xr-x 1 ved  ved         0 Feb 28 00:05 Music
drwxr-xr-x 1 ved  ved       174 Feb 28 00:11 paru-bin
drwxr-xr-x 1 ved  ved         8 Feb 28 03:56 google-chrome-git
drwxr-xr-x 1 ved  ved         8 Feb 28 03:57 goo
drwxr-xr-x 1 ved  ved       174 Feb 28 03:58 yay-git
-rwxr-xr-x 1 ved  ved     16783 Mar  1 11:00 install.sh
-rw-r--r-- 1 ved  ved  46592000 Mar  2 14:41 kubectl

e. ls –help – returns possible usage information of ls command

[ved@arch ~]$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..

f. ls -a – reveals hidden files. e.g. ‘.bash_history, .bashrc’

[ved@arch ~]$ ls -a
.                               .minikube
..                              .mozilla
.bash_history                   Music
.bash_logout                    .nv
.bash_profile                   .nvidia-settings-rc
.bashrc              

Conclusion

In this tutorial, we have explored some basic linux commands that are used by sysadmins in their day to day life. Stay tuned for more linux commands cheat sheet.

5 1 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments