0% found this document useful (0 votes)
9 views

UNIX Commands

This will give a detail view on UNIX Commands

Uploaded by

diekuj
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)
9 views

UNIX Commands

This will give a detail view on UNIX Commands

Uploaded by

diekuj
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/ 4

pwd

cd direct3

pwd

ls

touch file1.txt

cat>file1.txt
Hello, this is session is on unix
^C
cat file1.txt

cat>file1.txt
this example is on concatenation
^C

cat file1.txt

cat>>file1.txt
here the content will be appended instead of
overwriting^C

cat file1.txt

cp file1.txt f1_copy.txt
ls

cat f1_copy.txt

mv f1_copy.txt f1_move.txt

ls -n

ls -i

mv f1_move.txt f2_move.txt
================================================================================

filters

touch f1.txt

id|name|age|branch|fees|marks
101|rohith|22|cse|80000|89
102|yusuf|24|ece|56000|80
103|rohan|22|mech|60000|77
104|rehman|23|ce|56000|69
102|yusuf|24|ece|56000|80
103|rohan|22|mech|60000|77
104|rehman|23|ce|56000|69
----------------------------------
id name age branch fees marks
101 rohith 22 cse 80000 89
102 yusuf 24 ece 56000 80
103 rohan 22 mech 60000 77
104 rehman 23 ce 56000 69
102 yusuf 24 ece 56000 80
103 rohan 22 mech 60000 77
104 rehman 23 ce 56000 69

-------------------------
head
------------------------
character based

head -c 2 f1.txt

head -n 2 f1.txt

head f1.txt
------------------------------------------------------------------

tail
---------------------
tail -n 2 f1.txt

tail -c 2 f1.txt

tail f1.txt

---------------------------------------------------------------------------

uniq

no options prints non duplicates and a copy of duplicate lines

uniq f1.txt
-----------------------------------
duplicates
prints only duplicates

uniq -d f2.txt

--------------------
count frequency of occurences

uniq -c f2.txt

prints freq of lines at the start of line

------------------------------
print only unique lines

uniq -u f2.txt
===================================================================================

wc

------
wc f2.txt

prints lines |word count|char counts| filename


----------------------------

only lines and file name


wc -l f2.txt

same with
-c, = characters count
-w, = word count
-L =prints length

===================================================================================
=

sort
-------------

sort f1.txt
gives based on ascii or

sort based on column n

sort -k 2 -t"|" f1.txt

sort -m -t "|" f1.txt

======================================================================

grep

[] grep "grep" f3.txt

finds grep in f3

[] grep "grep" *

finds grep in all files in a directory

[] grep -i "grep" f3.txt


case insensitive

[] grep -w -i "grep" f3.txt


searches whole word -w
case insensitive is added along

[] count number of matches


grep -c -i "grep" f3.txt

[] to display only matched pattern


grep -o -i "grep" f3.txt

[] show line number


grep -n -i "grep" f3.txt

[] print lines that are not matching


grep -v -i "grep" f3.txt

[] check for strings starting with


grep -i "^gr" f3.txt

[] ending with string


grep -i "grep$" f3.txt
===================================================================================
======

sed

[] basic subsitution

sed 's/grep/Grep/' f3.txt

[0] subsitute all occureneces in second line


sed '7 s/unix/UNIX/g' f3.txt

[] change second occurences in each line


sed 's/unix/UNIX/g2' f3.txt

[] replace last occurence


sed '$s/unix/UNIX/g' f3.txt
===================================================================================
============

awk

[] print occurences of a word


awk '/unix/{print}' f3.txt

[] basic printing 1st column


awk 'BEGIN{FS="|";}
{
print $1;
}
END{
print "done";
}
' f1.txt

[] starting of a line
awk '/^[gG]rep/' f3.txt

You might also like