Linux Commands
Session 2
Prepared by DR
Command: date
⚫ To know the current date and time on linux
operating system, we use “date” command
Syntax:
date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
date +'%A %d-%m-%y’ date -d now
date +'%b %d-%m-%y' date -d yesterday
date +'%B %d-%m-%y' date -d tomorrow
date +'%c %d-%m-%y' date -d "next monday"
date +'%C %d-%m-%y' date -d "last monday"
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 2
Command: Find
⚫ The find command helps us to find a
particular file within a directory.
⚫ It is used to find the list of files for the
various conditions like permission, user
ownership, modification, date/time, size,
and more
Syntax: Find [OPTION]
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 3
Command: Find
find <location> <comparison-criteria> <search-term>
Options:
-name pattern: It checks that the file name is the same as the given shell-glob pattern or
not.
-type type: It checks that the file is a provided type.
-print: It always gives the true value. It prints the current file name and a newline to
stdout.
-exec program [argument ...];: It always gives the true value. It executes a program
with the fixed given arguments and the current file path.
-ok program [argument ...];: It is the same as -exec, but will return false or true if the
program gives 0.
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 4
Command: Find
⚫ find . -name "*.txt"
⚫ find . -type d -name "*.bak“
⚫ find . -newer msg.txt
⚫ find . -name Demo.txt -delete
⚫ find . type -depth -name Newdirectory
⚫ find ./Newdirectory -mtime -1
⚫ find ./Newdirectory -type f -name "*.txt" -exec grep 'demo' {} \;
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 5
Command: Locate
The locate command and find command is used to search a file by
name.
But, the difference between both commands is that locate command is
a background process and searches the file in the database whereas,
find command searches in the filesystem.
Syntax: locate [OPTION]... PATTERN...
e.g. locate <filename>
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 6
Command: Locate
The locate command and find command is used to search a file by
name.
But, the difference between both commands is that locate command is
a background process and searches the file in the database whereas,
find command searches in the filesystem.
Syntax: locate [OPTION]... PATTERN...
e.g. locate <filename>
locate httpd.conf
locate *.txt
locate –n 5 *.txt
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 7
Command: Locate
The locate command and find command is used to search a file by name.
But, the difference between both commands is that locate command is a
background process and searches the file in the database whereas, find
command searches in the filesystem.
By default, it may not available, if not present, we need to install “mlocate” and
then updated needs to use
Syntax: locate [OPTION]... PATTERN...
e.g. locate <filename>
locate httpd.conf
locate *.txt
locate –n 5 *.txt
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 8
Command: cal
⚫ The 'cal' term stands for calender. It displays current month's calender with
current day highlighted.
Syntax: cal
cal <month> <year>
Cal July 2028
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 9
Command: sleep
Linux sleep command lets the terminal wait by the specified amount
of time. By default, it takes time in seconds.
We can set the delay time in minutes (m), hours (h), and days (d). It
helps in pausing the execution of any particular command for a fixed
amount of time.
sleep NUMBER[SUFFIX]...
sleep 5 => The above command will pause the terminal for 5 seconds.
sleep 0.05m
sleep 0.002h
Sleep 0.0005d
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 10
Command: time
time command displays how long it takes to execute a command
Syntax: time [option] [command]
-o FILE: It is used to specify the resource and uses statistics to a FILE instead of the standard error
stream
-a, --append: It is used to attach resources so that information can be used instead of overwriting it in
the output file. This option is useful with the '-o' option.
-f FORMAT: It is used to use the FORMAT as the format string that controls the output of time.
--help: It is used to display the help documentation that contains the summary of the supported options
and usages.
-p, --portability: It is used to use the following options to conform to POSIX standard 1003.2:
real %e
user %U
sys %S
-v: It is used to display the output verbosely.
--quiet: It is used for not reporting the status of the program even if it is different from zero.
-V: It is used to display the version information of the installed time command.
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 11
Command sort
sort – this command read input from STDIN (the
keyboard) and produces an alphabetically or
numerically sort list
Syntax:
cat list1 list2 > biglist
sort < biglist
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 12
$who [options] [filename]
Command who
who – The who command is used to get information about currently logged in user
on to system.
Options:
⚫ Time of last system boot
⚫ Current run level of the system
⚫ List of logged in users and more.
Syntax:
$who [options] [filename]
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 13
Command: ps
⚫ To view the processes that you’re running:
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 14
Command: top
⚫ To view the CPU usage of all processes:
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 15
Command: kill
⚫ To terminate a process use “kill”
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 16
Input/Output Redirection (“piping”)
⚫ Programs can output to other programs
⚫ Called “piping”
⚫ “program_a | program_b”
program_a’s output becomes program_b’s input
⚫ “program_a > file.txt”
program_a’s output is written to a file called “file.txt”
⚫ “program_a < input.txt”
program_a gets its input from a file called “input.txt”
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 17
A few examples of piping
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 18
A few examples of piping
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 19
Command: wc
⚫ To count the characters, words, and lines
in a file use “wc”
⚫ The first column in the output is lines, the
second is words, and the last is characters
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 20
A few examples of piping
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 21
Command: grep
⚫ To search files in a directory for a specific
string use “grep”
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 22
Command: diff
⚫ To compare to files for differences use
“diff”
Try: diff /dev/null hello.txt
/dev/null is a special address -- it is always
empty, and anything moved there is deleted
Linux Session - 1 Intothepro Techscapes (OPC) Pvt. Ltd. 23