0% found this document useful (0 votes)
24 views24 pages

Linux Notes 1

The document provides a comprehensive overview of various Linux commands, including file manipulation commands like cat, cp, mv, and rm, as well as directory commands such as mkdir, cd, and rmdir. It also covers miscellaneous commands, filter commands like grep and sort, and file comparison commands like cmp and diff. Additionally, it discusses Unix file access permissions using chmod.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views24 pages

Linux Notes 1

The document provides a comprehensive overview of various Linux commands, including file manipulation commands like cat, cp, mv, and rm, as well as directory commands such as mkdir, cd, and rmdir. It also covers miscellaneous commands, filter commands like grep and sort, and file comparison commands like cmp and diff. Additionally, it discusses Unix file access permissions using chmod.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LINUX

COMMANDS

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
File Commands

1) cat 2) cp
3) mv
4) rm

cat command:

1) Creating the new file


2) Display content of the file
3) Concatenating more than one file 4) Appending data to the existing file 5) Copying many
files in to one single file.

Ex:

1) Creating the new file:

$cat >[Link]
--------
-------- --------
ctrl+d

2) Dispay data in the file:

$cat < [Link] or


$cat [Link]

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
3) Concatenation of files:

$cat [Link] [Link]

4) Copying data from many file to single file:

$cat [Link] [Link] >[Link] ls : Used for listing /display all the
files in the curreny directory.

cp command:

1) copy contents from a file to another file(source->destination) 2)copy files


from one directory to another directory.

Example:
$ cp [Link] [Link]
mv command:

1) Used for renaming a file(changing name of the file)


2) Renaming a directory
3) Moves files from one directory to another directory

Example:
$mv [Link] [Link] --> renaming a file
$mv chennai hyd --> renaming a directory
$mv [Link] hyd -->here the file google moves to hyd
directory

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
** Note: If we use cp command duplicate files will be crated
**If we use mv command file will be moved to target location(no duplicates)

rm command: used for delete/removing a file/directory.

Example:

$ rm [Link] --> it deletes file directly without


confirmation
$ rm -i [Link] -->deletes file with confirmation $rm -r
hyd

** Here this commands removes hyd directory even thou its having sub directories & files.
* But rmdir command removes directory when it should be empty. * -r is
recursive

Unix directory commands

1. Mkdir
2. cd
3. rmdir

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
mkdir: Creating a directory which has set of files & sub directories.

Example:

$mkdir hyd
$mkdir chennai

cd: Used for changing/closing directory

Example:

$cd chennai
$chennai>

If we want to come back to my previous directory we can use like

$chennai>cd ..
$ cd --> come back to root directory

If we want to come back more than one directory then

$chennai>places>cd ../.. --> this command is back to 2


directories

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
rmdir: Used for removes/deletes directory only if is empty.

Example:

$rmdir chennai

Unix Miscellaneous commands


• ls
• pwd
• ln
• head
• tail
• cal
• ps
• kill
• who
• whoami
• uptime
• ut

ls : This command displays files and directories in columnar format.

Example:
$ ls
$ ls -S

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Arrange the files based on the size(S is upper letter)
$ ls -l

long listing the files $ ls -


a

Displays hidden files


$ ls -i

Displays inodes for each file


$ ls -R

Displays all directories along with subdirectories in current working directory.


creating a hidden file:
$ cat >.[Link]

Wild card characters using with ls command.

? Represents single character


* Represents gruop of characters
[ ] Represents searching pattern

Examples:
$ ls ? Displays files with one letter
$ ls x* Displays files which are starting with 'x'
$ ls ??? Displays files with 3 letters

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
$ ls *.out Displays all the files with extension 'out'
$ ls [a-z] Displays single character files which are from a to z
$ ls [a-z]* Displays files starting with a to z
$ rm ? Removes the files with single character
$ rm *.c Removes the files with extension 'c'
$ cp ? chennai Single digit files will be copied into directory 'chennai'

pwd : This command shows current working directory in unix


$ pwd

head : Used to display First lines of the file

Example:
$ head [Link]
This command displays default 10 lines of the file [Link]
$ head -n15 [Link]
This command displays 15 lines of the file [Link]
$ head -n3 [Link]
This command displays 3 lines of the file [Link] tail :
Used to display last lines of the file. Ex:
$ tail [Link]
This command displays default last 9 lines.
$ tail -n5 [Link]
This command displays last 4 lines of the file.
$ tail -n15 [Link]
This command displays last 14 lines of the file.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
cal command: Used for display the calender.

Ex:
$ cal 2011 Displays 2011 calender
$ cal 2 2011 Displays Feb month in 2011 year

ln :
[Link] will create link between 2 files.(2nd file should new one) 2. If
one file modified another one affected. Ex:
$ln [Link] [Link]

ps : Knowing backgroud process running /stopped


$ ps pid

kill : Used for terminating the process Ex:


$ kill pid

who : Used for to display who are working in the system Ex:
$ who

whoami: Display my user name/accout


Ex:
$ whoami
uptime: This command used for display load in the server.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Unix Filter Commands
1) grep
2) sort
3) more
4) cut
5) wc
6) uniq

1) grep: (Global Regular Expression Pattern)

This command is used for searching a required patern in a file.

Syntax:
$ grep [- optopn] "search patern" Filename [redirection symbol newfilename]

Options:

-i Ignores case sensitiveness in searching patern


-n displays line numbers for those lines which gets matched and un matched with the
patern
-c counts number of times a searching patern exists and does not exists
-v (verbose) Displays those lines that does not match with the patern

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Example:

$ cat > [Link] welcome


to unix paypal welcomes you
unix multi user os
WELCOME to the world of unix

$ grep "welcome" [Link]


$ grep -i "welcome" [Link]
$ grep -i -n "welcome" [Link]
$ grep -i -c "welcome" [Link]
$ grep -i -v "welcome" [Link]
$ grep -i -v -n "welcome" [Link] > [Link]

Sort : Used to arrange numbers/text in ascending/descending order.

* by default it arranges ascending order.

Syntax:

$ sort [-option] [redirection synbol ] filename


[redirection synbol] [new filename]

options:

-r Arrage data in reverse or descending order


-n Arrage data in ascending or descending order by considering whole number.
* if n is not used then numbers gets arranged in order based on 1st digit.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Ex1:

$ sort > [Link]


6
2
9
1
5
3

$ cat [Link] Ascending order


$ sort -r [Link] > [Link]  Descending order $cat
[Link]

Ex2:

$ sort >[Link]
176
2165
8
93
-----
------ [ctrl+d]

$cat [Link] It considered first digit $sort -n


[Link] > [Link] It considered whole number.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
more: This filter command used to display information from multiple files based n page
wise.

It gives an identification of end of file for first file and begining of next file.

Syn:

$more [-option] file1,file2,file3, etc...

options:

-p clears the screen and displays next file in the list of files

*note:

Enterkey retrives next file based on %s spacebar


retrieves complete data from next file

Ex: $more - p [Link] [Link]

cut: Used to cut the required text from a [Link] can cut the data on the columns and feilds.

Syntax:

$ cut [-option] filename [redirection symbol new filename]

-c To cut the data in columns

-f To cut the data in feilds that is that data which is separated by tab.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Ex1:

$ cat>[Link]
Hyderabad
Secunderabad
Andhra [ctrl+d]

$ cut -c1 [Link] [Enter]


H
S
A

$cut -c3 [Link] [Enter]


d c d

$cut -c1 -3 [Link] [Enter]

Hyd
Sec
And
Ex2:

$cat > [Link] [Enter]


India Delhi
Andhra Hyderabad
Peers Net
[ctrl+d]

$ cut -f1 [Link] [Enter]


India

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Andhra
Peers

$ cut -f2 [Link] [Enter]

Delhi
Hyderabad
Net

wc: It will count number of lines,worlds,characters in a file.

Syntax:

$ wc [-option] filename

options:

-l count number of lines


-w count number of words
-c count number of characters

Ex:

$ wc -l [Link]
$ wc -w [Link]
$ wc -c [Link]

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
uniq: This filter is used to get the uniq or duplicate lines from a [Link] should be in order.

Syntax: $ unix [-option] filename

options:

-d Display duplicate lines


-u Display uniq lines
-c Counts number of times each word has occured in a file

Ex:

$ cat > [Link]


ameerpet ameerpet
peers bhel hyderabad
ameerpet
peers
secunderabad [ctrl+d]

$ sort [Link]> [Link]

$cat [Link] Ascending order of data displaying

$ uniq -u [Link]

$ uniq -d [Link]

$ uniq -c [Link]

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Unix File compare commands

1. cmp
2. diff
[Link]

cmp: It comapares 2 [Link] files are same it returns promp or else it returns the message
where the difference encountered.

Syn: $ cmp file1 file2

Ex: $ cmp [Link] [Link]

diff: This command compares 2files like [Link] any difference found in 2 files it displays
those lines.

Ex:

$ diff [Link] [Link]

comm : Used to compare 2 sorted [Link] provides out put in 3 columns.

* In first column displays uniq lines of first file.


* In second column displays uniq lines of second file * In third column
displays common lines in 2 files.

Ex:-

Step1 : Create two files with some data

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
$ cat> [Link] risk
payments ebay uv
norkom

$ cat> [Link]
foodball cricket crems
ebay payments

Step2: Sort above files and store the data into another 2 different files

$ sort [Link] [Link] [Enter]

$ sort [Link] [Link] [Enter]

Step3: Use comm command

$ comm [Link] [Link] [Enter]

** output shows in 3 different columns.

Unix File Access Permissions – Chmod

chmod: It provides permissions over a file in 3 categories.

1) owners
2) groups
3) others

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Permissions which can be granted are read,write and execute

1) read (r)
2) write (w)
3) execute (e)

These permissions are represented with numeric values

r- 4w- 2e-
1 -----------
7
-----------

Owners are users whose files gets referred from their respective accounts.
Groups are users whose accounts are dependent on the other accounts. Others are
users who can access the files of other users.

Chmod command is used to change the permissions for a file or directory.

Syntax:

$ chmod FAP Filename

* FAP is file access permissions

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Examples:

$ chmod ooo [Link]

No permissions to owners,groups and others

$ chmod 777 [Link]

All permissions to owners,groups and others

$ chmod 444 [Link]

Read permission to owners,groups and others (4 - read)

$ chmod 600 [Link]

Read(4),write(2) permissions to owners, no permissions to groups and others

$ chmod 664 [Link]

Read,write permissions to owners,groups and read permission to others

$ chmode 111 [Link]

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Execute permission to owners,groups and others

Change permissions using name of the permission:

Examples:

$ chmod u-w g-w o-r [Link]

* write permission cancelled from owner


* write permission cancelled from groups
* read permission cancelled from others

$ chmod u+rwx g+rwx o+r [Link]

* read,write,execute permissions added to owners


* read,write,execute permissions added to groups
* read permission added to others

** Note: + used for giving permissions.

- is used for removing permissions.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Interview FAQ’S on Unix Commands

1) How to find hidden files in current directory?

$ ls -lrta

2) How to find current running processes in unix server?

$ ps -ef

and if we want to find specific process we can use 'grep' with pipe $ ps -ef |
grep -i 'application'

3) How to find process which is taking maximum memory in server?


$ top
top command tell us about cpu usage , process id and other details. below is output of top command

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
4) How to find Exception in log files available in current directory and how to find number of
occurrence?

$ grep 'Exception' [Link] | wc -l

5) find all files in current and subdirectories which contains 'log' name?

$ find . -name 'log'

6) How do you access command line arguments from within a shell script?

Arguments passed from the command line to a shell script can be accessed within the shell script by using a
$ (dollar sign) immediately followed with the argument's numeric position on the command line.

7) How to tails last 200 lines of any log fine?

$ tail -200f [Link]

8) How to find remaining disk space in unix\linux server?

$ df -kl
df -kl
Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on

/dev/disk0s2 244277768 153679844 90341924 63% 38483959 22585481 63% /

9) How to make any script file executable?


$chmod 755 *.sh

10) How to kill process in unix server?


$ kill -9 #pid
these #pid can be found using ps -ef command.

Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra
Email:-info@[Link] [Link]
+91 77570 62955 | +91 78229 17585 Sai Luxuria , Office No 15 & 16 , 3rd Floor,Wakad , Pune, Maharashtra

You might also like