0% found this document useful (0 votes)
12 views28 pages

Linux13 July

The document outlines tasks and commands related to Linux shell scripting and file management, including creating soft and hard links, scheduling tasks with 'at' and 'cron', and managing user passwords. It provides examples of using commands like 'tar', 'gzip', and 'vi' editor for file operations, as well as user management techniques. Additionally, it includes exercises for practical application of the discussed commands and concepts.

Uploaded by

Aman Jha
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)
12 views28 pages

Linux13 July

The document outlines tasks and commands related to Linux shell scripting and file management, including creating soft and hard links, scheduling tasks with 'at' and 'cron', and managing user passwords. It provides examples of using commands like 'tar', 'gzip', and 'vi' editor for file operations, as well as user management techniques. Additionally, it includes exercises for practical application of the discussed commands and concepts.

Uploaded by

Aman Jha
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
You are on page 1/ 28

Day -2

To do :
1. head vs tail
2. less vs more
3. copy a file
4. soft vs hard link
5. input /output var in shell scripting
6. input and output rediection
7. open different terminal (alt ctrl f1 — alt ctrl f6)
8. man , info , help

Q: soft vs hard link

cat >a.txt
hi thisis my file

--how to make a soft link


ln -s a.txt dest.txt
ls -l
ls lia
rm a.txt
ls -l
Q: doest dest.txt is valid ?
sol: does't exist

Q: hard link
cat >a.txt
hi thi sis file

ln a.txt hard.txt
ls -lia

rm a.txt

Q: doest hard.txt is valid ?


sol: yes

day-3:
@@@@@@@@@@@@@@@@@2
16-july-24
Common Activity
1. at command
2. crontab command
3. gzip and tar file
4. info , man ,what , where ,which ,locate
5. grep vs egrep vs find
6. Activity based on vi editor
7. user password management
8. how to add a new hard disk in linux
9. how to merge 2 hard disk in link
example: add 2 hard disk of 20gb each and merge into
single(40 GB)

Note: (To do )
yellow color
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@
at command:
-- "at" command is one time job
-- This is used to schedule one time job.
-- No repeat execution
Q: how to schedule task:
--way1:
>atq
>at -l
[root@sumedha ~]# at now +1min
echo "hi everyone"
press ctrl+d

>atq
>at -l

--way2:
-- schedule another job
[root@sumedha ~]# echo "Anayze part" |at 7:53 pm jan 21
>atq

-- way3:
Q: how to schedule a file
[root@sumedha ~]# cat > a.txt
var1=10
var2=20
let sum=var1+var2
echo $sum
echo "This is task"
[root@sumedha ~]# at -f a.txt now +1 min
job 9 at 2021-01-15 19:59
[root@sumedha ~]# atq
9 2021-01-15 19:59 a root
[root@sumedha ~]#

Q: how to list all schedule jobs:


>atq
>at -l

Q: how to remove scheduled job


> at -d jobid
or
>atrm jobid

=================================================
https://www.computerhope.com/unix/uat.htm

https://linuxize.com/post/at-command-in-linux/#:~:text=at%20is%20a%20command%2Dline,
at%20are%20executed%20only%20once.

https://www.thegeekstuff.com/2010/06/at-atq-atrm-batch-command-examples/

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

cron job

>crontab -l
-- to create a new cronjob
note:
create 2 files named /root/a.txt, /root/b.txt
--> a.txt
echo "hi this is demo file"
--> b.txt
v1=9
v2=90
let sum=v1+v2
echo $sum
echo $(date)
echo $(cal)
----now ----->
>crontab -e
esc+i
format
min hour date month file
18 8 15 jan fri /root/a.txt
20 8 15 jan fri /root/b.txt
press esc+:wq

>crontab -l
Q: how many jobs are scheduled?

https://tecadmin.net/crontab-in-linux-with-20-examples-of-cron-schedule/

https://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/

https://www.tecmint.com/11-cron-scheduling-task-examples-in-linux/

execise:
create a corn job to run a.txt daily at 8AM

@@@@@@@@@@@@@@@@@@@@@@@@@@22

[root@sumedha /]# cat /etc/passwd > a.txt


[root@sumedha /]# wc -c a.txt
1691 a.txt
[root@sumedha /]# gzip a.txt
[root@sumedha /]# wc -c a.txt
wc: a.txt: No such file or directory
[root@sumedha /]# ls
a.txt.gz d1 home lost+found mnt proc selinux tmp
bin dev lib media net root srv usr
boot etc lib64 misc opt sbin sys var
[root@sumedha /]# wc -c a.txt.gz
707 a.txt.gz
[root@sumedha /]#

https://www.geeksforgeeks.org/gunzip-command-in-linux-with-examples/

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

tar : The archival program

For creating a disk archive that contains a group of files or an entire directory structure, we
need to use tar.
-c create an archive

-x extract files from archive

-t display files in archive

-f arch specify the archive arch

Only one these key options can be used at a time.

Creating an Archive (-c) :-

to create an archive , we need to specify the name of the archive (with -f) , the copy or write
operation (-c) and the filenames as arguments. Additionally we'll use the -v (verbose) option
to display the progress while tar works.

example:
-- create file --> file1 file2 file3 file4 file5
--> make archiving file:
$>tar -cvf abc.tar file1 file2 file3 file4 file5
>ls
--> to see tar contents :
$>tar -tvf abc.tar
[root@sumedha ~]# mkdir dd1
[root@sumedha ~]# ls
[root@sumedha ~]# mv abc.tar dd1
[root@sumedha ~]# ls
[root@sumedha ~]# cd dd1
[root@sumedha dd1]# ls
-- how to extract tar file
>tar -xvf a.tar
>ls

exercise:
In the following example, tar fills the archive progs.tar with three directory structures

tar -cvf progs.tar c_progs java_progs shell_scripts

----------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@
Q: user password management

User passwords on Linux systems can be configured to be permanent or can be set to


expire so that individuals must reset them periodically. Periodic password changing is
generally considered good practice for security reasons, but is not configured by default.
-- To view and modify password-aging settings,
[root@localhost ~]# chage -l u1

[root@localhost ~]# passwd -S u1


here:
The seven fields here represent:

1 – username
2 – account status (L=locked, NP=no password, P=usable password)
3 – date of the last password change
4 – minimum age for a change (password cannot be changed if it isn’t this many days old)
5 – maximum age (password must be changed by the time it gets this many days old)
6 – number of days before a required change that warnings will be provided
7 – number of days after password expires before it is locked (made inactive)

---------------------------------------------------------
demo:
-- to check user lock status
# passwd --status u1
or
#passwd -S u1

Q: lock a user
# passwd -l u1
or
# usermod -lock u1
or
#usermod -L u1
# passwd --status u1

now switch user frm gui and login with "u1"


note:
it should give "authentication failed"

Q: how to unlock user


again login in root user from "GUI"
# passwd -u u1
#passwd --status u1

Q:how to check user account status


#passwd --status u1

This will show a short information about the status of the password for a given account.

LK: Password locked


NP: No password
PS: Password set

or
# cat /etc/shadow

https://www.tecmint.com/manage-user-password-expiration-and-aging-in-linux/

https://linoxide.com/linux-command/password-expire-chage-command/

https://www.cyberciti.biz/faq/linux-howto-check-user-password-expiration-date-and-time/

https://www.techrepublic.com/article/how-to-manage-linux-password-expiry-with-the-chage-c
ommand/

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Q: how to disable user login
#usermod -s /sbin/nologin u1
# grep u1 /etc/passwd
try to login from GUI mode

Q: how to enable user login


# usermod -s /bin/bash u1

Q: How to lock or unlock multiple users?(not completed)

https://www.2daygeek.com/lock-unlock-disable-enable-user-account-linux/

step-1: create 4 users(u1,u2,u3,u4)


step2: create a file(userlist.txt)
# cat userlist.txt
u1
u2
u3
u4

Q: how to check user lock status

Q: lock and unlock user account


Q: expire user acocunt
Q: change password of user
Q: changing the shell of a user
@@@@@@@@@@@@@@@@@@@@

Q: info:
infocommand reads documentation in the info format. It will give detailed information for a
command when compared with the man page. The pages are made using the texinfo tools
because of which it can link with other pages, create menus and easy navigation.

Syntax:

info [OPTION]... [MENU-ITEM...]


Options:

-a, –all: It use all matching manuals.


-k, –apropos=STRING: It look up STRING in all indices of all manuals.
-d, –directory=DIR: It add DIR to INFOPATH.
-f, –file=MANUAL: It specify Info manual to visit.
-h, –help: It display this help and exit.
-n, –node=NODENAME: It specify nodes in first visited Info file.
-o, –output=FILE: It output selected nodes to FILE.
-O, –show-options, –usage: It go to command-line options node.
-v, –variable VAR=VALUE: It assign VALUE to Info variable VAR.
–version: It display version information and exit.
-w, –where, –location: It print physical location of Info file.

================================
Q: whatis
whatis command in Linux is used to get a one-line manual page descriptions. In Linux, each
manual page has some sort of description within it. So this command search for the manual
pages names and show the manual page description of the specified filename or argument.

whatis -d: This option prints the debugging information.


$>whatis -d ls
--------------------------
whatis -v: This option will prints verbose warning messages.
Example:

$>whatis -v ls

------------------
whatis -r : This option interprets each of the name as a regular expression. If any of the
names match any part of a page name, a match will be made. This option causes the whatis
command to be somewhat slower due to the nature of database searches.

$>whatis -r ls
----------------------------
whatis -w : This option interprets each name as a pattern containing shell style wildcards.
For a match about to make, an expanded name needs to match the entire page name. This
option causes the whatis command to be somewhat slower due to the nature of database
searches.

$>whatis -w ls
----------------------------------
whatis -l: This option does not trim output to the terminal width. Normally, the output will be
truncated to the terminal width just to avoid ugly results from poorly-written NAME sections.

$>whatis -l cat

------------------------
Activity (VI)
https://www.microsoft.com/en-us/evalcenter/evaluate-windows-10-enterprise

1. root user and general user


2. switching user
3. set user password
4. use different terminal for login with differnt user
5. basic commands
pwd,man,cd,cd .., cd /,mkdir,rmdir,ls,cp,mv,rm,cat,cat>,cat>>,vi,touch
-- how to see present working directory
-- how to see linux manuals
-- make directory
-- switch current directory
-- list all existing file and directory in curremt path
-- ways to create file
-- how to append/modify an existing file
-- copy, cut,remove file or directory

Exercise:
1. create a directory named 13_d1
2. make 13_d1 as present workimg directory
3. create 3 empty files named t1,t2 and t3
4. come one step back
5. list all contents of directory 13_d1
6. make a new directory 13_d2
7. how many files and directory present in directory 13_d2
8. create a file named "t4.txt" in 13_d1 and write 3 lines in it .
9. how many files exist in 13_d1 directory
11. copy t4.txt in 13_d2 directory
12. check is it copied with content or not
13. delete all files and directory from 13_d2 directory
14. copy all the files along with contents from directory 13_d1 to 13_d2
15. vi commands(esc i,o,O,w,q,wq,x,q!,A,I,r,x)
16. what is directory
17. ls vs ls -t vs. ls -l
18. command to delete all files and subdirectory from a directory (with/without confirmation)
19. maximum length of a file and the complete path ?
20. once you create a file named t1.txt
-- how many ways to create this file
-- how to see the contents of this file
-- how you can append this file
21. command to see linux version
22. what is prompt for general user and root user
23. create a directory hierarchy d1/d2/d3/d4/d5

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@

how to read data

vi a.txt
clear
whoami
echo "Good morning"
echo "enter you name "
read x
echo "hello $x"

$>sh a.txt
$chmod u+x a.txt
$> ./a.txt

--common practice for participants


1. Vi Editor
2. Shell scripting
3. Activities based on shell script
4. copy from host machine(windows) to vm Linux machine
5. commands link 6.
How to reset root password (if you miss or forget root password)
7. Groupwise assignment

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Q: common task in group


Note: common activities are highlight with Green color

1. vi editor commands and activity


Hint:
Activity : (10-15 min):
vi a.txt
esc+i --> hi this is demo
esc+o --> cursor come in next line (this is open mode)
esc+a ---> keep cursor in mid of statement and start writting
esc+r --> keep cursor in any character position and replace it
esc+A
:w
:q
>vi a.txt
this is same demo
press --> :wq(save and quit) or :x
>cat a.txt
>vi a.txt
Hi everyone
press --> :q!(quit without save)
>cat a.txt
>vi a.txt
:set nu ---> represent data with line numbering to the text
------------------------------------
remove data from vi editor :
x - removes a single characters from current cursor position

dW - removes a word from current cursor position

dd - removes an entire line from current cursor position

------------------------------------------------
----> create a file named "a.txt" --> insert 10 rows
Additional operations:
:1co3 - first line copying to 3rdline

:1,3co5 - first 3 lines copying to 5th line

:2mo4 - second line moves to 4th line

:2,4mo6 - from second line to 4th line moving 6th line

:2d - deletes second line

:1,4d - deletes first 4 lines

------------------------------------------
practice :
exercise:
Q1. create a file named "test1.txt" in home directory , Add 3 lines --> save and exit.

Note:
Hi Good Morning,
This is my new file
I am Learning Linux

Q2:Represent data from file "test1.txt" on terminal

Q3: Edit "test1.txt" file


replace the follwing characters
Capital (L)-->small (l)
Capital (M)---> small (m)
--> save the file
--> position cursor on 2nd line --> enter esc+o
Note:
The cursor position should be in line3
--> write in 3rd line (Hi data is modified now)
--> save and quit from the vi editor

2. shell scripting (loops and control)

HInt :
-----shell scripting -

$> if.sh
if [ $a == $b ]
then
#If they are equal then print this
echo "a is equal to b"
else
#else print this
echo "a is not equal to b"
fi

-----------------
$> vi for.sh
for a in 1 2 3 4 5 6 7 8 9 10
do
# if a is equal to 5 break the loop
if [ $a == 5 ]
then
break
fi
# Print the value
echo "Iteration no $a"
done

$> while.sh
a=hello
while [ "$a" != "bye" ]
do
echo "Please type something in (bye to quit)"
read a
echo "You typed: $a"
done
---------------
$>while.sh
num=1
while [ $num -le 5 ]
do
read var
if [ $var -lt 0 ]
then
break
fi
num=`expr $num + 1`
done
echo “The loop breaks for negative numbers”

task:
1. fabonacci series
https://www.geeksforgeeks.org/fibonacci-series-bash/

2. armstrong number
https://www.studentcpu.com/2009/05/linux-sehll-program-for-finding_259.html

3. https://www.softwaretestinghelp.com/unix-switch-case/

4. https://teachics.org/examples/linux-shell-scripts/shell-program-to-find-the-area-of-a-circle/
5. https://www.tutorialsandyou.com/bash-shell-scripting/area-of-a-rectangle-40.html

6. using switch case


1. area of circle
2. area of rectangle
3. wrong choice

3. How to copy host machine file "c:\a.txt" in linux machine


root/Desktop/a.txt

HInt
---use scp command
--use tool winscp

4. common activity for the review (Activity )

1. man command
https://www.geeksforgeeks.org/man-command-in-linux-with-examples/

2. wc command
https://www.geeksforgeeks.org/wc-command-linux-examples/

3.ls command
https://www.tecmint.com/15-basic-ls-command-examples-in-linux/

4. mv command
https://www.geeksforgeeks.org/mv-command-linux-examples/

5. cp command
https://www.geeksforgeeks.org/cp-command-linux-examples/

6. rm command
https://www.geeksforgeeks.org/rm-command-linux-examples/

7. mkdir command
https://www.geeksforgeeks.org/mkdir-command-in-linux-with-examples/

8. cd command
https://www.geeksforgeeks.org/cd-command-in-linux-with-examples/

9. pwd command
https://www.geeksforgeeks.org/pwd-command-in-linux-with-examples/#:~:text=pwd%20stan
ds%20for%20Print%20Working,path%20of%20the%20current%20directory.
10. touch command
https://www.geeksforgeeks.org/touch-command-in-linux-with-examples/

11. cat command


https://www.geeksforgeeks.org/cat-command-in-linux-with-examples/#:~:text=Cat(concatena
te)%20command%20is%20very,some%20frequently%20used%20cat%20commands.

Q5:
HOw to colpy vm1 file in vm2(how to manke communication between to vm machines)

Q6: How to reset root password (if you miss or forget root password)

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@

Activity -3 (Group ACtivity)

G1:
1. Boot process and grub (concept plan some notes and explain)
2. tee command usage (tee -a also explain )
3. at command and usage
-- try to schedule file based on (specific) time(now /at specific date or time)
--display all schedule jobs
-- delete specific jobs
-- find the file where all run job output saved

hint :
su -
whoami

at -l
atq

echo "echo 'Backup complete'" | at 2am


atq

at tomorrow
rm -rf d1

$ at tomorrow +45 minutes


at> echo “hello”

https://linuxconfig.org/at

cat > file.sh


echo "hello"
cal
date
ctrl +d

--schedule a file
at now +10 min -f file.sh
at 3:05pm today -f file.sh

atq

---delete a job
atrm 5
atq
at -d 4
atq

G2:
1. yum package usage (concept and practical)
2. merge command and usage
3. swap memory usage

G3:
1. directory structure in Linux and usage
2. cut command and usage
3. find comamnd (at least 4 example)

G4:
1. cmp vs diff (Suitable example)

2. grep vs egrep vs find


3.nohup
https://www.geeksforgeeks.org/nohup-command-in-linux-with-examples/

G5:
1. use of crontab command
--create a file named "a.txt",b.txt,c.txt incurrent directory
schedule a.txt for daily
schedule b.txt for monthly
schedule c.txt for 17july24
--display all schedule jobs
HInt:

--- to repeat the task


crontab -l
crontab -e
@daily /root/file.sh
@monthly /root/file.sh
esc :x

crontab -l
crontab -e
20 4 6/11/24 june tue echo "hello"

crontab -l

Q: in which file crontab and at job executed


Q: how to delete crotab schedule

SUmmary : (After completing you task)

Summary:
1. setup linux env
--download and installation
2. linux intro and usage areas
3. linux flavors
4. commands (useradd, su,whoami,pwd)
5. ways to create a new file?(touch,cat,vi)
--append in file /overwrite a file
--append a file using vi editor
6. commands :
man/info/--help ,cd,mkdir,rmdir,ls,cp,mv,rm, rm -rf, rm-rfi, rm -ri, cd .. , cd ,cd /
7. more , head, cmp,diff,
8. cd .. ,cd / ,cd
9. input-output redirection
10. tee command
11. uniq
12. grep ,egrep
13. shell scripting
14. how to transfer any file from host to linux vm or vice versa
15. trsansfer from host to vm using scp command
16. how to set if you forget root password
17. gzip and tar operations
18. user and group operations
19. file permission
20. sed, awk
21. winscp , ps , top, kill , bg and fg ,df,du ,
22. at and crotab
23. winscp
24. who, whereis ,which,hostname,uname
25. how to swith in backend terminal
26. seradd,usermod,userdel,groupadd,groupmod,groupdel,chmod, chown,chgrp

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@

Summary
basic
1. ways to create files in linux
2. create /delete directory
3. cd , cd ..., cd/ ,cd ~
4. whoami ,pwd , ls
5. user operations
--create a new user
-- switch into new user
-- group (primary and secondary)
-- set password for existing user
-- permissions
-- add new groups
-- change the primary group of existing user
-- add primary and secondary group at user creation time
-- add more than one secondary group in existing user

Q: what is script
Q: how to create /modify /run a script
Q: define input /output var ---pending
Q:

tr-1
ls -l a.txt
owner ---> root (rw)
group --->gr1(rw)
others ---o

cat >a.txt
clear
cal
date
echo "hello"
ctrld

tr2 --
su - us1
id us1 --primary group(gr1)
cat a.txt
./a.txt --error

tr-1
pwd --> /day1
chmod g+rwx a.txt
chmod 670 a.txt

--tr2
./a.txt

commands

#> whoami
pwd

Q: way to create file


mkdir d1
ls -l
cd d1
pwd
ls -l
touch a.txt
ls -l

cat > b.txt


hello
Good morning
ctrl d

ls -l

vi c.txt
esc i wsjhkf
sdfkjhkdsf
sdfkjhkdsf
esc :wq

Q: how to see file contents

cat c.txt
--------------------
cat >d.txt
hello this is my file
ctrl d

ls -l

cat d.txt

--append data in file d.txt


cat >>d.txt
appended data

ctrl d

cat d.txt

cat >d.txt
file new data

ctrld

cat d.txt

----------
vi d.txt
esc i
......

esc :wq or esc :x esc :q!


cat d.txt

========================
ACtivity
pwd --/root/d1
ls -l

cd ..
pwd
rmdir d1
rm -rfi d1

--------------------
mkdir -p d1/d2/d3/d4/d5
pwd
cd d1/d2/d3/d4/d5
pwd
cd ..
pwd
cd
pwd

------------------------
pwd
mkdir prod1
cd prod1
mkdir s1 s2 s3
ls -l
cd ..
pwd
cd prod1/s1
pwd
cd ../s2
pwd

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

clear
whoami
id root
---how to see all exitsing users
cat /etc/passwd
cat /etc/group

---when a new user created , automaticallyu same name of primary group created
--home dirreactory create --> /home/u1
-- one user should have one primary group and zero or more secondary group

useradd u1
cat /etc/passwd
cat /etc/group
id u1

pwd --/root
cd /home
pwd
ls -l

---switch from current user to u1 user


pwd
whoami
su - u1
whoami
pwd
touch a.txt
mkdir ss
ls -l
cd /root
pwd
mkdir gg

exit
whoami
pwd
passwd u1

==================
Q: ls command
https://www.geeksforgeeks.org/ls-command-in-linux/
Q: mkdir
https://www.geeksforgeeks.org/mkdir-command-in-linux-with-1examples/
Q: rm
https://www.geeksforgeeks.org/rm-command-linux-examples/
Q :info
https://www.tecmint.com/commands-to-collect-system-and-hardware-information-in-linux/
Q: cat
https://www.tutorialspoint.com/unix_commands/cat.htm
groupadd g1
groupadd g2
groupadd g3
cat /etc/group

useradd u11 -g g1 -G g2
id u11

---when a new user created , automaticallyu same name of primary group created
--home dirreactory create --> /home/u1
-- one user should have one primary group and zero or more secondary group

useradd u12
id u12
primary group --u12
usermod -g g1 -G g2,g3 u12
id u12

Q: how to add g2 and g3 secondary group in u11 user ?


usermod -aG g3,g2 u11
id u11

pwd ---
cd /root
pwd
whoami --root
mkdir day1
ls -l
rmdir day1
ls -l

mkdir /day1
ls -l
cd /
pwd
ls -l
cd day1
pwd
ls -l
cat >a.txt
hi
hello
good afternoon
post lunch session
ctrl d
ls -l a.txt
pwd ---/d1
whoami --root
useradd us1
useradd us2
useradd us3
groupadd gr1

file --newtab
tr-2
su - us1
whoami
pwd

cd /day1
pwd
ls -l
cat a.txt --valid
cat >>a.txt

tr1
pwd
chmod o+w a.txt
ls -l

-->tr2
cat >>a.txt

-----------------------
https://linuxize.com/post/chmod-command-in-linux/
https://www.howtogeek.com/437958/how-to-use-the-chmod-command-on-linux/

https://www.geeksforgeeks.org/chown-command-in-linux-with-examples/
https://www.geeksforgeeks.org/chgrp-command-in-linux-with-examples/

https://linuxize.com/post/usermod-command-in-linux/

q: WHAT IS PRIMARY GROUP OF USER US1?


id us1 -->us1
Q: what is group name of file /day/a.txt
cd /day1
ls -l a.txt ----root

Q: revoke all permission from others in a.txt


tr1---> cd /day1
chmod o-rwx a.txt
chmod 640 a.txt

Q: change primary group(gr1) for user us1


--tr1
clear
whoami --root
pwd ---/day1
usermod -g gr1 us1
id us1

--tr2
id us1
exit
su - us1

Q: change group name(gr1) of file a.txt


--tr1
cd /day1
ls -l a.txt
chgrp gr1 a.txt
ls -l

Q: give read and write permission on "gr1" of a.txt


--tr1
pwd ---/day1
chmod g+rw a.txt
chmod 660 a.txt
ls -l a.txt
Q: can we do read and write operation in us1-(tr2)
Q: how to revoke oermission from gr1

tr1 --
chmod g-rw a.txt
Q: how to see file contents

cat c.txt
--------------------
cat >d.txt
hello this is my file
ctrl d

ls -l

cat d.txt

--append data in file d.txt


cat >>d.txt
appended data

ctrl d

cat d.txt

cat >d.txt
file new data

ctrld

cat d.txt

----------

vi d.txt
esc i
......

esc :wq or esc :x esc :q!


cat d.txt

You might also like