Unix Basic Commands

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

UNIX Hand Notes by Amarsoftech

wc -l: To find the number of lines

wc -w: To find the number of words

wc -c: To find the number of characters

more -n: The content of the complete file is displayed

ls: listing

ls -l: long listing

ls -a: hidden files will be displayed

ls -r: this gives the reverse order

ls -t: time when the file was created

ls -tr: time based + reverse order

ls -lart: long listing + hidden files + reverse order + time based

Head: Top to bottom

Tail: Bottom to top

Ps: list of processes

Ps tree: list of process running since long time and memory usage.

Kill: to kill a process/terminates the process

Kill -9 1286 (1286 is the file we want to kill)

Cmp: compares word by word

Diff: compares line by line

m -ls-l: memory size of file

cd: change directory

$ touch command: to create a empty file

.done: to create a 0 byte file


Chmod 777 filename: to give permissions to group, users and others

777-All Permissions

7-Group, 7-Users, 7-Others

1-Execute

2-Write

3-Execute/Write

4-Read

5-Read/Execute

6-Read/Write

7-Read/Write/Execute

Pwd: Present Working Directory

Whoami: to know which user am i

Awk command ---this for awake

CAT command:

CAT > filename: we can enter the values into the file

CAT >> filename: values entered into the file can be edited (only at the end of the
file)

CAT filename: we can view the file

Vi editor: Using vi editor also we can edit the values (here we can edit anywhere –
Beginning, Middle or end of the file)

Vi filename: to create a file

i – to go into insert mode

w - save the data

q – quit from existing mode

:wq! – save and quit


!q; - exit without saving data

Cut command -- It is a search option for COLUMN’S

Cut -f --- columns

Cut -c --- characters

Cut command for selecting Columns/Fields ($cut –f ‘number of columns we want’


filename)

$ cut -f n filename (in place of n you need to mention the number of the column
you want)

Example : $ cut –f 2-5 filename ---- we will get 2,3,4,5 columns

Cut command for selecting Characters (cut –c ‘number of characters we want’


filename)

Unix Cut Command Example


Lets consider the below as an example

> cat file.txt

unix or linux os

is unix good os

is linux good os

1. Cut command to print characters by position?

The cut command can be used to print characters in a line by specifying the
position of the characters. To print the characters in a line, use the -c option in
cut command
OUTPUT:
cut -c4 file.txt

If we give 4,6 we will get the below result

cut -c4,6 file.txt

xo

ui

ln

This command prints the fourth and sixth character in each line.

tr --- translator

tr ‘0’ ‘9’ <filename ----9 will be replaced in place of 0

Note: 0 is old value, 9 is new value

tr ‘a-z’ ‘A-Z’ <filename --- small letters will be replaced into CAPITAL LETTERS

tr -d ‘0-9’ <filename ----0 to 9 numbers gets deleted

tr -d ‘0-9’,‘a-z’ <filename ----particular relevant numbers and alphabets gets


deleted

SED Command---It is a search option for ROWS (Sed -n ‘parameter number’


filename)
SED -n ‘25p’ filename this gives the 25th row (Here p is the parameter)

SED -n ‘11p – 19p’ filename this gives the rows from 11 to 19 (Here p is the
parameter)

GREP Command --It is a search option for WORDS (grep -n ‘word’ filename)

grep-n: this shows the number of times a particular word is present in a


paragraph or a page

Example: grep -n ‘word we want to search’ filename

Grep –ni (Here i ignores case sensitive)

Example : If we want to search the amount 50k?

If there is 50k (with a small letter k)

AND

If there is 50K (with a capital letter K)

In this case if you mention i it ignores case sensitive and gives all the 50k values (it
will have both 50k and 50K).

Grep Command (WITHOUT USING ni)

Grep ‘is’ filename – we will get all the records which has the word ‘is’ from that
particular file

Grep ‘rahul’ * ----- we will get all the records which has rahul from all the files.

Grep -l ----we will get all the filenames

Cal | (pipe symbol) tee filename ----Here it gives the result and copies the data
to another file.
Points to Remember

GREP  WORDS (-n)

SED  SENTENCES (-n)

CUT  COLUMNS (-f) f is for columns (-c) c is for characters

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy