[go: up one dir, main page]

0% found this document useful (0 votes)
2 views8 pages

How to perform command

The document provides a comprehensive overview of various Linux commands and their functionalities, including file searching, text processing, and system monitoring commands. It covers commands like find, grep, cut, sort, and more, detailing their options and usage examples. Additionally, it includes sections on mathematical calculations, communication commands, and process management in Linux.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views8 pages

How to perform command

The document provides a comprehensive overview of various Linux commands and their functionalities, including file searching, text processing, and system monitoring commands. It covers commands like find, grep, cut, sort, and more, detailing their options and usage examples. Additionally, it includes sections on mathematical calculations, communication commands, and process management in Linux.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

1)Find command:-

find . -name a.txt

#Find Read-Only Files


find / -perm /u=r

find sss -name c.txt

find -type d -name sss

find ~ -name "a.txt"

#Find all Empty Directories


find /tmp -type d -empty

#. File all Hidden Files


find /tmp -type f -name ".*"

find / -size 50M

2)pg Command:-

pg a.txt

#clear screen
pg -c a.txt

#do not display "EOF"


pg -e a.txt

3)more command :-

#overlaping and clearing window not scrolling


more -c a.txt

# display "Press space to continue "q" to quit


more -d a.txt

cat a.txt | more


ls | more

4)less command:-(allow scrolling)


Ctrl + f : forwards one window
Ctrl + d : forwards half window
Ctrl + b : backwards one window
Ctrl + u : backwards half window
j : forward by one line
k : backward by one line

less a.txt

5)head command:-

head -5 a.txt

6)tail command:-
tail -5 a.txt
7)wc command :-
wc -l a.txt
wc -c a.txt
wc -w a.txt

8)touch command
-a:-This option changes the access time only
-m:-This option changes the modification time only.
-r:-Uses the access and modification times from the reference file.

touch a
touch b
stat a
touch -m a b
stat a

touch -r a.txt b.txt


touch m.txt a.txt -m
#set the time of m replace a

touch -c -d "16 sep" doc2


#This is used to update access[-c] and modification[-d: date string] time
touch -d "2 hours ago" filename
touch test{1..10}

=)regular expression searching command


1)grep command:-(global regular expression print)

grep "m" a.txt


grep "M" a.txt
grep -i "M" a.txt #case insensitive
grep -c "M" a.txt #line count
grep -n "M" a.txt #line number
grep -w "MM" a.txt # word

grep -f a.txt b.txt #mathching of two file


grep -L "unix" * #file names that matches & pattern

2)fgrep command:-fixed-character strings in a file


fgrep "mm" a.txt
fgrep -c "m" a.txt #line number
fgrep "m" *.txt
fgrep -l "@a" a.txt #print filename
fgrep -n "@a" a.txt #print line number
fgrep -x "a" a.txt #display only lines matched entirely.

3)egrep command:-
egrep "mital" * #globally search
egrep "m" a.txt
egrep -c "mm" a.txt #linenumber mathched
egrep -l "mm" a.txt # print filename
egrep -n "mm" a.txt # print linenumber
egrep -r "m*" m.txt
egrep -r "m*" . #recursively searching whole root
=>working with columns and fields
1)cut:-
cat > stat.txt
Andhra Pradesh
Arunachal Pradesh
Assam
Bihar
Chhattisgarh
ctrl+z

cut -b 1,2,3 stat.txt


cut -b -3 stat.txt
cut -c 2,3 stat.txt

cat > b.txt


01234:567;89
abcd:drg;ij
ctrl+z

cut -d ";" -f1 b.txt //-f column name


cut -d ":" -f2 b.txt
who | cut -c 1-2

2)paste:-
paste a.txt b.txt
paste -d "%" a.txt b.txt
paste -d "1," a.txt b.txt c.txt
cat stat.txt | paste

3)join:-
cat > a.txt
1 aaa
2 vvv
^Z
cat > b.txt
1 xxx
2 ccc
^Z
join a.txt b.txt
join a.txt b.txt > l.txt

=>
1)sort command:-
sort -r a.txt #reverse
sort -n a.txt #numerical character
sort -u a.txt # duplicate remove display
sort -c a.txt #if already sorted no output
sort -k2 a.txt #particular column
sort -m a.txt # sort monthwise

2)unique command:-
cat > music
i love music
i love music
i love music

3)uniq music
uniq -u music #unique line
uniq -d music #duplicate line
uniq -c music # count

#redirection and piping


ls - l >hello #output(stdout)
cat >> out.txt #append data
cat >> out.txt < l.txt # input data (stdin)
cat file.txt | grep "mm" a.txt
cat m.txt | more

#comparing file
cat > a
This is a Line1
^z
cat > b
This is a Line2
^z

1)cmp:-
cmp a b #byte

2)comm:-'comm' command is used to compare two files or streams. By default, it


displays three columns, first displays non-matching items of the first file, second
indicates the non-matching item of the second file, and the third column displays
the matching items of both files.

comm a b #linebyline

3)diff:-
diff a b # >line < line

=>changing information to file


1)tr[translate)

cat file | tr [a-z] [A-Z]


at b.txt | tr 'hello' 'HELLo'
cat file | tr [:lower:] [:upper:]
echo "Welcome To Geetanjali" | tr [:space:] "\t"
tr -d W <<< "Welcome to Geetanjali" #remove "W"
echo "my ID is 73535" | tr -d [:digit:] #remove digit
echo "my ID is 73535" | tr -cd [:digit:] #complete digit
echo "hello world" | tr -d ' '
echo -e "hello\nworld" | tr -d '\n'

2)sed (stream editor programme)

cat > a.txt


unix is great os. unix is opensource. unix is free os.
learn operating system.
unix linux which one you choose.
unix is easy to learn.unix is a multiuser os.Learn unix .unix is a powerful.
^z

sed 's/unix/linux/' a.txt


sed 's/unix/linux/2' a.txt #change 2 line
sed 's/unix/linux/g' a.txt #globally replacement

3)od:-
od -b a.txt #convert file in octal format
od -c a.txt #convert character format

MATHEMATICAL CALCULATION

BC command:-

x=10
y=20
echo $x+$y | bc

factor command:-

factor 10

MONITORING INPUT OUTPUT

tee command:-
cat > a
1
2
3
cat >b
4
5
6
wc -l a |tee -a b

who | tee a.txt # content remove and data


who | tee -a a.txt #add existing file

script command:-(record all the terminal activities)


script a
date
time
cal
exit
cat a

DATE & TIME RELATED COMMAND

cal
cal 2022

date +“%A” #display weekday


display date in mm/dd/yy
date +“%D”

COMMUNICATION COMMAND

wall l.txt #write a message to all users

wall Submit Your UNIX Assignment Tomorrow.


wall -h #help

#The write command in Linux creates a communication line between two logged-in
users through the terminal.

w
write stud #send message on users

mail -s "hello world" some@gmail.com

finger mital #show information of users


finger -s mital

mesg #control write access to your terminal


mesg [y/n]

#The ping command sends an echo request to a host available on the network.
ping www.google.com
ping 216.58.203.4
ping localhost

PROCESS RELATED COMMANDS


ps #display about active process
ps -f #full display
ps -u mital #specific user

nice:nice -n <nice_value> <command>


-n:Set the nice value for a new process.
-p:Modify the nice value for a process using its PID.

nice #set the priority of the process

ps -l #check value ni column


nice -10 gnome-terminal
ex:
ps -el | grep terminal
renice -n 15 -p 3088
ps -el | grep terminal

kill #located in (/bin/kill)


kill -l #to display all available signal
kill 1024

at 12:15 #to schedules a command to be run once at a particular time.


at tuesday +2 hours

crontab -l #view logged in current user enteries in crontab

sleep 10s
sleep 1m

S= for second (the default)


m=for minutes.
h= for hours.
d= for days.
EXAMPLE:

Create file ‘test.sh’ and run with `sh`

echo “display Message After 10Second”


sleep 10
echo “Welcome”

wait:-
1. The ampersand sign (&) after a command indicates a background job.

2. $! fetches the PID of the last background process. Store the previous PID in a
variable when working with multiple background processes.

3. $? prints the exit status of the last process.


wait <pid>
sleep 10 &
echo $!
echo $?

ex:-
$sleep 10 &
$jobs -l
$wait
#After 10 seconds (due to sleep 10), the console prints a Done message.

top #active linux Processes.

You might also like