++++A shell is a command-line interface which allows to perform certain tasks using command
Linux & Terminal Commands

Linux & Terminal Commands
A shell is a command-line interface which allows to perform certain tasks using command
Basic Commands
cdβ change directory
cd ..β goes back a single directory
mkdirβ make new folder
mkdir -pβ makes directories and sub-directories too.
touchβ creates a new file
ls/dirβ lists all the files in the current directory
ls -aβ displays all the hidden files
ls -lβ shows more information like size, date about the files in working directory.
ls -Rβ show files, directories and sub-directories as well.
xdg-open/openβ opens the graphical interface of the present working directory.pwdβ Print Working Directory
cpβ creates a copy of a file or a folder
cp -Rβ copies directories and also the sub-directories
mvβ moves files
If names of two files are given, then the file gets renamed.rmβ removes only files permanently.
rm -Rβ removes directories permanently.
rm -rfβ force remove of files or directories.
sudoβ Super User Do gives system administrator privileges.
sudo apt update && sudo apt upgradeis used to download and install updates.
File Commands
-
echoβ displays -
catstands for concatenate, it is used to display the contents of a file
cat >creates a file.
-
vi <file_name>allows editing the file in the console.

- press
ito enter insert mode andEscto enter command mode.I- Insert text at the beginning of the current lineAβ Write at the end of the line (goes into insert mode)bβ Go to the beginning of the wordeβ Go to the ending of the worduβ Undo last changeUβ Undo all changes to the entire lineoβ Open a new line (goes into insert mode)ddβ Delete line3ddβ Delete 3 lines.Dβ Delete contents of the line after the cursorCβ Delete the contents of a line after the cursor and insert new text.dwβ Delete word4dwβ Delete 4 wordscwβ Change wordxβ Delete the character at the cursor~β Change case of individual character
:wqβ writes and quit the file in command mode:q!β quit without saving the changes in command mode:wβ save and continue editingyyβ Yank (copy a line of text)
- press
-
headβ displays the first 10 lines of a filehead -n 1β displays the first line of a file
-
tailβ displays the lasts 10 lines of a filetail -n 1β displays the last line of a file
-
diffβ compares files and displays lines which does not match -
trβ translate -
grepβ searches Strings in files.grep -wβ searches Strings of a complete word in files.grep -iβ [ignore cases] searches non-case sensitive Strings in files.grep -nβ searches Strings in files and also displays the line no.grep -winβ search non-case sensitive Strings in words in files and also displays the line no.grep -B 3β also displays 3 lines before the searched Strings.grep -rβ searches Strings in files recursively.grep -lβ displays list of filenames only.grep -cβ display the no of times the search string is present in a filegrep -pβ is used to search regular expressions
-
sortβ displays lines of file sorted alphabetically.sort -rβ displays lines of files sorted in reversesort -bβ ignores blacks while sortingsort -fβ ignores cases while sortingsort -nβ sorts numerical value
-
lsofβ lists all the opened fileslsof -u driptanilβ displays all the opened files by βdriptanilβ user
-
cutβ remove sections from each line of filescut -bβ removes only bytescut -cβ removes only characters
-
locate "*.txt"β will display location of all the .txt files. -
find .β displays all the files and folder in the working directory.find . -type dβ displays all the folders in the working directory.find . -type fβ displays all the files in the working directory.find -nameβ displays all files and folders with the name in working directory.find -inameβ displays all files and folders with the name [not case sensitive] in the working directory.find -mmin -15β displays all the files and folders modified less than 15 mins ago.find -mmin +30β displays all the files and folders modified more than 30 mins ago.find -mtime -10β displays all the files and folders modified less than 10 days ago.find -maxdepth 1β displays files and folders in working directory.find -mindepth 2β displays files and folders in the folders in working directory.find -size +1kβ displays files and folders more than 1 Kb size.find -emptyβ displays files and folders which are empty.find -perm 777β displays files and folders with -rwxrwxrwx permissions.find . -type f -name "name*" -exec rm -rf {'{}'} +βexec: execute the files and folder found by find command with another command,{}: place holder,+: add all the files.
Other Commands
where/whereisβ displays the location of the environment variables..bashrcfile consists of the commands which are automatically executed whenbashterminal is opened.- It also has
alias, which is a short user-defined command that the shell translates to another command. The variables in capitals are environmental variables. - temporary alias
- permanent alias [adding it in ~/.bashrc file
- It also has
.profilefile consist of all the environmental variable paths.$PATHβ consists all directories of the environmental variablesexportis used to set temporary environmental variablechmodβ used to change the access permissions of file.- Types of file permissions:
- Read(r) [value = 4]
- Write(w) [value = 2]
- Execute(x) [value = 1]
- Types of users:
- User[u]
- Guest[g]
- Other[o]
chmod 777β -rwxrwxrwxchmod 124β --x-w-r--chmod 000β ---------
- Types of file permissions:
chownβ change owner
Terminal Shortcuts:
Ctrl + Aβ move to the beginning of the lineCtrl + Eβ move to the end of the lineCtrl + Uβ remove the whole commandCtrl + Kβ removes everything to right of the cursor.Ctrl + Lβ clears the terminal likeclearcommandTabβ used to auto-complete;β many commands together
Network Commands
pingβ allows to request website server and displays all the statisticswgetβ download files from the internet.nslookupβ displays the IP address of a particular domainnetstatβ displays the ports that are listeningcurl ifconfig.me -sβ displays the IP address of the user
User Commands
whoamiβ displays the usernamehostnameβ displays the name of the Hostnamehostname -iβ displays the IP Address
useraddβ adds new userpasswdβ adds new passworduserdelβ deletes existing users
unameβ displays the kernel nameuname -oβ displays the typeuname -mβ displays the architectureuname -rβ displays the kernel version
idβ displays the group IDsgetent group driptanilβ checks if βdriptanilβ group exists
System Information Commands
dfβ shows the disk size and usage detailsdf -hβ displays the size and usage details in human readable format.
duβ shows the disk usage statistics in working directorydu -hβ shows the disk usage statistics in working directory in human readable format.
cat /etc/os-releaseβ displays the operation system informationlscpuβ displays the CPU detailsfreeβ displays the memory statisticsvmstatβ displays the virtual memory statistics
Managing Tasks Commands
topβ shows all the processes runningkillβ kills the process with the specified process ID.jobsβ displays the running commandsps auxβ the processes and the process IDhtopβ shows the processes which are using the resources
Operators
-
Ampersand
&β This command sends a process/script/command to the background.- to kill this background process use
psandkillcommand.
- to kill this background process use
-
Pipe
|β The output of the first command acts as input to the second command -
&&β executes the second command if and only if the first command is executed successfully. -
||β executes the second command if and only if the first command fails. -
!β not operator -
>>β append -
>β over-write -
Combination
(...)β group commands using;