ls is used to list files and directories.
lsls -l -hoption provides details in human readable format.
- Some options require values arguments/values to be passed.
help displays a list of options that you can use with the command.
ls --helpThis Command will be helpful when you don’t know about its parameters and return type etc.
clearcommand clears the terminal.- Shortcut:
Ctrl+L
clearmandisplays the user manual of a command .- Here we pass the command as an argument.
man <command>man ls- Type
qto exit the manual
date displays the system date and time.
datewhoami displays the current logged in user
whoami- Shell keeps track of the commands you have typed in.
- Use up ( ⬆) and down ( ⬇) arrows to access the commands.
historydisplays the history of the commands you have typed in so far.- By default, It shows the last 500 recent commands.
historyBash maintains the history to . bash_history file.
cat .bash_historyexit to close/end a shell session.
exittouch creates an empty file.
touch filenamecat eads contents of file and prints it.
cat filenameecho output/prints a string in the terminal.
echo "content"Using > (greater than) operator we can redirect the output of echo command to a file.
echo "Hello World!" > filename-mv renames the file names.
- destination can be a new or existing file.
mv source destinationmv practice.txt exam.txtcp copies src_file to dest_file.
cp src_file dest_filecp exam.txt fun_text.txtNote : If dest_file already exist then cp overrides the contents of dest_file.
rm removes (delete) files.
rm filenamerm exam.txtHidden Files
- Linux, by default, hides many of the sensitive system files, in order to avoid accidental changes.
- Hidden files starts with "."
ls ashows the hidden files.ls aalso shows the current and parent directories:.representsCurrent directory..representsparent directory
ls -amkdir creates a directory.
mkdir directory_pathpwd prints name of current working directory.

cd changes the current working directory.
cd directory_pathNote : cd / changes your current directory to root folder.
mkdir creates a directory.
mkdir directory_namecd ..move to parent directory.- Here
..is relative path to parent directory.
cd ..There are two notations for file paths:
- Absolute Path
- Relative Path
Representing the complete path of a file or folder from the root.

Representing the path of a file or folder wrt. current working directory.
In relative path conventions:
Each user in the computer is given a separate directory to work with - called home directory.
cd ~can be used to switch to home directory.
cd ~cd(cd and space) command can also be used to switch to home directory.
cd mv renames the directory name
mv source destinationmv tutorial commandsmv moves files or directories from source to destination paths.
mv source destinationmv welcome.txt commandscp can be used to copy files between directories.
cp file_path directory_namecp welcome.txt commandscp -r can be used to copy a directory.
cp -r source_path destination_pathcp -r commands linuxRaises an error if destination path have any non existing directories in between.

rm -r removes(deletes) directories.
rm -r directory_namerm -r commands- A text editor is used for editing text files.
- Various text editors are:
- Notepad++
- Sublime Text
- gEdit
- Visual Studio Code etc..
Nano is an easy to use command line text editor for Unix and Linux-based operating systems.

To open a file with nano, pass the filename as an argument.
nano filenameAdd the text of the file in the middle of the editor.

To save a file, PRESS Ctrl+O and Enter()
To exit from nano editor, PRESS Ctrl+X
To view file Contents:
cat filenameWe can filter the contents of a file using the following filter commands.
- head
- tail
- grep
- Used to print top N lines of a file.
- By default, it will print the first 10 lines.
head [-N] filenamehead -2 sentences.txt- Used to print last N lines of a file.
- By default it will print the last 10 lines.
tail [-N] filenametail -2 sentences.txtwc is used to find out number of lines, word count and characters count in the files.
wc filename- Pipe is used to combine two or more commands
- Output of one command is passed as an input to the command followed and so on.
command_1 | command_2 | command N cat sentences.txt | head -2Searches a file or files for lines that have a certain pattern.
cat filename | grep <pattern>cat sentences.txt | grep "morning"Number of lines that contain the word morning in the given file.

Occurrences of the word "morning" in the given file from the lines 10 to 15

">" takes the standard output of the command and redirects it to the file.
command > filenamecat sentences.txt | head -2 > learnings.txt- File compression is a reduction in the number of bits needed to store the data of a file.
- Files are stored in such a way that, it uses less disk space than all the individual files and directories combined
- Advantages of compressing files are:
- taking less disk space
- easier and faster transmission
- Commonly used file formats for the compressed files:
We can use tar to compress files & directories
tar -czvf file-name.tar.gz path1 path2 ..tar -czvf my_collection.tar.gz videos report.txttar -xzvf filename.tar.gz -C pathtar -xzvf my_collection.tar.gz -C collectionsIt is used to package all the files into one file with .zip extension
zip -r zipfile.zip file1 folder1 file2 ...zip -r collections.zip videos report.txtThe unzip command extracts all files from the specified ZIP archive
unzip filename.zip -d pathunzip collections.zip -d new-folderThe root user, also known as the superuser or administrator, has access to all commands and files.
sudo command temporarily elevates the privileges allowing users to complete sensitive tasks without logging in as the root user.
sudo commandwhich command is used to identify the location of a given executable path.
which command$ which sudo
/usr/bin/sudouseradd is used to create a new user with the given username.
sudo useradd username sudo useradd ganupasswd is used to set or change password of a given user.
sudo passwd usernamesudo passwd ganusu is used to execute command as another user.
su usersu -c command userMulti-user operating systems like linux provide two levels of authorization in securing the files
- Ownership
- Permission
Users accessing a file/ directory can be categorized into 3 types

chmod permissions filenamechmod 764 sample.txt"chmod" stands for change mode

- For changing the user of a file/directory
sudo chown user filenamesudo chown root sample.txt- For changing the user and group of a file/directory
sudo chown user:group filenamesudo chown root:root sample.txt- A package file is a compressed collection of files that comprise the software package
- Packages are stored in repositories to make them accessible to users
- APT stands for the Advanced Packaging Tool
- It is used to install, upgrade or remove software packages in linux
sudo aptInstalling a package from a repository
sudo apt install package_name- It is a Package Manager for macOS.
- With
brewcommand you can install the packages in macOS.
- With
brew install package_nameyum is a graphical based package management tool for RPM (RedHat Package Manager) based Linux systems.
yum package_namewget is a command-line utility for downloading files from the web.
To install wget :
- apt
sudo apt install wget- brew :
sudo brew install wget- yum:
sudo yum install wgetwget will download the resource specified in the url to the current directory.
wget "URL"wget "https://www.lifewire.com/uses-of-command-wget-2201085"curl is a command-line utility for transferring data from or to a server designed to work without user interaction.
To instal curl :
- apt :
sudo apt install curl- brew :
sudo brew install curl- yum :
sudo yum install curlcurl prints the contents of the URL to the output.
curl "URL"curl "wttr.in"apt-cache command is used to searches for a particular package.
sudo apt-cache search package_nameapt-cache search google- System checks against the repositories.
- If newer version available of the program it will update the information about the existing packages and their versions available. Updating a package from a repository:
upgrade will upgrade all the applications to latest version.
sudo apt upgradeupdate will simply update the information about the existing packages and their versions available
sudo apt updatedpkg -l : It is used to list all installed packages
sudo dpkg -lPPA (Personal Package Archive) is an application repository that can be used to upgrade and install packages from third parties.
add-apt-repository : It is used to add repository
sudo add-apt-repository repository_linkYour Linux device can use that signature to check the authenticity of the packages.
apt-key : Add PPA security key
sudo apt-key add - KEY_IDremove : removes the installed packages
sudo apt remove package_name
Warning
Under the installation of an apt package from a PPA, there is a change in one of the MongoDB installation steps, due to the changes made by the MongoDB website.
Update command from
curl https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -to
curl https://pgp.mongodb.com/server-4.4.asc | sudo apt-key add -for a seamless monogodb installation.
ping checks the network connectivity between host and server/host.
ping hostname/IP addressping google.comtraceroute prints the route that a packet takes to reach the host.
traceroute host_addresstraceroute google.comA network interface is a software interface to networking hardware.
Different types of network interfaces are:
- Ethernet
- Loopback etc.
ifconfig gives you the information of various network interfaces.
ifconfigexxxx is a physical interface representing Ethernet network card.

- lo is a special virtual network interface called loopback device.
- It is used to connect to services running on the user system

- Linux environment variables act as placeholders for information stored within the system.
- They will be available to the programs launched from the shell.
env command can be used to print all the environment variables.
envexport command is used to define/update value for a variable.
export VARIABLE_NAME=variable_valueexport CUSTOM_ENV_VARIABLE=10- Use $ to access environment variables.
- When redefining variables, do not use the dollar sign.
echo $VARIABLE_NAME$ echo $CUSTOM_ENV_VARIABLEunset command removes an environment variable.
unset VARIABLE_NAMEPATH variable holds the colon-separated list of folder paths where executables are located.
echo $PATHalias is a (usually short) name that the shell translates into another name or command.
alias name=valuealias t=traceroute
t google.comunalias removing an existing alias is known as unaliasing.
unalias alias_nameEnvironment variables defined in a shell are deleted as soon as you exit the terminal.
To persistent environment variables we write them in .bashrc or ~/.bash_profile configuration files.
export VARIABLE_NAME=variable_value# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/Examples/startup-files (in the package bash-doc)
# for Examples
case $- in
*i*) ;
...
export CUSTOM_ENV_VARIABLE=5-
To immediately apply all changes in .bashrc,
use the
sourcecommand
source ~/.bashrc









