Linux Commands and Icc Commands 3
Linux Commands and Icc Commands 3
ICC COMMANDS
Presenting by Siva Reddy
CONTENTS
• Linux commands
• Grep
• Awk
• Sed
Linux Commands
• ls :
list files and directories
• use:
ls –l: indicates file/directory type, permissions, owner, size, last modified.
– normal, d- directory, s-socket file, l-link file
ls -a: shows hidden files/directories
ls -t ; lists the files/directory on basis of modification time
ls -lart ; lists all the files and directories in order of last modified.
• clear:-
clear the terminal (but keep the history of commands intact)
• man / –help:-
Show a manual of command and switches written in details.
• pwd:-
Print Working Directory, The directory where you are currently.
• cd:-
Change Directory, to move to another directory.
Use:
cd .. ; back to parent directory.
cd – ; back to previous directory.
cd ~ ; go to home directory.
cd ../../../ ; back to n steps.
cd ‘abc xyz’ ; go to a directory whose name contain white space.
• mkdir:-
create a directory
use:
mkdir directory_name ; To create a new directory with the given name.
mkdir dir1 dir2 dir3 ; To create multiple directories in a single step.
• touch:-
create a file
use:
touch file_name ; create a new file.
touch file1 file2 file3 ; To create multiple files.
touch –a file_name ; to change file access time.
touch –m file_name ; to change the file modification time.
• gedit file_name &:-
create and edit a file in GUI mode.
use:
gedit /path/to/file_name ; create and edit a file in specified location; word
count, line no. , language.
• vi file_name:-
create and edit a file using command-line interface
use:
i ; Switch to edit mode
ESc ; Exit from edit mode and Switch to command mode
/string ; find the string
Esc + :q ;exit without saving
Esc + :s ; Save only not exit
Esc + :wq ; save and exit
• cp source destination:-
copy command.
use:
cp source_file destination_dir ; To copy a file
cp source_file . ; To copy a file to current directory (“.”means cur-
rent dir)
cp -f source_file destination_dir ; To copy forcefully a regular file
cp -R source_file destination_dir ; To copy recursive a directory.
• mv source destination:-
move command, like cut+paste
use:
mv f1 f2 ; rename f1 by f2
mv -rf ; recursive and force moving of a directory
• rm:-
remove file/directory, like delete
use:
rm -rf ; remove recursive and force
! One of the dangerous commands for root, use carefully!!!
rm *.txt ; Will remove all the file having extension .txt in PWD
• cat:-
stands for concatenate
use:
cat file_name ; Display a contain of a file in CLI
cat text1 > text2 ; redirection of text, overwrite
cat text1 >> text2 ; appending the text
• which:-
Path of the command
use:
which virtuoso ; Display the path of the executable file for virtuoso
which vi ; Will show the vi command path
which python ; Will show the installation path of the python program
• find:-
searching a file/directory
use:
find / -name “dir_name” ; to find a file/dir
find /home/user_name -name “file_name” ; to find a file/dir only in user’s home area
man find ; to get more details on find command
• history:-
Get the list of executed commands
use:
history ; the history of all command
history n ;list of last n command executed
history -c ; clear all the history
~/.bash_history ; location of stored command history
• chmod:-
Change mode, change the permission of file/directory
use:
ls -l file_name ; To see the current permissions of the file/dir
• touch:-
create a new file
use:
touch file1 ; create an empty file
touch file1 file2 file3 ; create multiple files in one command
touch –am file2 ; change access and modification time
• Gedit:-
A GUI based Linux text editor
use:
gedit & ; open gedit text editor and release the CLI
gedit file1 ; create/open a file in geditor
• head:-
To read the first 10 lines of a file in CLI
use:
head file_name ; To read the first 10 lines of a file
head –n 8 file_name ; To read first 8 lines of a file OR head -8 file
head -4 *.log ; Read first 4 lines of all log files in PWD
• tail:-
To read the last 10 lines in the command line
use:
tail file_name ; To read last 10 lines of a file
tail –n 12 file_name ; To read last 12 lines of a file OR tail -2 file
• sort:-
To sort the list
use:
sort file_name ; sort the content of file
sort –n file_name ; sorting a file which has numbers
sort –r file_name ; sorting the file in reverse order
sort –o outputfile inputfile ; redirection of sorted output
sort –n -k2 file_name ; sorting the file on basis of the nth column
• unique:-
An utility for filtering the repeated lines in a file
use:
unique file_name ; will display only unique lines
unique –c file_name ; will tell no. of times a line has repeated
• more:-
Display text one screen at a time
use:
more file_name ; display the text in command line
more -10 file_name ; will display 10 lines at a time
• less:-
to read the text file in the command line
use:
less file_name ; To view the content of a file
less -N file_name ; Will show the content with line number
• diff or vimdiff:-
find the difference between two files/dir
use:
diff file1 file2 ; To check the difference between two files
diff dir1 dir2 ; To check the difference between contains of two dir
• top or htop:-
It will show the status of various resources and tasks
use:
top ; you can see the utilization statics for resources and get PID of all running process
htop ; Similar to the top command but an improved version.
• ps:-
Known as Process Status
use:
ps ; process for the current shell
ps -e ; Display all active process
ps -ef ; Display all active process in full format
• kill:-
To terminate a process
use:
kill PID ; Killing a process by PID, PID is a numeric value.
kill PID1 PID2 PID3 ; Kill multiple processes together. You can specify the signal name in
between Kill and PID. If no signal has
been specified,
by default TERM signal will be sent.
• who:-
Display the users who are currently logged in your Linux machine
use:-
who ; Without any argument who command will display user’s
login name, terminal, login time and host
who –q ;Display the name of all users and total no. of users logged in
• w:-
information about current logged user and what they are doing
• users:-
Display the all current users name in a single line
• last:-
it display the list of user who logged the system
use:
last ; If no options provided the last command displays a list
of all users logged in (and out) since /var/log/wtmp file was created
last user_name ;Will display the activities of a particular user only
• free:-
Used to check available physical memory and swap memory
use:
free ; Command used to check used and free memory space in KB
free –m/g ;Space will be shown in MB or GB
free -s 5 ; Will update the status in every 5 seconds.
• lshw:-
Used to check hardware information
use:
lshw ; Generates detail reports about various hardware of system
lshw –class memory ;Details memory in the system
lshw –class processor ; Details of processor in the system
lshw –short –class disk ; Details about the hard drives (network)
• lscpu:-
Display information about CPU architecture
Use:
lscpu ; Give the detailed information about the CPU
• cat /proc/cpuinfo:-
Similar information like lscpu
• uptime:-
Gives the time how long system is running
use:
uptime -p ; Gives the duration of the system running
• reboot:-
Will shutdown and restart the machine instantly
• shutdown:-
Can be used to shut down or restart the machine
use:
shutdown –h now ; System will be shut down instantly
shutdown –h +5 “message” ; System will be shut down
after 5 minute
shutdown –r +5 ; System will be restart after 5 minutes
• date:-
Will show the current date, time and of time zone
use:
date ; Will show day, date, current time and timezone
date –d “1990-12-31” ; Details of any specific date
timedatectl ; Will show details of local and universal
time and timezone
timedatectl set-time ‘2018-12-27 07:30:10’ ; to set specific
date and time
timedatectl set-time ‘Asia/Kolkata’ ; Setting time by time zone
• cal:-
Will display the calendar of current month in terminal
use:
cal ; Will show calendar of current month in terminal
cal 08 1947 ; To display a calendar of particular month and year
cal –y 2019 ; Will show calendar of all month of a particular year
• env:-
Used to print all the current environment variables and it’s value
• whoami:-
prints the username of the current user
• uname:-
It provides kernel versions and other details
use:
uname ; Without any option, will print kernel name only
uname -a ; Get all the information like, kernel name,
version, architecture, host name, current date and time.
• hostname:-
To know the hostname
• echo $BASH_VERSION:-
To know the BASH version. For
more variables value run env command
Grep commands
• grep cmd : "global regular expression print"
• grep cmd search for a particular string/keyword from a file and print lines
matching a pattern.
• it check line by line and print lines matching given pattern.
• we can grep cmd anywhere like with files, searching for file, directories
ect...
• grep cmd syntax: grep [option].. pattern [file]..
• -grep Siva s1.rpt
• grep -i "keyword" file (to ignore upper and lower case while searching)
• grep -iv "keyword" file (to search everything except given patern/keyword)
• grep -c "keyword" file (to print how many times (count) given keyword present
• grep -w "keyword" file (to search for exact match of given keyword in a
file) (mahi, mahi, mahi, mahi)
• grep -n "keyword" file (to print the line no. of matches of given keyword in
a file) (8.mahi, 14.mahi, 15.mahi, 16.mahi)
• grep -o "keyword" file (to display only the matching pattern) (mahi, mahi,
mahi, mahi)
• grep "keyword" file1 file2 (to search a given keyword in multiple files)
(s1:mahi, s1:mahi, s1:mahi, s2:mahi, s2:mahi, s2:mahi)
• grep -h "keyword" file1 file2 (to suppress file names while search a given
keyword in multiple files) (mahi, mahi, mahi, mahi based on repated times)
• grep -e "keyword1" -e "keyword2" file (to search multiple keywords in a file)
(Mahi, Raja, Mahi, Mahi, Raja, Raja, Raja)
• grep -l "keyword" file1 file2 (to only print file names which matches given
keyword) (s1, s2 only we will get file names)
• grep "^keyword" file (to print the matching line which start with given keyword)
(Malli, Mahi, Mallika, Madhu, Madhu it will show the matching words in that file)
• grep "keyword$" file (to print the matching line which end with given keyword)
(MallI, MahI, it will show the last matching words in that file)
• grep -q "keyword" file (if you just wanna search but don't want to print on
terminal)
• to see the output ->echo $?
(grep -q madhu s1 it will execute but it won't show to check that
we use echo $?)