Linux for Devops
Introduction
Linux is not a OS, its a kornel
Linux is not a unix derivative,it was written from scratch
A Linux distribution is contain the Linux kernel and a collection of software together to create OS
There is two type of OS access
CLI(Command Line Interface)
GUI(Graphical User Interface)
Feature of Linux
- Open Source
- Secure
- Light Weight
- Multiuser-Multi task
- Multi distibution-Redhat,federa
- simplified update for all installed software
OS Interface
In Windows- Hardware->OS->Shell->User
In Linux- Hardware->Kernel->Shell->User
Windows file structure
C:/->Program files,users,program(86),logs
Linux File structore
/root,/home,/boot,/etc,/usr,/bin
Naming Convention
Folder->Directory
Adminstrative->Root
File->File
Software->Package
Folder Detail
/home->home directory for other user
/root->it is home directory for root user
/boot->it contains bootable files for Linux(if you change any file,the os will currept issue)
/etc->it controls all configuration files(ram,rom,herd disk detail)
/usr->by default software are installed in this directory
/opt->store option application software packages
/bin->it contains commands used by all user include root
/sbin->it contains commands used by only root user
/dev->essential device files this include terminal devices,usb or any device attached to the system
Basic Commands
All commands in small latter,it is case censitive
sudo su ->to go to root(Admin)
sudo su->super user do switch user ->[root@ip]#
#-> root
sudo su
(ctrl+l) to clear screen
4 Ways to create a File
cat cat >filename then enter(it will go to next line) then type you text then ctrl+d to save and exit . you cant edit the file with this command
touch ->create empty file ->touch file1 file2 file3
- vi/vim ->editor
- nano ->editor
root@ip]# cat >file1
cat command
The cat command is one of the most universal tools,yet all it does is copy standard input to standard output
use cases
1->create file
cat >file1
Type text
(ctrl+d)
To check the file
ls
To check the content of file1
cat file1
code
[root@ip-172-31-3-239 ec2-user]# cat >file1
hello
namaste
(ctrl+d)
[root@ip-172-31-3-239 ec2-user]# ls
file1
[root@ip-172-31-3-239 ec2-user]# cat file1
hello
namaste
To create one more file
[root@ip-172-31-3-239 ec2-user]# cat >file2
hi
samir
[root@ip-172-31-3-239 ec2-user]# ls
file1 file2
[root@ip-172-31-3-239 ec2-user]# cat file2
hi
samir
2->Concat file content
(you can add more text in existing file)
[root@ip-172-31-3-239 ec2-user]# cat >>file2
kumar
[root@ip-172-31-3-239 ec2-user]# cat file2
hi
samir
kumar
3->copy file->To copy the content of x into y
[root@ip-172-31-3-239 ec2-user]# cat file1
hello
namaste
[root@ip-172-31-3-239 ec2-user]# cat file2
hi
samir
kumar
[root@ip-172-31-3-239 ec2-user]# cat file1 file2 >file3
[root@ip-172-31-3-239 ec2-user]# cat file3
hello
namaste
hi
samir
kumar
[root@ip-172-31-3-239 ec2-user]# cat file1 >file2
[root@ip-172-31-3-239 ec2-user]# cat file2
hello
namaste
4->tac->to see the content in button to top
[root@ip-172-31-3-239 ec2-user]# tac file3
kumar
samir
hi
namaste
hello
Touch Command
use cases
1->Create Empty file
[root@ip]# touch file1
[root@ip]#ls
file1
2->create multiple empty file
[root@ip]# touch file2 file3 file4
[root@ip]#ls
file1
file2
file3
file4
write some content using cat command
[root@ip-172-31-3-239 ec2-user]# cat file4
[root@ip-172-31-3-239 ec2-user]# cat >>file4
samira
kumar
[root@ip-172-31-3-239 ec2-user]# cat file4
samira
kumar
3->change all timestamp of a file
[root@ip]# touch file1
[root@ip]# stat file1 (to see the time stamp)
[root@ip-172-31-3-239 ec2-user]# stat file1
File: ‘file1’
Size: 14 Blocks: 8 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 13440599 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-03-28 09:31:12.961889339 +0000
Modify: 2021-03-28 09:31:25.293746741 +0000
Change: 2021-03-28 09:31:25.293746741 +0000
Birth: -
[root@ip-172-31-3-239 ec2-user]# touch file1
[root@ip-172-31-3-239 ec2-user]# stat file1
File: ‘file1’
Size: 14 Blocks: 8 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 13440599 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-03-28 09:45:52.331691145 +0000
Modify: 2021-03-28 09:45:52.331691145 +0000
Change: 2021-03-28 09:45:52.331691145 +0000
Birth: -
4->update only access time of file, modify time of file-
[root@ip]# touch -a file3 (to change access time)
[root@ip-172-31-3-239 ec2-user]# stat file1
File: ‘file1’
Size: 14 Blocks: 8 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 13440599 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-03-28 09:48:27.073895204 +0000
Modify: 2021-03-28 09:45:52.331691145 +0000
Change: 2021-03-28 09:48:27.073895204 +0000
Birth: -
[root@ip]# touch -m file4 (to change modify time)
[root@ip-172-31-3-239 ec2-user]# touch -m file1
[root@ip-172-31-3-239 ec2-user]# stat file1
File: ‘file1’
Size: 14 Blocks: 8 IO Block: 4096 regular file
Device: ca01h/51713d Inode: 13440599 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2021-03-28 09:48:27.073895204 +0000
Modify: 2021-03-28 09:49:21.933259458 +0000
Change: 2021-03-28 09:49:21.933259458 +0000
Birth: -
Type of time stamp
1->Access tile(Last time when a file has access)->touch -a
2->Modify time->(Last time when a file has midified)->touch -m
3->Change time->(Last time when file metadata(file type,file size,file property,file location) was changes )->touch -acces
for all command->stat file1
VI Editor
A programmers text editor
It can be user to edit all kinds of plain text ,it is specially useful for editing programs mainly used for Unix programs
[root@ip]# vi file1
press i
then change data
esc :wq
[root@ip-172-31-3-239 ec2-user]# vi file7
[root@ip-172-31-3-239 ec2-user]# cat file7
hello
programmers
[root@ip]#ls
file1
Note-> :w-TO save file
:wq or :x -to save and quit
:q- quit
:q! -force quit ,no save
nano command
[root@ip]#nano fileb
write text
(ctrl+o)
(ctrl+x)-> shift y ->enter
[root@ip]#ls fileb [root@ip]#cat fileb
[root@ip-172-31-3-239 ec2-user]# nano file8
[root@ip-172-31-3-239 ec2-user]# cat file8
nano content
text editor
Other usefull command
All file with time
[root@ip-172-31-3-239 ec2-user]# ls -l
total 24
-rw-r--r-- 1 root root 14 Mar 28 09:49 file1
-rw-r--r-- 1 root root 14 Mar 28 09:38 file2
-rw-r--r-- 1 root root 29 Mar 28 09:35 file3
-rw-r--r-- 1 root root 13 Mar 28 09:43 file4
-rw-r--r-- 1 root root 0 Mar 28 09:41 file5
-rw-r--r-- 1 root root 0 Mar 28 09:41 file6
-rw-r--r-- 1 root root 18 Mar 28 09:52 file7
-rw-r--r-- 1 root root 26 Mar 28 09:57 file8
[root@ip-172-31-3-239 ec2-user]# ll
total 24
-rw-r--r-- 1 root root 14 Mar 28 09:49 file1
-rw-r--r-- 1 root root 14 Mar 28 09:38 file2
-rw-r--r-- 1 root root 29 Mar 28 09:35 file3
-rw-r--r-- 1 root root 13 Mar 28 09:43 file4
-rw-r--r-- 1 root root 0 Mar 28 09:41 file5
-rw-r--r-- 1 root root 0 Mar 28 09:41 file6
-rw-r--r-- 1 root root 18 Mar 28 09:52 file7
-rw-r--r-- 1 root root 26 Mar 28 09:57 file8
All file with hidden
[root@ip-172-31-3-239 ec2-user]# ls -a
. .bash_history .bash_profile file1 file3 file5 file7 .ssh
.. .bash_logout .bashrc file2 file4 file6 file8
To See History Of Command
[root@ip-172-31-3-239 ec2-user]# history
1 ls
2 cat >file1
3 ls
4 cat file1
5 cat >file2
6 ls
7 cat file2
8 cat >>file2
9 cat file2
10 cat file1 file2 >file3
11 cat file3
12 tac file3
13 cat file1
14 cat file2
15 cat file1 >file2
16 cat file2
17 touch file4 file5 file6
18 ls
19 cat file4
20 cat >>file4
21 cat file4
22 stat file1
23 touch file1
24 stat file1
25 touch -a file1
26 stat file1
27 touch -m file1
28 stat file1
29 ls
30 vi file7
31 cat file7
32 vi file7
33 cat
34 cat file7
35 nano file8
36 cat file8
37 ls -l
38 ll
39 ls -a
40 history
How to create a directory
[root@ip]# mkdir dir1
[root@ip-172-31-3-239 ec2-user]# mkdir dir1
[root@ip-172-31-3-239 ec2-user]# ls
dir1 file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# ls -l
total 20
drwxr-xr-x 2 root root 6 Mar 28 10:50 dir1
-rw-r--r-- 1 root root 21 Mar 28 10:05 file1
create dir inside a dir
dir3 inside dir2 and dir4 inside dir3
[root@ip]# mkdir -p dir2/dir3/dir4
how to go inside one directory
- cd-change directory*
[root@ip-172-31-3-239 ec2-user]# mkdir -p dirc/dird/dire
[root@ip-172-31-3-239 ec2-user]# ls
dir1 dirc dirx diry file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# cd dirc
[root@ip-172-31-3-239 dirc]# ls
dird
[root@ip-172-31-3-239 dirc]# cd dird
[root@ip-172-31-3-239 dird]# ls
dire
[root@ip-172-31-3-239 dird]#
- how to come out from directory*
[root@dir3]# cd ..
[root@dir2]#cd ..
[root@ip]#
[root@dir3]#cd ../..
[root@ip]#
print working directory
[root@dir3]#pwd
/home/ec2-user/dir2/dir3
Go inside folder
[root@ip-172-31-3-239 ec2-user]# cd dirc
[root@ip-172-31-3-239 dirc]# cd dird
[root@ip-172-31-3-239 dird]# cd dire
or
[root@ip-172-31-3-239 ec2-user]# cd dirc/dird/dire
come out
[root@ip-172-31-3-239 dire]# pwd
/home/ec2-user/dirc/dird/dire
[root@ip-172-31-3-239 dire]# cd ../../..
[root@ip-172-31-3-239 ec2-user]#
Inside Root
[root@ip-172-31-3-239 ec2-user]# cd ..
[root@ip-172-31-3-239 home]# cd ..
[root@ip-172-31-3-239 /]# ls
bin dev home lib64 media opt root sbin sys usr
boot etc lib local mnt proc run srv tmp var
[root@ip-172-31-3-239 /]# cd home
[root@ip-172-31-3-239 home]# ls
ec2-user
[root@ip-172-31-3-239 home]# cd ec2-user/
[root@ip-172-31-3-239 ec2-user]#
create more than one dir
[root@ip]# mkdir dir5 dir6
[root@ip-172-31-3-239 ec2-user]# mkdir dirx diry .dirz
[root@ip-172-31-3-239 ec2-user]# ls
dir1 dirx diry file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# ls -a
. .bash_logout dir1 diry file2 file5 .file8
.. .bash_profile .dira .dirz file3 file6 .ssh
.bash_history .bashrc dirx file1 file4 file7
To see all detail of file with hidden file
[root@ip-172-31-3-239 ec2-user]# ls -al
total 36
drwx------ 8 ec2-user ec2-user 262 Mar 28 10:56 .
drwxr-xr-x 3 root root 22 Mar 27 06:45 ..
-rw------- 1 ec2-user ec2-user 8 Mar 27 07:14 .bash_history
-rw-r--r-- 1 ec2-user ec2-user 18 Jul 15 2020 .bash_logout
-rw-r--r-- 1 ec2-user ec2-user 193 Jul 15 2020 .bash_profile
-rw-r--r-- 1 ec2-user ec2-user 231 Jul 15 2020 .bashrc
drwxr-xr-x 2 root root 6 Mar 28 10:50 dir1
drwxr-xr-x 2 root root 6 Mar 28 10:54 .dira
drwxr-xr-x 2 root root 6 Mar 28 10:56 dirx
drwxr-xr-x 2 root root 6 Mar 28 10:56 diry
drwxr-xr-x 2 root root 6 Mar 28 10:56 .dirz
-rw-r--r-- 1 root root 21 Mar 28 10:05 file1
-rw-r--r-- 1 root root 14 Mar 28 09:38 file2
-rw-r--r-- 1 root root 29 Mar 28 09:35 file3
-rw-r--r-- 1 root root 13 Mar 28 09:43 file4
-rw-r--r-- 1 root root 0 Mar 28 09:41 file5
-rw-r--r-- 1 root root 0 Mar 28 09:41 file6
-rw-r--r-- 1 root root 18 Mar 28 09:52 file7
-rw-r--r-- 1 root root 0 Mar 28 10:53 .file8
drwx------ 2 ec2-user ec2-user 29 Mar 27 06:45 .ssh
Hidden File/Folder
add a dot before name
[root@ip]#touch .file9
[root@ip]# mkdir .dir4
- to see hidden file*
[root@ip]# ls -a
[root@ip-172-31-3-239 ec2-user]# touch .file8
[root@ip-172-31-3-239 ec2-user]# ls
dir1 file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# ls -a
. .bash_history .bash_profile dir1 file2 file4 file6 .file8
.. .bash_logout .bashrc file1 file3 file5 file7 .ssh
[root@ip-172-31-3-239 ec2-user]# mkdir .dira
[root@ip-172-31-3-239 ec2-user]# ls
dir1 file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# ls -a
. .bash_history .bash_profile dir1 file1 file3 file5 file7 .ssh
.. .bash_logout .bashrc .dira file2 file4 file6 .file8
How to copy file
[root@ip]# cp source destination
[root@ip-172-31-3-239 ec2-user]# cat file7
hello
programmers
[root@ip-172-31-3-239 ec2-user]# cat file1
hello
namaste
update123
[root@ip-172-31-3-239 ec2-user]# cp file1 file7
cp: overwrite ‘file7’? y
[root@ip-172-31-3-239 ec2-user]# cat file7
hello
namaste
update123
[root@ip-172-31-3-239 ec2-user]#
copy file in dir
[root@ip-172-31-3-239 ec2-user]# [root@ip-172-31-3-239 ec2-user]# ls
dir1 dirc dirx diry file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# cp file1 dir1
[root@ip-172-31-3-239 ec2-user]# ls
dir1 dirc dirx diry file1 file2 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# cd dir1
[root@ip-172-31-3-239 dir1]# ls
file1
How to cut and paste file(move)
[root@ip]# mv souceFile destDir
[root@ip]# mv file1 dir1
[root@ip]# mv dir2 dir1
[root@ip-172-31-3-239 ec2-user]# mv file2 dir1
[root@ip-172-31-3-239 ec2-user]# ls
dir1 dirc dirx diry file1 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# cd dir1
[root@ip-172-31-3-239 dir1]# ls
file1 file2
How to rename filr/directory
[root@ip]# mv file1 fileNewName
[root@ip-172-31-3-239 ec2-user]# ls
dirc dirx diry file1 file3 file4 file5 file6 file7
[root@ip-172-31-3-239 ec2-user]# mv file1 newFile
[root@ip-172-31-3-239 ec2-user]# ls
dirc dirx diry file3 file4 file5 file6 file7 newFile
[root@ip-172-31-3-239 ec2-user]#
[root@ip-172-31-3-239 ec2-user]# ls
dirc dirx diry file3 file4 file5 file6 file7 newFile
[root@ip-172-31-3-239 ec2-user]# mv dirc dirs
[root@ip-172-31-3-239 ec2-user]# ls
dirs dirx diry file3 file4 file5 file6 file7 newFile
[root@ip-172-31-3-239 ec2-user]#
[root@ip-172-31-3-239 ec2-user]# mv dirs .dirs
[root@ip-172-31-3-239 ec2-user]# ls -a
. .bash_logout .dira diry file4 file7 .ssh
.. .bash_profile .dirs .dirz file5 .file8
.bash_history .bashrc dirx file3 file6 newFile
How to remove file or folder
rmdir->this command is used to remove the specified directory(empty)
[root@ip]# rmdir dir1 rmdir-p->Remove both parent and child directory
[root@ip]# rmdir-p dir1
rmdir-pv->Remove all the parent and child
rm -rf->removes even non-empty file and directory [root@ip]# rm -rf dir1
[root@ip-172-31-3-239 ec2-user]# rm -rf file8 rm -rp->removes even non-empty file and directory include parent and subdirectory
rm -r->remove empty directory
rm -rf /home/ec2-user/ -> to remove all file from particular folder with hidden folder
less file1 to come out from less type q
more file1
head file1 ->top 10 tail file1 ->last 10
Linux Basic Command
hostname->to know about machine,version,package,ip
ip-172-31-38-161.ap-south-1.compute.internal
ifconfig-> to know ip of machine
hostname -i-> to know ip of machine
cat /etc/os-release ->to konw version of os
cat /etc/os-rel* ->to konw version of os
yum update -y -> to update all inbuild software
yum install tree -y -> to see the structure of file
[root@ip-172-31-38-161 ec2-user]# tree
.
├── dir1
│ └── dir2
│ └── dir3
├── dir2
├── file1
├── file2
└── file6
yum install httpd ->to install package like httpd
yum install httpd -y ->install package with all option is yes
yum remove httpd -> to uninstall or remove package
yum update httpd ->update installed package
service httpd start ->to start service or package
service httpd status -> to konw service is running or not
chkconfig httpd on ->it will start httpd automatically when vm will start
chkconfig httpd off -> to stop automatically start when os open
yum list installed ->to know all installed package
which ->to know particular software is installed or not
which chef ,which tree
whoami -> to know the role of log on user
echo ->message reflect,who are in the same vm
echo "Hello"
with echo we can create a file
echo "Welcome" >file1
cat file1 Welcome
To add message in same file echo "New Message" >> file1
cat file1
Welcome New Message
To empty file
echo >file1
cat file1 o/p will be empty
grep ->find out certain string in a paagraph
grep root /etc/password ->serach "root" in password file
[root@ip-172-31-38-161 ec2-user]# grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin
sort ->to sort content of file
[root@ip-172-31-38-161 ec2-user]# cat file1
amira
kumar
hello
python
java
aws
[root@ip-172-31-38-161 ec2-user]# sort file1
amira
aws
hello
java
kumar
python
User Permission
useradd - To create user
to see user
cat /etc/passwd
[root@ip-172-31-38-161 ec2-user]# useradd samir
[root@ip-172-31-38-161 ec2-user]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
rpc:x:32:32:Rpcbind Daemon:/var/lib/rpcbind:/sbin/nologin
libstoragemgmt:x:999:997:daemon account for libstoragemgmt:/var/run/lsm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
ec2-instance-connect:x:998:996::/home/ec2-instance-connect:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
rngd:x:997:995:Random Number Generator Daemon:/var/lib/rngd:/sbin/nologin
chrony:x:996:994::/var/lib/chrony:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
ec2-user:x:1000:1000:EC2 Default User:/home/ec2-user:/bin/bash
apache:x:48:48:Apache:/usr/share/httpd:/sbin/nologin
samir:x:1001:1001::/home/samir:/bin/bash
groupadd -To create group
groupadd techskp
cat /etc/group
[root@ip-172-31-38-161 ec2-user]# groupadd samirgroup
[root@ip-172-31-38-161 ec2-user]# cat /etc/group
root:x:0:
bin:x:1:
daemon:x:2:
sys:x:3:
adm:x:4:ec2-user
tty:x:5:
disk:x:6:
lp:x:7:
mem:x:8:
kmem:x:9:
wheel:x:10:ec2-user
cdrom:x:11:
mail:x:12:postfix
man:x:15:
dialout:x:18:
floppy:x:19:
games:x:20:
tape:x:33:
video:x:39:
ftp:x:50:
lock:x:54:
audio:x:63:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
input:x:999:
systemd-journal:x:190:ec2-user
systemd-network:x:192:
dbus:x:81:
ssh_keys:x:998:
rpc:x:32:
libstoragemgmt:x:997:
sshd:x:74:
rpcuser:x:29:
nfsnobody:x:65534:
ec2-instance-connect:x:996:
slocate:x:21:
postdrop:x:90:
postfix:x:89:
rngd:x:995:
chrony:x:994:
screen:x:84:
stapusr:x:156:
stapsys:x:157:
stapdev:x:158:
tcpdump:x:72:
ec2-user:x:1000:
apache:x:48:
cgred:x:993:
docker:x:992:
samir:x:1001:
samirgroup:x:1002:
samir is showing as a group because it is not tagged to any group,so it create own group
[root@ip-172-31-38-161 ec2-user]# useradd ajaya
[root@ip-172-31-38-161 ec2-user]# useradd bikash
-a, --add USER add USER to GROUP
-d, --delete USER remove USER from GROUP
-h, --help display this help message and exit
-Q, --root CHROOT_DIR directory to chroot into
-r, --delete-password remove the GROUP's password
-R, --restrict restrict access to GROUP to its members
-M, --members USER,... set the list of members of GROUP
-A, --administrators ADMIN,... set the list of administrators for GROUP
gpasswd -a/-M ->To add user into group,add multiple user
gpasswd -a sam techskp ->For single
[root@ip-172-31-38-161 ec2-user]# gpasswd -a samir samirgroup
Adding user samir to group samirgroup
gpasswd -M ajaya,sameer,bijaya techskp ->for multiple
[root@ip-172-31-38-161 ec2-user]# useradd samir123
[root@ip-172-31-38-161 ec2-user]# useradd samir456
[root@ip-172-31-38-161 ec2-user]# gpasswd -M samir123,samir456 samirgroup
cat /etc/group
ln ->hardlink ->create a backup automatically
ln file2 backupfile2 ->backupfile2 is backup data of file2 ,both are different file
[root@ip-172-31-38-161 ec2-user]# cat file2
new data added first
nice look
[root@ip-172-31-38-161 ec2-user]# ln file2 backupfile2
[root@ip-172-31-38-161 ec2-user]# cat backupfile2
new data added first
nice look
[root@ip-172-31-38-161 ec2-user]# ls
backupfile2 cat dir1 dir2 file2 file6
[root@ip-172-31-38-161 ec2-user]# ls -l
total 12
-rw-r--r-- 2 root root 31 Mar 31 14:20 backupfile2
-rw-r--r-- 1 root root 0 Mar 31 14:15 cat
drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1
drwxr-xr-x 2 root root 6 Mar 31 13:55 dir2
-rw-r--r-- 2 root root 31 Mar 31 14:20 file2
-rw-r--r-- 1 root root 1 Mar 31 10:55 file6
[root@ip-172-31-38-161 ec2-user]# cat >>backupfile2
added data in bacup file
[root@ip-172-31-38-161 ec2-user]# cat file2
new data added first
nice look
added data in bacup file
[root@ip-172-31-38-161 ec2-user]# cat >>file2
added in actual file
[root@ip-172-31-38-161 ec2-user]# cat backupfile2
new data added first
nice look
added data in bacup file
added in actual file
[root@ip-172-31-38-161 ec2-user]# rm -rf file2
[root@ip-172-31-38-161 ec2-user]# cat backupfile2
new data added first
nice look
added data in bacup file
added in actual file
if you delete source file also backupfile will be there
ln -s ->softlink -> shortcut ->create soortcut from one software
ln -s file1 softfile1 ->softfile1 is shortcut icon of file1,here softfile1 is just face of file1,
[root@ip-172-31-38-161 ec2-user]# cat file1
amira
kumar
hello
python
java
aws
[root@ip-172-31-38-161 ec2-user]# ln -s file1 softlinkfile1
[root@ip-172-31-38-161 ec2-user]# ls
dir1 dir2 file1 file2 file6 softlinkfile1
[root@ip-172-31-38-161 ec2-user]# cat softlinkfile1
amira
kumar
hello
python
java
aws
[root@ip-172-31-38-161 ec2-user]# cat >cat >>file1
new text is added
[root@ip-172-31-38-161 ec2-user]# cat softlinkfile1
amira
kumar
hello
python
java
aws
new text is added
[root@ip-172-31-38-161 ec2-user]# cat >>softlinkfile1
new data added in softlink
[root@ip-172-31-38-161 ec2-user]# cat file1
amira
kumar
hello
python
java
aws
new text is added
new data added in softlink
all data is same because it is a shortcut icon
if you remove original file then icon will be empty
[root@ip-172-31-38-161 ec2-user]# rm -rf file1 [root@ip-172-31-38-161 ec2-user]# cat softlinkfile1 cat: softlinkfile1: No such file or directory
ls -l
[root@ip-172-31-38-161 ec2-user]# ls -l total 8 -rw-r--r-- 1 root root 0 Mar 31 14:15 cat drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1 drwxr-xr-x 2 root root 6 Mar 31 13:55 dir2 -rw-r--r-- 1 root root 52 Mar 31 14:15 file1 -rw-r--r-- 1 root root 0 Mar 30 12:26 file2 -rw-r--r-- 1 root root 1 Mar 31 10:55 file6 lrwxrwxrwx 1 root root 5 Mar 31 14:13 softlinkfile1 -> file1
tar ->Tar is combine multiple folder into one folder like zip in window
tar -cvf dirx.tar dirx
dirx/diry/dirz
cvf-create verbrose forcefully
gzip ->gzip is for compression of file size gzip dirx.tar
dirx.tar.gz
gunzip dirx.tar.gzip ->to uncompress
tar -xvf dirx.tar ->to extract
[root@ip-172-31-38-161 ec2-user]# tree
.
├── backupfile2
├── cat
├── dir1
│ └── dir2
│ └── dir3
├── dir2
└── file6
4 directories, 3 files
[root@ip-172-31-38-161 ec2-user]#
[root@ip-172-31-38-161 ec2-user]# tar -cvf dir1.tar dir1
dir1/
dir1/dir2/
dir1/dir2/dir3/
[root@ip-172-31-38-161 ec2-user]# ls
backupfile2 cat dir1 dir1.tar dir2 file6
[root@ip-172-31-38-161 ec2-user]# ls -l
total 20
-rw-r--r-- 1 root root 77 Mar 31 14:25 backupfile2
-rw-r--r-- 1 root root 0 Mar 31 14:15 cat
drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1
-rw-r--r-- 1 root root 10240 Mar 31 14:30 dir1.tar
drwxr-xr-x 2 root root 6 Mar 31 13:55 dir2
-rw-r--r-- 1 root root 1 Mar 31 10:55 file6
[root@ip-172-31-38-161 ec2-user]# gzip dir1.tar
[root@ip-172-31-38-161 ec2-user]# ls
backupfile2 cat dir1 dir1.tar.gz dir2 file6
[root@ip-172-31-38-161 ec2-user]# ls -l
total 12
-rw-r--r-- 1 root root 77 Mar 31 14:25 backupfile2
-rw-r--r-- 1 root root 0 Mar 31 14:15 cat
drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1
-rw-r--r-- 1 root root 148 Mar 31 14:30 dir1.tar.gz
drwxr-xr-x 2 root root 6 Mar 31 13:55 dir2
-rw-r--r-- 1 root root 1 Mar 31 10:55 file6
[root@ip-172-31-38-161 ec2-user]# gunzip dir1.tar.gz
[root@ip-172-31-38-161 ec2-user]# ls -l
total 20
-rw-r--r-- 1 root root 77 Mar 31 14:25 backupfile2
-rw-r--r-- 1 root root 0 Mar 31 14:15 cat
drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1
-rw-r--r-- 1 root root 10240 Mar 31 14:30 dir1.tar
drwxr-xr-x 2 root root 6 Mar 31 13:55 dir2
-rw-r--r-- 1 root root 1 Mar 31 10:55 file6
[root@ip-172-31-38-161 ec2-user]# tar -xvf dir1.tar
dir1/
dir1/dir2/
dir1/dir2/dir3/
[root@ip-172-31-38-161 ec2-user]# ls -l
total 20
-rw-r--r-- 1 root root 77 Mar 31 14:25 backupfile2
-rw-r--r-- 1 root root 0 Mar 31 14:15 cat
drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1
-rw-r--r-- 1 root root 10240 Mar 31 14:30 dir1.tar
drwxr-xr-x 2 root root 6 Mar 31 13:55 dir2
-rw-r--r-- 1 root root 1 Mar 31 10:55 file6
[root@ip-172-31-38-161 ec2-user]# rm -rf dir1
[root@ip-172-31-38-161 ec2-user]# ls
backupfile2 cat dir1.tar dir2 file6
[root@ip-172-31-38-161 ec2-user]# tar -xvf dir1.tar
dir1/
dir1/dir2/
dir1/dir2/dir3/
[root@ip-172-31-38-161 ec2-user]# ls
backupfile2 cat dir1 dir1.tar dir2 file6
wget ->to download software
wget
wget packages.chef.io/stable/el/7/chefdk-0.11.2-..
yum install chefdk-0.11.2-1.el7.x86_64.rpm
for copy over in name the click right in paste location
[root@ip-172-31-38-161 ec2-user]# which chef /bin/chef
rm -rf * ->to remove all file and folder
Access to User
chmod-used to change the access mode(permissions) of a file
chown-change the owner of file or dir
chgrp -change group of file
-rw-r--r-- 1 root root 1 Mar 31 10:55 file6
- ->file
rw- -> (first 3)owner
r-- -> (next 3)for group
r-- -> (next 3) other
1 ->symbolic link
root -> first root ->owner name
root ->second root -> group name
1 -> file size
drwxr-xr-x 3 root root 18 Mar 31 10:26 dir1
d- directory
first 3 -> rwx ->owner permissions
second 3 -> r-x ->group permissions
third 3 ->r-x ->other user permissions
18 folder size
r-read, w- write, x-execute
4 is decimal value of r
File Directory
r ->4 -> to display the content(for file) to list the content(for directive)
w ->2 ->to modify (for file)
to create or remove(for directive)
x -> 1 ->to execute file(for file)
to enter into file(for directive)
drwxr-xr-- 3 root root 18 Mar 31 10:26 dir1
rwx ->4+2+1->7
r+x ->4+0+1=5
r->4 if you want this d rwx rwx rwx
7 7 7
chmod 777 dir1
r-x -wx r--
5 3 4
chmod 534 file1
chmod 700 file1
- rwx --- ---
chmod 536 file1
- r-x -wx rw-
another method
u->user/owner g->group o->other
u=r-w for user r-w u-w r--
u+x r-x
chmod u-wx,g+w,o=wx file1
[root@ip-172-31-38-161 ec2-user]# ls -l
drwxr-xr-x 2 root root 6 Mar 31 15:40 dir1
-rw-r--r-- 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod 777 dir1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rw-r--r-- 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod 700 file1
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rwx------ 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod 755 file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rwxr-xr-x 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rwx------ 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod g=r,o=rw file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rwxr--rw- 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod u=r,g=rwx,o=x file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-r--rwx--x 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod u+w,g-x,o=xr file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rw-rw-r-x 1 root root 0 Mar 31 15:40 file1
chown sam file1 ->change owner to sam
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 root root 6 Mar 31 15:40 dir1
-rw-rw-r-x 1 root root 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chown samir dir1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 samir root 6 Mar 31 15:40 dir1
-rw-rw-r-x 1 root root 0 Mar 31 15:40 file1
chgrp samgroup file1 ->change group name to samgroup
[root@ip-172-31-38-161 ec2-user]# chgrp samirgroup file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 samir root 6 Mar 31 15:40 dir1
-rw-rw-r-x 1 root samirgroup 0 Mar 31 15:40 file1
[root@ip-172-31-38-161 ec2-user]# chmod 000 file1
[root@ip-172-31-38-161 ec2-user]# ls -l
total 0
drwxrwxrwx 2 samir root 6 Mar 31 15:40 dir1
---------- 1 root samirgroup 0 Mar 31 15:40 file1
That's all for this blog. This is very long post which cover basic of Linux command,I hope you enjoyed yet.