LINUX SHELL COMMANDS

File and directory commands


$ls
$ls –l
$ls –al
$ls –R
$ls –Rl
$ls –i
$ls –il
$touch file1
$touch file2 file3 file4
$cat > Newfile.txt
This is test file
<ctrl+c>
$ls –l
$cat >> Newfile.txt
Second line in this file
<ctrl+c>
$ls –l /dev |more
$ls –l /dev |less
      

Long list details


$ls –l
drwxrwxrwx 3 root root 4096 Jan 25 07:00 forms.txt
PERMISSIONS LINKS OWNER GROUP SIZE DATE & TIME FILENAME
      

Copy /move commands


$cp testfile.txt newfile.txt
$cp –r Dir1 /tmp
$mv Jack Aves
$mv Aves /opt
      

Directory related commands


$mkdir PVR
$mkdir inox1 inox2 inox3
$rmdir inox1
$cd PVR
$mkdir ait1 ait2 ait3
$cd ait1
$touch file2 file4 file5
$cd
$rm –rf PVR
      

Shells in Linux


Bash - Bourne Again Shell in RHEL and CentOS
Csh - C shell with C type syntax
Zsh - used in Mac
      

Available shells in Linux


#cat /etc/shells
/bin/bash
/bin/sh
/sbin/nologin
/usr/bin/sh
/usr/sbin/nologin
/bin/tcsh
/bin/csh
      
#usermod –s /bin/csh user3

Access help using command line


$man cp
$help cp
$mv –-help
$mandb                     Update manual pages
      

Switch to super user (root)


[user1@ait~]$su –
Password:[type root password]
[root@ait~]#
      

Filter text files using commands


#grep <string> <filename>
#grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
#find / -name ishaq
#find / -user john
#updatedb
#locate <filename>
      

Miscellaneous commands


#uname –r                            Display kernel version
#uname –a                            Detailed kernel info
#ps                                  Show Foreground processes
#top                                 Show Background processes
#file *                              Shows types of files
#which [command]                     Command location
#date
#cal                                 Calendar
#cal 2025
#cal –y
#cal 08 2026
#cal -3                              Calendar of previous, current and next
                                     month
#timedatectl status
#timedatectl list-timezones
#timedatectl set-timezone “Asia/Kolkata”
#timedatectl set-time ‘2025-01-25 9:00:00’
#history
#history –d <number>
#history –c
#less <filename>
#more <filename>
#head <filename>
#head -5 <filename>
#tail <filename>
#tail -3 <filename>
#echo $PATH                           Path of running commands
#env
#w                                    Who is logged on
#uptime
#du –h
#df –h
#whatis <command>
#logout
#whoami
#free -h
      

Hardlink and softlinks

HARDLINKS

#ln <original> <link>
#ln courses.txt newcourses.txt
      
SOFTLINKS

#ln –s <original> <link>
#ln –s receipt.txt receipt2.txt
      

Text editor – vim (vi improved) Visual editor


Normal Mode
Insert Mode
Command Mode
i, a - Input mode
Esc - Input mode to command mode
:w -Write to current file
:wq - Write and quit the file
:q! - Quit without saving
:w filename - Write current file with different file name
dd Delete current line
5dd Delete 5 lines
yy Copy current line
10yy Copy 10 lines
p - Paste or put the contents
P - Put above line
u - Undo last command
Ctrl + r - Redo last command
gg - Goes to first line
G - Last line
/text - search
:%s/old/new/g - Search and replace
      

TAR- Tape Archive Format


     #mkdir imax
     #cp /etc/* /root/imax
     #tar –cvf imax1.tar /root/imax
Update #tar –uvf imax1.tar /home/user1
Show files #tar –tvf imax1.tar
Extract to original #tar –xvf imax1.tar

Compress and Uncompress utilities in Linux


     
      Compress file using gzip
            #gzip imax1.tar
Uncompress file using gunzip #guzip imax1.tar.gz
Compress file using bzip2 #bzip2 imax1.tar
Uncompress file using bunzip2 #bunzip2 imax1.tar.bz2