Linux13 July
Linux13 July
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
cat >a.txt
hi thisis my file
Q: hard link
cat >a.txt
hi thi sis file
ln a.txt hard.txt
ls -lia
rm a.txt
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 ~]#
=================================================
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
https://www.geeksforgeeks.org/gunzip-command-in-linux-with-examples/
======================================================================
=================
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
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
----------------------
@@@@@@@@@@@@@@@@@@@@@@@@@@@
Q: user password management
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
This will show a short information about the status of the password for a given account.
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
https://www.2daygeek.com/lock-unlock-disable-enable-user-account-linux/
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:
================================
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 -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
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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@
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
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
------------------------------------------------
----> create a file named "a.txt" --> insert 10 rows
Additional operations:
:1co3 - first line copying to 3rdline
------------------------------------------
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
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
HInt
---use scp command
--use tool winscp
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/
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)
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@
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
at tomorrow
rm -rf d1
https://linuxconfig.org/at
--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)
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:
crontab -l
crontab -e
20 4 6/11/24 june tue echo "hello"
crontab -l
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
ls -l
vi c.txt
esc i wsjhkf
sdfkjhkdsf
sdfkjhkdsf
esc :wq
cat c.txt
--------------------
cat >d.txt
hello this is my file
ctrl d
ls -l
cat d.txt
ctrl d
cat d.txt
cat >d.txt
file new data
ctrld
cat d.txt
----------
vi d.txt
esc i
......
========================
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
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
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/
--tr2
id us1
exit
su - us1
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
ctrl d
cat d.txt
cat >d.txt
file new data
ctrld
cat d.txt
----------
vi d.txt
esc i
......