ls * list file and directory
ls -l *long list file and directory , ll
ls -R *listing the file and directory with recurrsive.
ls -laR
pwd *present working direcory
cd dirname *enter a directory
cd.. back one directory cd - * to enter
cd ../.. *two level dir back
cd/ *root partition
cd and enter * to enter users home directory , "cd~"
rm filename *Remove file
rmdir directory_name * Remove directory (If empty)
rm -r dirname *Remove directory (If not empty) (r -> recurrsive).
rm -rf dirname *Remove directory and file forcefully.
cp filename destination_address *to copy file.
cp -a dirname destination_address *to copy directory.
mv - filename/dirname newname *to rename
mv - filename/dirname destination_address *to move file or directory.
Command /syntax
command option argument
[root@localhost Desktop]#
user machine using dir root user
$ Local user
useradd username or adduser username (with root permissions only)
to chg password -> passwd username
#newpassword ******
File System Hierarchy
/ is root directory
/bin user essential commands
/sbin Superuser essential commands
/dev to store device files
/boot Its a bootloader (to store required booting file) Grub2 (Grand unified Bootloader)
/etc to store configuration file.
/root root user data.
/tmp temporary directory (after 10 days file will be deleted automatically)
/usr to install programs.
/var Its a variable data (different types of files available )
/var/log for logs /var/tmp after 30 days /var/spool/mail mail
/run/media removable drives (For rhel 6 and old in /media directly)
vim - Text Editor.
1.) Command Mode vim filename.
2.)Insert Mode - Edit or Modify file . press 'i' or Insert key.
3.)Ex Mode close a file with saving or not saving. ESC key
to save file :wq (close file with save)
:wq! (save forcefully)
:q (without saving)
ESC o open a new line below from cursor
ESC u undo
ctrl + r redo
ESC n yy
no of lines yy(yanked)
ESC p paste copied data
ESC :7,12 copy between lines
Search and replace -> :%s/oldwordname/newname/g
search global
ESC /word_name to search a word n-> next find match word shift+n -> previous
ESC :nohl No Highlighted
ESC :set nu to set line numbers
ESC :set nonu remove or unset line numbers
ESC gg First line
ESC shift+g last line
ESC :line_number
View content of a file
cat filename
less filename view content page wise
more filename view content page wise show % studied
head filename (first 10 lines)
head -n3 filename (first n lines)
tail filename (last 10 lines)
head -n3 filename (last n lines)
wc filename (show line,word,size)
Help
whatis cmd_name
man cmd_Name
info cmd_Name more details then man
which cmd_Name from where cmmd is running
rpm -q -f /usr/bin/mv to know the package
Users and Groups :
3 types of users
1.) SuperUser - rootuser user Id '0'
2.)System user -to manage and create system services.
3.)Regular user/local start from 1000(RHEL7) 500(Rhel 6)
1-201 (Static-Id) 201-999(dynamic Id)
id - current user id
id username - user id
userdel -r username delete user
usermod -L username
usermod -U username
usermod -l newname oldname
chfn username - change info about user
chage -l username to check age on an user
chage -E "days/weeks/year" username expire
chage -E -1 username unexpire
chage -m 5 -M 45 -I 3 -W 2 mustfzz *min max inactive warning
chage -m 0 -M 99999 -I -1 -W 7 mustfzz *bring back to original
Group Users
groupAdd group_name
groupmod -n newname oldname
usermod -G groupname username
usermod -G groupname,group2,group3 username
gpasswd -M user1,user2,user3 groupname
groupmems -g groupname -l *list of user in a group
groupmems -d username -g groupname *delete user from group
groups mustfzz display group info
IT:x:1004:mustfzz
groupname:password:Group_iD:list_of_users_in_group
userfields in passwd file 7
username:password:user_id:group_id:user_comments:users_home_dir:users_shell
password stored in /etc/shadow stores username/password/age information
shadow has 9 fields.
username:password:user_creation_no_of_days:min_days:max_days:warning_days:inactive_days:user_account_age_info:future_reserve
Linux File System Permissions
File has three categories
1.) User
2.) Group
3.) Others
UMASK controls the permission automatically
permissions r-w-x
file dir
r
rw
rwx rwx
--- rx
- --- --- --- . +
file_type : User_permission : Group_premission : Other_permission ACL
_ file
d dir
l Link File
--------------------
b block file |
c character file | =>h/w device (in /dev)
p pipe file |
s socket file |
--------------------
Switch User (from one to another from terminal)
su - username
Symbolic
---------------
who - u,g,o,a
what - +,-,=
which - r,w,x
cmmd/syntax - chmod whoWhatWhich file/dir_name
chmod g+w file/dir_name
chmod -R whoWhatWhich file/dir_name
chmod -R g+w file/dir_name
chmod go+wx file/dir
chmod a+rwx file/dir
chmod g+wx,o-rx file/dir
Numeric
r-4
w-2
x-1
--0
stat file/dir show the permissions of file/dir in symbolic and numeric method
Changing User and Group Ownership
chown user/owner_name file/directory_name * change ownership
chown -R user/owner_name file/directory_name * Reccurrsive
chgrp group_name file/dir
chown username:groupname file/dir_name * to change user and group ownership (-R for reccurrsive)
Special Permissions
1.) Suid (Set user id) - when only particular user can execute. this time permission apply on user execution position. (i.e. in place of --x).
Symbol - 's' and no. 4 . It can only be applied to file.
ex: _rwsr_xr_x
chmod 4755
here 4 is for special permissions.
2.) Sgid
sgid assign on group execute position that mean place of x
when sgid is set on a directory then files new created in the directory have there group owner set to match the group owner of the directory.
symbol - 's' and no. 2
Ex chmod 2775 directory
3.) Sticky
It assings on a directory
It assign on other execute postion.
When sticky is set on a directory then file/dir created under this directory , then
only file/dir deleted by only owner.
Symbol 't' and no. '1'
EX: chmod 1757 litc/a
Break Root Password
Rhel 6
Enter in kernel mode by s
passwt root
and then Enter the new password
Rhel 7
ctrl+alt+del then e
take to linux16 then to end and rd.break
Archiving files creating and Compressing
---------------------------------------------------------
Tar (tape archive)
The archive file creates from Tar command.
tar -cvf filename.tar files/dirname
create verbose file
tar -tvf filename.tar
to list file/dir from
tar -rvf filename.tar
to add files and directory if already archive file existing
tar -xvf filename.tar
to restore particular file and directory from archive file
After Tar
1.) gzip | gzip filename.tar
gunzip filename.tar.gz
2.) bzip2 | bzip2 filename.tar
bunzip filename.tar.bz2
3.) xz | xz filename.tar
unxz filename.tar.xz
tar -czvf filename.tar.gz file/dirname -> gzip
tar -cjvf filename.tar.bz2 file/dirname -> bzip2
tar -cJvf filename.tar.xz file/dirname -> xz
UMASK
-------------------------------------------
It is a value that controls file/dir permission.
without umask file permission 666 | directory permission 777
localuser mask 002 and root user mask 022
to calculate umask Default Mask - Required Mask
Ex:
[u1@localhost ~]$ vim ~/.bash
[u1@localhost ~]$ vim ~/.bashrc
add umask 007 at the end
Permanent for all user
root user
vim /etc/bashrc
change 002 to 007
Repeat the same for /etc/profile
ACL (Access Contol List)
---------------------------------------------
when we want to multiple permission assing one a single target file/dir and access by user and group then we can implement ACL.
getfacl file/dir * to get acl info
setfacl -m u:username:permission file/dirname * set acl
setfacl -m g:groupname:permission file/dirname * set acl
on group
EX: setfacl -m u:mustfzz:rw file/dirname
setfacl -x u:username file/dirname * remove permissions
setfacl -b file/dirname * remove all acl
Link - Hard Link and Soft Link
------------------------------------------------
1.) can create only within a partition 1.) can create accross the partition
2.) Inode number will be the same 2.) Inode number are different
3.) original and link file are in same size. 3.) size is less than original file.
4.) If original file is removed then we can access the link file 4.) Link file can not be accessed
5.) Only for file 5.) for file and directory.
Link is an another name of our original file.
df -TH * show partitions
ls -il file/dirname * show inode number
ln file/dirname link-file/dirname
unlick file/dirname * unlink and file will be deleted
Find Files and Directory
------------------------------------------
by name * -name
by size * -size 10m | +5m | -5m
by permission * -perm 755
by ownername and ownership * -user username
by groupname * -group groupname
by uid and gid
by File-Type * -type f(file) d(directory) l(linked) b(block) c() p(pipeline) s(socket)
particular extention *.txt
by no of days access time * atime 5days | +5days | - days
by no of minutes * amin | mmin (m for modification time).
by links * find / -type f -links 2 | +2 | -2
Search and save file
find / - user mustfzz -exec cp -av {} /destination_address \;
Syntax
find path file/dirname * whole system
find /etc file/dirname * particular directory
find -name file/dirname * working directory
Using Grep
--------------------------------------------------
to find particular string
grep stringname filename
grep --color stringname filename 8 with color for rhel 6
grep ^stringname filename | start
grep stringname$ filename | end
grep -e stringname -e stringname filename
grep --color stringname filename >> path/filename
Sudo
--------------------------------------------------
Sudo gives root priveledges to the local user.
If any is a member of wheel group It can execute root commands.
vim /etc/sudoers
NETWORKING
----------------------------------------------------------
Lan Cable
4-Pair
1) Cross-over cale
2) Straight cable
3) Roll-over cable /console cable
IP-Address
class - A 1-127
class - B 128-191
class - C 192-223
class - D 224-239
class - E 240-255
Private Ip Range
class - A 10.0.0.0
10.255.255.255
class - B 172.16.0.0
172.31.255.255
class - C 192.168.0.0
192.168.255.255
Subnet Mask
Its a property of IP address.
CIDR
class - A 255.0.0.0 /8
class - B 255.255.0.0 /16
class - C 255.255.255.0 /24
CIDR (Class-Less Inter Domain Routing)
Total Host and Total N/W in each classes
class A 1 00000001
127 0111111111
2^7 = 127 N/W
2^24 = 16777216-2 = 16777214
Class B
128 10000000
191 10111111
2^14 = 16384 N\W
2^16 = 65534 Total host
65532 Valid host
Class C
192 11000000
223 10111111
2^21 = 16384 N\W
2^8 = 256 Total host
254 Valid host
CIDR (/8-/32 {/9-/30}) and Subnet Mask calculation.
/8 255.0.0.0
/9 255.128.0.0
/10 255.192.0.0
/11 255.224.0.0
/12 255.240.0.0
/13 255.248.0.0
/14 255..252.0.0
/15 255.254.0.0
/16 255.255.0.0
/17 255.255.128.0
/18 255.255.192.0
/19 255.255.224.0
/20 255.255.240.0
/21 255.255.248.0
/22 255.255.252.0
/23 255.255.254.0
/24 255.255.255.0
/25 255.255.255.128
/26 255.255.255.192
/27 255.255.255.224
/28 255.255.255.240
/29 255.255.255.248
/30 255.255.255.252
Subnetting :
To breakup large network into small using subnetting.
Rules
1.) Class IP-Address
2.)Subnet MAsk
3.)Blocksize (256-Mask)
4.)Subnetwork id -(First valued Host | Last Valued Host | Broadcast Address )
5.)Total Host on each subnetwork id - 2^x-2 x= off bit of host part.
6.)Total Subnetwork id 2^y where y = on bit of host part.
class c
1.) 192.168.10.0 /26
2.)subnet mask 255.255.255.192
11000000
3.)block size 256-192 = 64
4.)subnet id
FVH LVH B/C
192.168.10.0 10.1 10.62 10.63
192.168.10.64 10.65 10.126 10.127
192.168.10.128 10.129 10.190 10.191
192.168.10.192 10.193 10.254 10.255
5.)Total Host on each subnetwork id = 2^6-2=62
6.) TOTAL SUBNET ID 2^2 =4
Networking
-----------------------------
N/W address
IP address
Subnet Mask
Gateway
DNS
DHCP
Rhel 6
setup
service network restart
cat e