Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 78

Day No.

1---------

What is an OS

It is a program which controls hardware

(cpu, ram, hard disk, nic, keyboard, mouse, terminal)

What are the common OS in the market

UNIX (

WIndows (XP, 7, 8, )

2000, 2003, 2008, 2012

MacOS - Mac (Apple)

OS/400 (IBM) - AS/400

MainFrame (IBM)

Theory : UNIX History

AT & T, Bell Labs, C - 1967 - Dennis Riche

AIX (IBM),

Solaris (Sub)

HP-UX (HP)

IRIS (Silicon Graphics)

DEC (Digital)

Linux - x86 - Intel, AMD (open source)

Linux Distros (Red Hat, SuSe, CentOS, Fedora, Ubuntu)

Open Source

License, Subscription
How to logon to UNIX machine

Command : echo

echo "Hello world"

echo 'Hello world'

echo Hello world

echo Hello world

echo 'Hello wor

ld'

echo -e '\n\nHello\nWorld\n'

echo -e '\n\nHello\tWorld\n'

Command : clear

Command : alias

alias cls='clear'

alias

unalias cls

Note: alias will last only for a session

Shortcuts : ctrl + l

Command : whoami

Command : id

Display UID, GID of promary group and GIDs of all seconday groups

Command : date

date -s to set the time of the server - can be run as root


What is a UNIX date : 01-01-1970

date +%D

date +%Y

date +%m

date +%d

date +%d.%m.%Y

date +%d-%m-%Y

Command : cal

cal

cal 1960

cal 5 2014

Command : uname

uname

uname -r

uname -a

Note: architecture,64bit/32it,machinename,

Command : man

man date

man crontab

man 5 crontab

man -k keyword

Command : ifconfig

ifconfig

Note: ip addr, mac addr, netmask, name of ethernet card given by SA


Command : uptime

Command : who

Command : w

Note: JCPU, PCPU, IP Address, What

Command : users

Command : hostname

hostname -s

Command : history

history -c

export HISTSIZE=5000

Note: These commands are stored in a file named .bash_history

!20 <== execute 20th command from your history

ctrl + r <== search at the command prompt

Command : exit

Shortcuts : ctrl + d

Command : ping

ping yahho.com

ping -c2 192.168.0.254

Command : ssh

ssh shekhar@172.24.0.240

ssh -l shekhar 172.24.0.240

ssh -X shekhar@172.24.0.240 <== For opening graphical commands (firefox)

Command : last

Command : write

Command : wall
Shortcuts : ctrl + shift + n

Shortcuts : ctrl + shift + t

Shortcuts : ctrl + shift + +

Enlarge font

Shortcuts : ctrl + -

Reduce font

Shortcuts : up arrow

previous command

Shortcuts : down arrow

next command

Test : No 1

Q: Which command helps you clear the screen

Q: How do you find out who you are logged in as

Q: Display names of users who are currently logged in

Q: WHat commands have you recently executed

Q: What is the ip address of your server

Q: Write a command to print Hello World

Q: How would you send an instant message to all logged in users

Q: How would you send an instant message to a perticular logged in user

Q: What is a shortcut to open another tab

Q: What is a shortcut to open another window

Q: What is a shortcut to clear the screen

Q: Which command will log you out from your current session

Q: How do you connect to a remote UNIX machine


Q: What is the name of your operating system

Q: How do you find out if yahoo.com is reachable from you machine

Q: How to you exexute 39th command from your history

Q: How do you search a command with a specific key word from your history

Q: In which file all history commands are kept

Q: What is the current time on your system

Q: Display list of users who have logged on to your system since the last 4 days

Q: Which command displays the name of your machine/server

Q: What is the operating system kernel version

Q: Is your operating system 64 bit or 32 bit

Q: In which company UNIX was invented

Q: In which programming language UNIX is written

Q: Name 4 flavors of UNIX that are currently popular in the indian IT industry

Q: Who is the father of Linux

Q: Is Linux Free

Q: What is the meaning of open source. Does it mean its free.

Day No. 2

---------

Command : pwd

Command : cd
cd <== goes to your home dir

cd .. <== goes to your parent dir

cd . <== . mean current directory

cd ~ <= goes to your home dir

cd ~shekhar <= goes you shekhar's home directory

cd ~shekhar/bin <= goes to bin directory which is under shekhar's home dir

cd / <== go to the top most dir

cd - <== go to previous directory

Theory : Filesystem (Directory structure)

/bin

/etc

/home

/sbin

/root

/tmp

/usr/bin

Command : ls

ls -l <= long listing sorted from a-z

name

time on which the file/dir was last modified

size of a file/dir

group owner

owner/user

no of links
permissions ( owner, members of group owner, others)

file type (- file, d dir, l link, s socket, c char device, b block device)

devcices (mouse, keyboard, disks, disk partition, terminal/window, usb)

ls -a <== all - mean show hidden files (hidden file starts with a .)

ls -t <== list of files sorted by time

ls -r <== list of files sorted by i reverse order

ls -i <== Display inode number of each file

ls -l .

ls -l $HOME

ls -l ~

ls -l ..

ls -l ../..

ls -l ~oracle

ls -ld /home/shekhar <== display the info of the direcrory and not what is inside that directory

Theory : What is inode (index Node). It is structure. A table with info of a file

name, timestamps, owner, group owner, perm, size,

Symbol : ?

Symbol : *

Command : cat

cat /home/arununix/dir1/abhi.txt
cat abhi.txt

cat ./abhi.txt

cat -n abhi.txt

cat -n /etc/passwd

permissios:

r4

w2

x1

chmod u+x a.txt

chmod 751 a.txt

chmod 750 a.txt

chmod 755 a.txt

chmod -R 751 /home/shekhar


r w x

File cat,more,less vi run

Dir ls vi, rm cd

Command : su

su - arununix <== will ask you arununix's password

su - root <== will ask you root's password

su - <== will ask you root's password

passwd <== change your own password

passwd shekhar <== change shekhar's password (only root can change someone else's password)

Command : more

more /etc/passwd

space bar <== display next page

enter key <== display next line

Command : less

less /etc/passwd

space bar <== display next page

enter key <== display next line

/shekhar <== search the word 'shekhar' in the file

q <== exit from the file

Command : head
head /etc/passwd <== display top 10 lines of /etc/passwd file

head -6 /etc/passwd <== display top 6 lines of /etc/passwd file

Command : tail

tail /etc/passwd <== display last 10 lines of /etc/passwd file

tail -6 /etc/passwd <== display last 6 lines of /etc/passwd file

tail -f /etc/passwd <== display last few lines contineously

tail -n +2 /etc/passwd <== display all lines from bottom except the top two

Command : touch

Command : cp

cp /etc/passwd /home/shekhar/mypasswd

cp /etc/passwd ./mypasswd

cp /etc/passwd . <= . means pwd

cp /etc/passwd ./bin

cp /etc/passwd bin <== same as above because i im in my home dir

cp /etc/passwd /tmp

cp ../../etc/passwd .

cp /etc/passwd $HOME

cp /etc/*.conf $HOME

cp -i /etc/passwd /tmp

cp -r bin binbac

cp -r ./bin ~/binback

cp -r ./bin ~arununix

cp ~oracle/*.sh ~/bin
Theory : What is a shell script & how to execute it

Command : file

Command : set <== display values of user & system defined variables

Command : env <== display values of system defined variables

Command : stat

Command : wc

wc -l <== display total number of lines in a file

wc -w <== display total number of words in a file

wc -c <== display total number of characters in a file

Command : mv <== rename a file or to move a file ( cut paste)

mv a.txt b.txt

mv /home/shekahr/a.txt /home/shekhar/b.txt

mv $HOME/a.txt b.txt

mv ~/a.txt ~shekhar/b.txt

mv ./a.txt ./b.txt

mv a.txt /tmp

mv a.txt /tmp/b.txt

mv ~arununix/.bash_profile ~

mv ~oracle/*.sh ~/bin

mv /home/shekhar/bin /home/shekahr/binbak

mv /home/shekhar/bin/* /home/shekahr

Command : rm

rm a.txt
rm -i a.txt

rm -f a.txt

rm *.sh

rm $HOME/*.txt

rm ~oracle/*.sh

rm /tmp/*.tmp

rm -r ./bin <== remove bin directory

rm -r $HOME/bin <==remove bin directory

rm -r /home/shekhar/bin <== remove bin directory

rm -f /tmp/a.txt

rm -i /tmp/a.txt

Command : mkdir

mkdir /home/shekhar/newbin

mkdir ~/newbin

mkdir newbin

mkdir ./newbin

mkdir ~oracle/newbin

mkdir $HOME/newbin

mkdir /tmp/shekhar

Command : rmdir

rmdir /home/shekhar/bin <== remove dir if it is empty


du /etc/passwd

du -b /etc/passwd

du -b /tmp

du -b ~

du -b $HOME

du -s -b .

du -s -b /

Symbol : ~

Symbol : .

Symbol : ..

Theory : Client Server Concepts

Servers: sshd(22), vsftpd (21), httpd(80) dns(53)

Daemon is a constantly running program in the background

Note: File related commands (ls, cat, more, less, wc , cp, mv, touch, stat,

head, tail

chmod,chown chgrp)

vi)

Note: Dir related commands (ls -ld , mkdir, rmdir , rm -r cd , stat, chmod, chown, chgrp

Test : No 2

Q:* How do you display the contents of a text file.

cat, more, less, head, tail, vi, nano

Q: *Can you see the contents of a binary file


no

Q: *Which command shows you the type of a file

ls -l ( - regular file

d directory file

l link file

b block device file

c character device file

s socket file)

stat

Q:* HOw do find out who has created a file.

ls -l , stat

Q: *How to find out the size of a specific file

ls -l , stat, du

Q: *How do you display the list of all files in /etc directory

ls -l /etc

du /etc

Q: *Display list of all files that have extension .config in /etc directory

ls -l /etc/*.config

Q: *What is your present working directory

pwd

Q: *T/F home directory is same as your present working directory

some times, when you are just logged in


Q: *WHich is the top most directory in UNIX

Q: *In which directories a user can create files

(any dir where a user have a w permission)

home dir

/tmp

Q: *Name 2 ways of creating a new file

vi, cat, cp, touch, >

Q: *mention 3 ways to go to your home directory from any directory

cd

cd ~

cd $HOME

Q: *Write a command to go to /tmp diretory using absolute path

cd /tmp

Q: *Write a command to go to /tmp diretory using relative path (assume that your are in /etc directory)

cd ../tmp

Q: Copy the passwd file in /etc directory to you home directory


cp /etc/passwd /home/shekhar

cp /etc/passwd $HOME

cp /etc/passwd . <== if yoy are in your home dir

cp /etc/passwd ~

cp /etc/passwd ~shekhar

Using relative path (assume that you are in /tmp dir)

cp ../etc/passwd ../home/shekhar

Using relative path (assume that you are in /home/shkhar dir)

cp ../../etc/passwd .

Q: You are in /tmp directory. you file the following commands. Is there any difference between them

:q!

rm -rf ./bin
rm -rf bin

rm -rf /bin

Q: Copy the password file in /etc directory to /tmp directory. Name it as shekhar_passwd

cp /etc/passwd /tmp/shekhar_passwd

Q: *Who is the owner of /etc/passwd file. Who is the owner of the file you just created

ls -l /etc/passwd

stat /etc/passwd

Q: *What is an inode and how to find out and inode number of a file

ls -li /etc/passwd

stat /etc/passwd

Q: How to display information from the inode of a file

ls -l /etc/passwd

stat /etc/passwd

*Q: Copy all .conf files from /etc to your home directory

cp /etc/*.conf /home/shekhar

cp /etc/*.conf ~/shekhar

If you are in /etc

cp ./*.conf /home/shekhar

cp *.conf /home/shekhar

cp *.conf ~shekhar

If you are in /home/shekhar

cp /etc/*.conf .
*Q: Create a directory named config_files under your home directory

mkdir config_file <= you should be in your home dir

mkdir /home/shekhar/config_files

mkdir ~shekhar/config_files

*Q: Move all .conf files in your home directory to the config_files directory that you just created.

mv /home/shekhar/*.conf /home/shekhar/config_files

mv /home/shekhar/*.conf ~shekhar/config_files

mv ~shekhar/*.conf ~shekhar/config_files

mv ~shekhar/*.conf ~shekhar/config_files

mv ~/*.conf ~/config_files

mv ./*.conf ./config_files <== you are in your home dir

*Q: What is the size of /etc/group file. Tell 3 commands to find the size of a file.

ls -l /etc/group

ls -s /etc/group

stat /etc/group

du -b /etc/group

Q: How many lines in the /etc/passwd file


wc -l /etc/passwd

Q: Create a backup of all files in config_files directory under your home directory to
/tmp/shekhar_backup directory

mkdir /tmp/shekahr_backup

cp /home/shekhar/config_files/* /tmp/shekhar_backup

*Q: Which command will display the top 26 lines of /etc/passwd file

head -26 /etc/passwd

*Q: Write a command to delete all shell scripts from the bin directory of shekhar's home directory. Shell
must ask you a y/n question before deleting each file.

rm -i ~shekhar/*.sh

rm -i /home/shekhar/*.sh

rm -i ./*.sh <== you must be in home

Q: Create an alias in such a way that you will be always asked for a y/n confirmation when you delete
any file.

alias rm='rm -i'

*Q: How do display the bottom 6 lines of the group file in the /etc directory

tail -6 /etc/group

Q: How many words are in /etc/vsftpd/vsftpd.conf file


wc -w /etc/vsftpd/vsftpd.conf

*Q: Copy all .config files /etc directory to a newly created directory named config in your home
directory.

Copy all shell scripts from shekhar's home directory to a newly created directory named bin in your
home directory.

Q: Take a backup of both of the above directories inder /tmp/shekharbackup - replace shekhar by your
name

$HOME

bin <== shell scripts from shekhar's home dir

config <== all .config files from /etc

/tmp/shekharbackup

bin

config

mkdir /tmp/shekharbackup

mkdir /tmp/shekhar/backup/bin

cp ~shekhar/bin/*.sh /tmp/shekharbackup/bin

cp -a a,txt b.txt

cp -r dir1 dir2
Day No. 3

---------

Command : man

man -k keyword

SEE ALSO

Command : whatis

whatis ls

Command : whereis

whereis cp

Command : which

which cp

Command : tar

tar -c -f /tmp/shekhar.tar /home/shekahr

tar -x -f /tmp/shekhar.tar -C /tmp/new

tar -t -f /tmp/shekhar.tar

tar -c -z -f /tmp/shekhar.tar.gz /home/shekahr

tar -x -f /tmp/shekhar.tar.gz -C /tmp/shekhar

tar -c -f /tmp/shekhar_26_06_2014.tar $HOME

tar -c -f /tmp/shekhar_26_06_2014.tar ~
Command : gzip

gzip abcd.txt

gzip /tmp/abcd.tar

Command : gunzip

gunzip abcd.txt.gz

gunzip abcd.tar.gz

gunzip /tmp/abcd.tar.gz

Command : zip

zip abcd.txt.zip abcd.txt

Command : unzip

unzip abcd.txt.zip

Q: Take the compressed backup of your friend's home dir and keep the backup file in your home dir.
What is the compression ration

Command : vi

3 modes - command (Esc) , typing mode (insert) , Ex Mode

Type - insert (below current line - o , above current line)

i - insert before current position

a - insert after the current position

o - below the current line

O - above the current line


delete (word, line, multiple lines, char)

dw - delete a word

dd - delete the current line

9dd - delete 9 lines below the current, including the current line

D - delete from the current position till the end of line

x - delete a current character

copy (word, line, ...)

yw - copy current word

yy - copy current line

9yy - copy 9 lines including the current line

paste (above the current line, below current line, at the end of the line)

p - paste clipboard below current line

P - paste clipboard above current line

undo

u - undo previous changes

search (above the current cursor location, below the current cursor location)

/shekhar <== search the word shekhar below current position

?shekhar <== search the word shekhar above current position

n - to goto next occurence of the searched word

replace

:1,20s/shekhar/peter/ <== replace shekhar by peter from line 1 till 20

replace only the first occurence of word shekhar

:1,40s/shekhar/peter/g <== replace shekhar by peter from line 1 till 40

replace all occurences of word shekhar in these lines

:1,$s/shekhar/peter/g <== replace shekhar by peter in the entire file


replace all occurences of word shekhar in entire file

:%s/shekhar/peter/g <== replace shekhar by peter in the entire file

replace all occurences of word shekhar in entire file

r <== replace a current character

cw <== change the current word

redo

. <== redo the previous command

save

:w <== save

:w! <== save even if the file is read only

(you must be the owner of the file)

close/exit/quit - quit without saving

:q <== quit

:q! <== quit without saving

show line numbers

:set nu

:set nonu

goto - begining of file , end of file, to spacific line,

start of line, end of line

up , dkkkkwn , right, left

gg <== gkkkk to the begining of the file

G <== end kkkkf the file

:5 <== gkkkk to line number 5

^ <== go to start of the current line


$ <== go to the end of the current line

j <== down arrow

k <== up arrow

l <== right arrow

h <== left arrow

page up

ctrl b < ==pageup

page down

ctrl f <== pagedown

bring contents from other file to the current file

:r a.txt <== bring contents of a.txt into current file at the current cursor location

Test : No 3

*Q: How to find out what files are in a tar file

Q: How to extract only one file from a tar file

*Q: How to perform compression of a tar file

gzip abcd.tar

tar -czf abcd.tar /home/shekhar

*Q: Which compression utility is used to compress a the file when we use -z option tar

gzip

*Q: How to compress any normal file


gzip abcd.tar

zip abcd.txt.zip abcd.txt

*Q: How to uncompress an already compressed file

gunzip abcd.tar.gz

unzip abcd.txt.zip

*Q: Write a command to take a backup of your home directory

tar -cvf /tmp/a.tar $HOME

tar -cvf /tmp/a.tar /home/shekhar

tar -cvf /tmp/a.tar ~

*Q: What commands are related to a keyword copy

man -k copy

*Q: In which directory the 'ifconfig' command is located

which ifconfig

whereis ifconfig

Q: vi - How to go to the end of the file

*Q: Create a direc strucure as follows in your home dir

$HOME

- bin

- docs

- commands.txt <== copy from UNIX dir under shekhar's home dir

- mycommands.txt <= use vi

- tmp

move all other files and dir under you home dir to tmp
mkdir /home/jason/tmp

mv /home/jason/* /home/jason/tmp

mkdir /home/jason/bin

mkdir /home/jason/docs

cp ~shekhar/UNIX/commands.txt ~/docs

*Q: How many lines are there in $HOME/docs/mycommands.txt file

wc -l $HOME/docs/mycommands.txt

*Q: How many lines are there in commands.txt file in shekhar's home dir

wc -l ~shekhar/UNIX/commands.txt

*Q: What is the size of your tar file

ls -l abcd.tar

stat abcd.tar

*Q: reduce the tar file using the best compression utility

Q: Extract your docs dir in /tmp from the tar file that you have just created

*Q: take a backup of bin and docs directory under your home directory. The backup file should be
named as /tmp/mybak.tar

tar -cvf /tmp/mybak.tar /home/peter/docs /home/peter/bin

Day No. 4

---------

Command : sort

cat data.txt

Shekhar Pune 99
Sachin Parbhani 9000

Sanyam Satara 888

sort data.txt

sort /home/shekhar/UNIX/data.txt

sort -r /home/shekhar/UNIX/data.txt

sort -k2 /home/student/Desktop/data.txt

sort -r -k2 /home/student/Desktop/data.txt

sort -k2 -r /home/student/Desktop/data.txt

sort -rk2 /home/student/Desktop/data.txt

sort -k3 /home/student/Desktop/data.txt

sort -k3 -n /home/student/Desktop/data.txt

sort -r -n -k3 /home/student/Desktop/data.txt

sort -rnk3 /home/student/Desktop/data.txt

Shekhar:Pune:99

Sanyam:Satara:888

Sachin:Parbhani:9000

sort -n -t: -k3 data.txt

sort -n -t':' -k3 data.txt

Command : uniq

uniq data.txt

uniq -c data.txt

The data in file must be sorted for uniq

command to properly work

Command : cut
cut -d":" -f1 data.txt

cut -d":" -f2 data.txt

cut -d":" -f1,3 data.txt

cut -d":" -f1-3 data.txt

cut -d'a' -f2 data.txt

cut -d' ' -f3 data.txt

cut -d' ' -f3 /home/student/data.txt

cut -c1-10 /home/student/data.txt

cut -c5-10 /home/student/data.txt

File : /etc/passwd

stores user info on your system

1. username

2. password (always x

3. UID

4. GID

5. Name or info of user

6. home directory of the user

7. login shell <= shell program automatically starts when user logs in

cut -d':' -f1 /etc/passwd

cut -d':' -f1,6 /etc/passwd

Command : fgrep , grep, egrep

grep shekhar data.txt

grep -i shekhar data.txt

grep -v shekhar data.txt

What is a regular expression :


It is a search pattern used by commands like grep, egrep, sed, etc to search a specific pattern of
characters in a file

Regular expressions

. <== any single char

* <== zero or multiple occurances of a previous char

^shekhar <== shekhar word is at the begining of the line

shekhar$ <== shekkhar is at the end of the line

[abc] <== either a or b or c

[^p] <== any char other than p

[a-z] <== any char from a to z

[A-Z] <== any char from A to Z

^$ <== blank line

[0-9] <== any single digit

[086] <= either 0 or 8 or 6

[^086] <= neither 0 nor 8 nor 6

Extended Regular expression

egrep '(shekhar|peter)' data.txt <== show all line those contain either shekhar or peter

grep -E '(shekhar|peter)' data.txt <== show all line those contain either she khar or
peter

Command : diff

Command : tr

echo 'shekhar Tulshibagwale | tr -s ' '

Command : cmp
I/O Redirection

> 1>

>> 1>>

2>

2>>

<

<<EOF

&>

&>>

tee

io redirection: cmd 1> filename

io redirection: cmd 1>> filename

1> filename <== created a blank file

What is a /dev/null file

There is a file named null in /dev/ directory. Anyone has the write permission on this file. Any
data written or redirected to this file is immediately erased. This file, therefore, can be used for
collecting garbage.

io redirection: cmd | cmd

cut -d':' -f1 /etc/passwd | sort

ls -l | sort -n -k5 | tail -1

ls -l /etc | sort -n -k5 | tail -1

who | cut -d' ' -f1 | sort | uniq

io redirection: &>

io redirection: 2>>
io redirection: 2>

tar -cvf /tmp/a.tar /etc 1> a.txt

tar -cvf /tmp/a.tar /etc 2> b.txt

tar -cvf /tmp/a.tar /etc &> c.txt

C*Q: take a backup of bin and docs directory under your home directory. The

backup file should be named as /tmp/mybak.tarommand that need input

cat, wc, sort, more, less, grep, fgrep, egrep, head, tail, sed

io redirection: <

Note: stdout is a virtual file sttting in RAM. You cannot see this file using

ls command. The file descriptor for this file is 1.

Test : No 4

Q: Display list of system users in sorted fashion z-a

cat /etc/passwd | cut -d':' -f1 | sort -r

cut -d':' /etc/passwd | sort -r

Q: Display list of system users and their login shell

cat /etc/passwd | cut -d':' -f1,7

cut -d':' -f1,7 /etc/passwd

Q: Find out all IP address from where users are currently logged in

w -h | tr -s ' ' | cut -d' ' -f3

w | grep -v 'load average:'| grep -v TTY | tr -s ' ' | cut -d' ' -f3

who | tr -s ' ' | cut -d' ' -f5

who | cut -d'(' -f2 | cut -d')' -f1


Q: Crete an alias named ip do display only the IP address of your server

alias ip='ifconfig | head -2 | tail -1 | cut -d":" -f2| cut -d" " -f1'

Q: Find out all uniq IP address from where users were logged in (use last command)

last | grep -v reboot | fgrep -v :0 | fgrep -v -w :1 | tr -s ' ' | cut

-d ' ' -f3

Q: How many times the system was rebooted

last | grep reboot | wc -l

last | grep -c reboot

Q: List of IPs from where users had logged in which are not internal IPS(172, 192, desktop)

last | fgrep -v 192. | fgrep -v 172. | fgrep -v desktop | tr -s ' ' | cut -d ' ' -f3 | sort | uniq

last | egrep -v (172|192|desktop) tr -s ' ' | cut -d ' ' -f3 | sort | uniq

last | grep -E -v (172|192|desktop) tr -s ' ' | cut -d ' ' -f3 | sort | uniq

Q: Display ip address/es or machine names of the machine from where shekhar has loogged in

who | grep shekhar | cut -d'(' -f2 | cut -d ')' -f1 | sort | uniq

process Management

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

What is a differerence between a process and a program .

What are the main attributes of a process that are stored in process table

1. owner of a process

2. PID - unique no. assigned to a process

3. PPID - parent of the process

4. CPU consumption by
5. RAM consumption

6. Nice value

7. command

ps

ps -f

ps -e

ps -ef

ps aux

kill pid

kill -9 pid

ctrl c

ctrl z

bg

fg

jobs

&
Q: How many processes oracle is running

ps -ef | grep ^oracle | wc -l

Q: How many processes are there for ssh

ps -ef | grep sshd | grep -v grep | wc -l

Q: IS oracle database named focus running on your server

ps -ef | grep ora_pmon_focus

Q: IS Web server running on your server

ps -ef | grep httpd

Q: IS FTP server running on your server

ps -ef | grep vsftpd

Q: Who is the owner of 4545(PID) process


ps -ef | grep -w 4545 | grep -v grep | cut -d ' ' -f1

Q: Display PID and owner of the process which is comsuming highest cpu

ps aux | sort -k3 -n | tail -1| tr -s ' ' | cut -d' ' -f1,2

Q: Display PID and owner of the process which is comsuming highest ram

ps aux | sort -k4 -n | tail -1| tr -s ' ' | cut -d' ' -f1,2

Q: Choose all items that match the regular expression

br[nr]k

bank

banrk

bark

bakk

^root

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin

root is the best!

you are not root.

root

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin

root is the best!

you are not root.

r..t

root:x:0:0:root:/root:/bin/bash

operator:x:11:0:operator:/root:/sbin/nologin

root is the best!


you are not root.

Q: Create a regular expression

Line begins with "Test" or "test"

Line ends with "end."

The entire line is: This is a test

Any one of the names: file5 file6 file7 file8

Day No. 5

---------

Ad Practicals : No 1

Ad Practicals : No 2

Ad Practicals : No 3

Day No. 6

---------
Theory : permissions, groups, users

Command : id

id <= displays uid and gid of currently logged in user

id oracle <==displays uid and gid of user oracle

Command : groups

groups <== displays all groups that you are a member o (first group is the primary group)

groups oracle <== displays all groups that the user oracle is a member of

FIle : ~/.bash_logout

FIle : ~/.bash_profile

FIle : ~/.bash_history

FIle : ~/.bashrc

FIle : ~/.vimrc

File : /etc/group <== list of all groups

Command : chgrp

chgrp dba a.txt <== changes the group owner of a.txt file to dba

Command : chmod

Only owner/root can run the chmod command on a file/directory

u=owner/user g=group o=other a=all

- <== remove the permission

+ <== give the permission

chmod g+x $HOME

chmod go-rwx $HOME

chmod a+rwx $HOME <= be careful when you run this command

chmod a-rwx a.txt

chmod u+rwx,g+rx a.txt


r-4

w-2

x-1

chmod 444 a.txt

chmod 421 a.txt

chmod 621 a.txt

chmod 700 a.txt

chmod 750 a.txt

chmod 755 a.txt

chmod 777 a.txt

chmod -R 755 $HOME

chown

chown arung a.txt <== chown can be executed by root only

changes the owner of a.txt file to arung

chown arun.dba a.txt <== changes owner to arun and group owner to dba

chown arun:dba a.txt <== changes owner to arun and group owner to dba

chown -R arun:dba /home/shekhar <== changes owner to arun and group owner to dba of all
file and subdirectories inside /home/shekhar

Shortcuts : ctrl + d

Test : No 6

Q: What is a group

Its a collections of users


Q: If a user named shakhar creates a file who would be the owner of that file and who would be the
group owner of that file

shekhar, shekhar's primary group

Q: How to find out shekhar's primary group

groups shekhar , id shekhar <== first group is the primary group

Q: How to find out gid of shekhar's primary group

id shekhar

Q: how to find out oracle's uid

id oracle

Q: How to find out arun's secondary groups

id arun

groups arun

Q: How to find out who is the owner of a file (e.g /etc/passwd)

ls -l /etc/passwd

stat /etc/passwd

Q: How to find out what permissions the owner has on a file

ls -l /etc/passwd

stat /etc/passwd

Q: How to find out the ower of a directory (e.g. /tmp)

ls -ld /tmp

Q: Can you copy the /etc/passwd to your home directory. Why

cp /etc/passwd $HOME

Q: Can you run the following command succesfully. Why

rm /etc/shadow

You cannot because you do not have write permission of the parent dir i.e /etc

Q: Can you run the followig command. Why


mv /etc/passwd /tmp

No. Because you don't have write permission on the /etc directory

Q: Can you(oracle) execute the following command. Why

cp /etc/passwd ~shekhar

No. Because oracle does not have write permission to ~shekhar directory

Q: How can run the chmod command

owner of the file , root

Q: How can run the chgrp command

owner of the file , root

Q: How can run the chown command

root only

Q: What permissions are required if user oracle wants to execute the following command

cp ~shekhar/.bash_profile ~

Read permission on ~shekhar/.bash_profile file

Write permission on ~ (i.e. write permission on oracle's home directory)

Q: What permissions are required if user shekhar wants to execute the following command

mv /etc/passwd /tmp

Write permission on /etc directory. Any permission on passwd file will do

Write permission on /tmp

Q: What is the difference between the following two commands

chmod o+rx /tmp/a.txt <== relative permission. means you cannot tell what will be the final
permission of /tmp/a.txt

chmod 755 /tmp/a.txt <== absolute permission

Q: ls -l /tmp/shekhar.txt gives the followig output

-rw-r--r-- 1 oracle oinstall 11 Jul 6 23:11 shekhar.txt


What will be the attributes(permissions, owner, groupowner, timestamp) if user shekhar
execites the following commands

cp /tmp/shekhar.txt /tmp/shekhar.txt.new

cp -p /tmp/shekhar.txt /tmp/shekhar.txt.new

What will be the attributes(permissions, owner, groupowner, timestamp) if user root execites
the following commands

cp /tmp/shekhar.txt /tmp/shekhar.txt.new

cp -p /tmp/shekhar.txt /tmp/shekhar.txt.new

Day No. 7

---------

Command : ps

ps

ps -e <== shows everything i.e. all processes on your system

ps -f <== full listing i.e. give more info of process

ps -ef

ps aux <== give cpu and ram info of each process

IMP fields (owner, pid, ppid, comm, %CPU, %MEM)


Command : pstree <== shows parent child relationships between processes

Command : top

Command : free

Swap mean virtual ram. It is not real ram. It is some space on hard disk

Swap = page file in windows

Swap can be a file on a hard disk or it can be a partition on the harddisk

File : /proc/meminfo

Command : mpstat

File : /proc/cpuinfo

Command : iostat

Command : bg

Command : fg <== bring the background job to foreground. The background job

may be running or stopped.

Status :

Running & attched to terminal - Running in the foreground

Running in background

Stopped

Command : jobs <== display list of jobs started from the termonal

Command : sleep

Command : kill

kill 8188 <== kill i.e. terminate the process with 8188 PID

kill -9 8188 <== forceful/sure kill if the process cannot be killed by the above command

Command : lsof <== display list of opened files

lsof

lsof -u shekhar <== all files opened by shekhar (can be run by root)
lsof -p 1881 <== shows all files opened by process 1881

Symbol : &

Shortcuts : ctrl + c

Shortcuts : ctrl + z

Test : No 7

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

Q: Which process is consuming highest amount of CPU

ps aux | sort -k3 -n <== last process

top <== fiorst process

Q: Which process is consuming highest amount of RAM

ps aux | sort -k4 -n <== last process

Q: What is a daemon

It is a process. This process is constantly running in the background

doing its work. The names of daemon processes usually end with a letter 'd' .

Example, crond, vsftpd, httpd, sshd, atd, ntpd, udevd, iscsid, libvirtd. They are not tied to any terminal. It
means under the heading of TTY there would be a '?' for this process

crond - job scheduling (autosys is an advanced scheduler)

vsftpd - ftp server daemon/process

httpd - Web server daemon/process

sshd - Secure Shell daemon (if this is down, no one can connect using ssh to the server)

atd - another scheduler. very basic

ntpd - time server daemon (other machines in your organization will sync up their system time
with this machine)
udevd - this daemon is used to give consistent/same names to all devices

/dev/sda <= block device file i.e. disk

/dev/sdb

iscsid - another daemon related to storage services

libvirtd - another daemon related to virtualization

Q: Run sleep command in one window and kill it from another window

Only the owner of the process can kill the process

ps -ef | grep sleep <== get the proper PID

kill 8388 <= 8388 is the PID in this example

Q: There is a shell script named /tmp/my.sh. Copy it to your home dir. Run it in the background.

sh my.sh &

sh ~shekhar/my.sh &

sh /home/shekhar/my.sh &

Q: Bring it to the fore ground

jobs

fg 1 <== 1 is the job number/id (This is not the PID)

Q: Kill it from another window

kill 8237 <= 8237 is the PID found from the ps command

Q: What will happen when you type ctrl z in vi

vi will go to background and will be stopped

jobs

fg 3 <== bring it to foreground


Q: How to kill it from the same window

ctrl c <== the job should be running in the foreground. i.e. it should be attached to a tty

Q: How to put a foreground job in background

ctrl z <== this will stop the job

jobs <== get the job number of the stopped process

bg 1 <==1 is the job number obtained from the jobs command

Note: Stopped process does not consume any CPU

Q: Kill the process that has opened a file named a.sh

lsof | grep a.sh <== get the PID

kill

Q: What is the RAM on your server. How much is free

free

Q: tell 3 commands to display memory information

free

cat /proc/meminfo

top

Q: Are there any jobs running for your session

jobs <== only for your session. A window is a session

Q: WHich process is accessing a file named /tmp/a.txt

lsof | grep a.txt

Q: Why should you not used kill -9 as the first option to kill a process

You may create defunt processes. Which creates memory leak. ememory

lead reduces t6he performance of your server

Q: How to send signals to amy process. Name some of the signals


kill -l <== display list of all possible signals that can be sent to any process

kill 8188 < == This sends a signal number 15 (termination)

kill -15 8188 < == This sends a signal number 15 (termination)

kill SIGTERM 8188 < == This sends a signal number 15 (termination)

kill -9 8188 < == Sinnale no. 9 tells the process to surely kill itself

ctrl z <== send SIGSTOP(19) signal to a process

Q: How many CPUS are there on your system. Give their info

cat /proc/cpuinfo

Q: How to find out if your machine is a read machine or a virtual machine

cat /proc/cpuinfo <== Look for Model name. it will show 'virtual' if the machine is virtual

Q: Is your CPU idle

top

Q: What is the load on your system for the last 15 minutes

uptime <== last number in uptime's output

top <== first lines last number

Q: How many disks are there on your system.

Q: Which disk is performing high amount of i/o.

Q: Which activity (read or write) is happening on this disk


Day No. 8

---------

Command : nslookup

Command : nmap

Command : netstat

Command : bc

Command : dnsdomainname

Command : scp

Command : ftp

Command : lftp

Command : sftp

Command : wget

Command : rsync

Test : No 8

hat is DNS

Domain name server. it is a daemon process running on one of the servers in our organization.
The name of the daemon process is named.

[root@localhost ~]# ps -ef | grep named

named 1971 1 0 00:46 ? 00:00:00 /usr/sbin/named-sdb -u named -t /var/named/chroot

root 3106 3088 0 01:00 pts/0 00:00:00 grep named

Any machine in your organizarion can query this DNS to get answers.

1. Give name of the machine and Get IP from DNS.

2. Give IP of the machine nad Get name from DNS

DNS has a database of IPs and hostnames


Which commands are used to query DNS

nslookup

How to know which is your DNS Server. I.e. which DNS server your machine is querying

cat /etc/resolv.conf

WHich ports are open on 192.168.0.3

nmap 192.168.0.3

Which file documents the list of all possible ports used by various daemon processes(services)

/etc/services

WHich ports are open on your own machine

nmap localhost

nmap your_own_ip_address

How to find out which clients are connected to your machine (not just ssh clients)

netstat -tn (t=tcp connections, n=show ip addressess instead of hostnames

How to find out the domainname of your DNS Server

dnsdomainname

Give at least 2 commands to copy a file from one server to another

scp

You must know the password

it uses the ssh protocol(22). Therefore you need to know the password that you use to ssh into
the machine

ftp

You may not need to know the password (anonymous)

It uses ftp protocol(21)

wget

YOu don't need to know the password

It uses http protocol(80)


rsync

ssh and telnet are not used to copy/download/upload a file from one server to another. They
are used only to establish the connection to another server.

Q: Assume that your are a user named arun currently logged on to 172.24.0.240

1. Copy a file named a.txt in /tmp of 192.168 0.3 to your home directory

scp shekhar@192.168.0.3:/tmp/a.txt $HOME

Note: The above command will ask you shekhar's password on 192.168.0.3

2. Copy a file named /home/shekhar/p.txt to /tmp directory on 192.168.0.4

scp /home/shekhar/p.txt peter@192.168.0.4:/tmp/p.txt

Note: The above command will ask you peters's password on 192.168.0.4

3. Copy a file named /tmp/x.txt from 192.168.0.3 to /home/shekhar directory

on 192.168.0.4

scp priya@192.168.0.3:/tmp/x.txt abhishek@192.168.0.4:/home/shekhar

Note: The above command will ask you priya's password on 192.168.0.3

Note: The above command will ask you abhishek's password on 192.168.0.4
Q: WHy the following command would not work

scp /home/student/Desktop/amrut.txt student@192.168.0.3:/etc

Q: WHy the following command would work

scp /home/student/Desktop/amrut.txt root@192.168.0.3:/etc


Q: How to transfer a file from/to windows machine to UNIX

Download a software named winscp. Its free

Q: What will the folling command do

scp -r /etc shekhar@172.24.0.240:/tmp

It will copy entire /etc directory to /tmp directory on 172.24.0.240. It will ask you shekhar's
password on 172.24.0.240
Q: On which port ftp server runs

21

Q: How to connect to the ftp server. Mention at least 3 ways

ftp ip_address_of_the_server_where_ftp_daemon_is_running

These days not used in industry. Because it transfers data/file in non-encrypted format

lftp ip_address_of_the_server_where_ftp_daemon_is_running

lftp does data transfer in encrypted and has many advanced commands to transfer the
file

sftp ip_address_of_the_server_where_ftp_daemon_is_running

Sftp transfrs data in encrypted fashion and therefore used in industry

Use web browser to connect to ftp server as follows

ftp://192.168.0.250/
Q: Mention at least 5 different ftp commands

help

pwd

ls -l

cd <== change dir at server location

lcd <== change dir at client location

get a.txt get /pub/a.txt

put b.txt

mget *.sh

mput *.txt

quit
Day No. 9

---------

Command : crontab

Note: crontab is a command which interacts with a daemon named crond.

Daemon is a constantly running process in the background. The daemon process

is not attached to the termminal. i.e. TTY is ?. This crond daemon is

automatically started when your server is booted. You can check if this

process is running or not by typing the following command

ps -ef | grep crond

service crond status

The purpose of this daemon process is to wake up every minute and

check if there are any programs/scripts that need to be executed on behalf of

some user. A program/script scheduled to run at a specific time is called as a

job. In other words crond is reponsible for running jobs on your system.

The crontab command is the way to tell crond about which

program/script to run at which time and at which interval.


crontab -l <== see the existing job schedule

crontab -r <== remove the existing job schedule (dengerous command)

crontab -l > crontab.backup <== output of crontab -l is stored in crontab.backup file

crontab < crontab.

<== Schedule eritten in crontab.backup is sent as an input to the crontab command

Explain each and every entry in crontab file.

The time and date fields are:

field allowed values

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

minute 0-59

hour 0-23

day of month 1-31

month 1-12 (or names, see below)

day of week 0-7 (0 or 7 is Sun, or use names)

A field may be an asterisk (*), which always stands for "first-last".

Ranges of numbers are allowed. Ranges are two numbers separated with a hyphen. The speci-

fied range is inclusive. For example, 8-11 for an "hours" entry specifies execution at hours

8, 9, 10 and 11.

Lists are allowed. A list is a set of numbers (or ranges) separated by commas. Examples:
"1,2,5,9", "0-4,8-12".

Step values can be used in conjunction with ranges. Following a range with "<number>" speci-

fies skips of the number’s value through the range. For example, "0-23/2" can be used in the

hours field to specify command execution every other hour (the alternative in the V7 standard

is "0,2,4,6,8,10,12,14,16,18,20,22"). Steps are also permitted after an asterisk, so if you

want to say "every two hours", just use "*/2".

Command : find

find command is used to find a file/s in a specific directory (Note: grep is used to find a
word/string in a file/s)

find - search for files in a directory hierarchy

Syntax :

find which_dir [criteria] action

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

A file whose name is a.txt and print it on the terminal

find /home -name a.txt -print

A file whose name is a.txt, A.txt, A.TXT and print it on the terminal

find /home -iname a.txt -print

A file whose owner is shekhar and print it on the terminal

find /home -user shekhar -print


Find in either /home or /etc a file whose owner is shekhar and print it on the terminal

find /home /etc -user shekhar -print

Find in /home a file whose groupowner is oinstall and list the file details like the ls command

find /home -group oinstall -ls

Find in /home a files whose permission is 777 and list the file details like the ls command

find /home -perm 777 -ls 2> /dev/null

+10 10 -10

<---------------------|---------------------|

5 15

(Today)

Find files in /home whose modification time is exactly 7 days ago

find /home -mtime 7 -print

Find files in /home whose modification time is 7 days ago

find /home -mtime +7 -print

Find all log files in /tmp whose modification time is before 7 days and delete them

find /tmp -mtime +7 -name '*.log' -delete


Find files in /home whose modification time is within last 7 days

find /home -mtime -7 -print

find /home -atime <== access time

Find files in /home whose size is 10M (you can use K M G T)

find /home -size 10M -print

Find files in /home whose size is greater than 10M

find /home -size +10M -print

find / -user oracle -size +100M -ls 2> /dev/null

Find files in /home whose size less is 10M

find /home -size -10M -printo

find /home -newer a.txt -exec rm {} \;

find /home -newer a.txt -exec cp {} /tmp \;

find /home -newer a.txt -exec mv {} /tmp \;

find /home -newer a.txt -exec chmod 700 {} \;

find /home -newer a.txt -exec chown oracle.oinstall {} \;

find /home -newer a.txt -exec grep shekhar {} \;

find /home -newer a.txt -exec wc -l {} \;

find /etc -name '*.conf' -exec cp {} /mybakup \;


find /etc -name '*.conf' -exec cp {} /mybakup/{}.bak \;

tar -cvf /tmp/a.tar /home/shekhar/a.sh /home/shekhar/b.sh /home/shekhar/c.sh

tar -cvf /tmp/a.tar `find /etc -name '*.conf' -print`

find /etc -name '*.conf' -exec tar -cvf a.tar {} \;

find /home -empty

find /home -gid 100

find /home -uid 200

find /home -newer a.txt -print

find /home -newer a.txt -ls

find /home -newer a.txt -delete

find /home -newer a.txt -ok

find /home -newer a.txt -ok -exec rm {} \;

find /home -inum 27772 -print

Some examples of find commands :

# touch file_{1,2,3}

# touch FILE_{1,2,3}
# touch file_{pune,mumbai,nagpur}

1> find /home/shekhar -name "file_pune -print

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

where to find What to find What action to take on this file

2> find . -name "file_?"

3> find $HOME -name "file_*"

4> find /etc -name "*.conf"

5> find /usr -name "*.gz"

7> find / -user lp -name a.txt 2> /dev/null

8> find /var -user root -group mail -print 2> /dev/null

9> find /var/lib -user rpm -group rpm -ls 2> /dev/null | less

10> find /etc/httpd -exec file {} \;

11> find /etc/mail -name "sendmail*" -exec file {} \;


12> find /etc -name "*.conf" -exec cp {} {}.bak \;

13> find /etc -name *.conf.bak -ok rm {} \; # -ok is like -exec, but asks user for confirmation

14> find /tmp -type f -ls 2> /dev/null

15> find /tmp -type d -ls 2> /dev/null

17> find /etc -type l -ls 2> /dev/null | wc -l

18> find /var/lib -user games -ls 2> /dev/null | less

19> find /bin /usr/bin/ /sbin -perm -u+s -ls 2> /dev/null

20> find /etc/httpd/conf -ok file {} \;

21> tar -cvf etc.tar $(find /etc -name "*.conf" )

22> find /etc -name passwd > /tmp/output_of_find

23> find /etc -name squid.conf >> /tmp/output_of_find 2> /dev/null

24> find $HOME -mtime +7 -print

25> find $HOME -mtime -7 -print


Command : ln

Command : mail

mail <== check the email inbox (1, d 2, d * )

mail shekhar@gmail.com (. means end of email)

mail -s 'Hello' shekhar@gmail.com < /etc/passwd

mail -s 'Hello' shekhar@gmail.com -a b.txt < /dev/null

echo 'Hello' | mail -s 'Hello' shekhar@gmail.com -a b.txt

Test : No 9

Q: WHich command shows you list of emails in your inbox

mail

Q: List a few mail commands

f * <== display entire inbox

q <== quit

59 <== display the body of 59th email

d 21 <= will delete 21st email from your inbox

Q: How to send an email to abhishekk

mail abishekk (entire subject and body and at the end type a . )

mail -s 'Hello' abhishekk < a.txt

cat a.txt | mail -s 'Hello' abhishekk

Q: In which file your entire inbox is stored

/var/spool/mail/shekhar <== if your username is shekhar


Q: How to send a file as an attachment

mail -s 'Hello' abhishekk -a k.txt < m.txt

In the above example k.txt file will be sent as an attachment

and m.txt file's content will appear as the body of an email

Scheduler - cron

===========

Q: Name 4 scheduler software popular in the industry

Control M (Windows or UNIX)

Autosys (Windows or UNIX)

Windows Scheduler (Only on windows)

cron (Only on All UNIX flavors )

Q: What is a job

It is a schedule for a specific program/script/executable

e.g. Run ifconfig command at 3:00 PM every day

e.g. Run backup.sh script at 4:00 AM every sunday

Q: Which process must be running in order for a job to be executed

crond
Q: How to check if the crond daemon/process is running or not

ps -ef | grep crond

service crond status

Q: WHo is the owner of the crond process

root

Q: How to check the current schedule of jobs


crontab -l

Q: How to submit an instruction to a crond daemon

crontab -e

Q: How to disable one job from an existing scheedule

crontab -e and then comment the line for the job by putting #

Q: How to take a backup of your current job schdule

crontab -l > mycron.bak

Q: How to restore from the backup


crontab < mycron.bak

Q: What is the 4th field in crontab file

Month

Q: What permissions are required on the program/script file

Owner mush have execute permission

chmod u+x script_name

Q: How to check if your job has failed or succeed

1. Check the email

2. Capture stdout and stderr to a file and check the file's content
Q: Will your job run if you are not logged on

yes. The machine needs to be up

Q: Will your job run if your server is shut down

No.

Q: If you restart the server will your jobs run that were scheduled during the downtime

Q: How to run a script every minute

* * * * * /home/shekhar/a.sh
Q: How to run a script at 8:10 PM every night except sundays

10 20 * * 1-6 /home/shekhar/a.sh

10 20 * * 1,2,3,4,5,6 /home/shekhar/a.sh

Q: How to run a script at 2:30 PM on Christmas day only,and 31st of December only

30 14 25,31 12 * /home/shekhar/a.sh

Q: How to run a script at 2:30 AM on Christmas day only,and at 2:30 PM on 31st of December only

30 2 25 12 * /home/shekhar/a.sh

30 14 31 12 * /home/shekhar/a.sh
Q: Write a shell script in your home directory named backup.sh to take the backup of your home dir.
Schedule this script to run every night at 9:00 PM. Check the next day if the script was executed
successfully. redirect the stderr and stdout of your script to a log file named $USER_backup.log in /tmp
directory

Q: Will you receive an email from cron if there is no stdout and stderr from scheduled script/program

no

Q: Can you execute a script when another job is successfully completed. i.e. can you have dependency
on jobs

No. You will have to do some shell scripting to perform this task

Q: Can you execute a script when a specific file arrives from another server to your server in a
predefined directory.

Yes. Need shell scripting


Q: How to schedule a job for another use

crontab -u sunil -e <= You must be root to execute this command

Q: How to deny some users from secheduling any jobs on their behalf

Put their username isn /etc/cron.deny file <= You must be root to execute this command

Q: How to allow only few users to schedule cron jobs

Put their username isn /etc/cron.allow file <= You must be root to execute this command

Q: What will happen if a username is in both files (cron.allow & cron.deny)

He will be denied to schedule any jobs

Q: What are the two types of link in UNIX


soft link, symlink, symbolic link

hard link

Q: What is a link

It is another way/name of accessing a file

Windows has a same concept like softlink. Its called a shortcut

Windows does not have a concept link hardlink

Q: What is a soft link

It is a shortcut to the original file

If the original file is deleted the softlink does not work

You can create a softlink for a file or a directory

Softlink points to the inode of the original file

inum of softlink and orginginal file are different

softlink can be created across the UNIX partitions

ln -s /tmp /home/shekhar/abcd

How to create a soft link

ln -s orig_file_name link_name

ln -s /home/shekhar/a.txt /tmp/b.txt

ln -s a.txt b.txt

Q: What is a hardlink

inum of originial file and hardlink are same

sizes/timestamp/owner/permission of originial file and hardlink are same

if original file is deleted, hardlink still works.


hardlink cannot be created across partitions

cp consumes additional disk space , hardlink does not consume additional disk space

How to create a hard link

ln a.txt b.txt

Q: How to find out all hardlinks to your file

find $HOME -inum 558 -print 2> /dev/null (558 is your file's inum)

Q: How many hard links are there to you file

ls -l a.txt (2nd field is the number of hardlink)

Red hat Package Manager = rpm

Day No. 10

---------
Command : rpm

rpm -qa

rpm -qa | grep nmap

rpm -q

rpm -qi

Command : ssh-copy-id

Command : ssh-key-gen

Command : vmstat

Test : No 10

Q: Which command is used to find information about already installed software

rpm -q package_name (e.g rpm -q nmap)

rpm -q software_name

Q: How to get the detailed info of the vsftpd software/package

rpm -qi vsftpd

Q: What version of httpd software has been installed on your system

rpm -q httpd

Q: How to find all packages installed on your system

rpm -qa (a means all)

Q: Is perl or python installed on your system

rpm -qa | grep perl

rpm -qa | grep python

Q: What is the version of perl

rpm -qi perl

Q: have you installed 64 bit or 32 bit version of python

rpm -q python <== look for x64


Q: Which command creates publc and private keys

ssh-keygen

Q: In which dir these keys are stored

$HOME/.ssh

Q: What are the permissions on the private key

rw-------

Q: WHich algorithm is used to encrypt these keys

RSA

Q: How to put your public key in some other user's account

ssh-copy-id student@192.168.0.2

The above command will copy your public key in student's account

on 192.168.0.2 machine. The password of student will be asked.

Q: Where is the public key stored in student's account

~student/.ssh/authorized_keys

Q: How to execute a command on another machine

ssh student@192.168.0.2 'hostname'

Day No. 11
---------

Ad Practicals : No 1

Ad Practicals : No 2

Ad Practicals : No 3

Day No. 12

-----------

Final test (Theory + Practicals)

Networking

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

You might also like