Linux Rec 2024 III BSC CS
Linux Rec 2024 III BSC CS
No : 1
COMMANDS:
a)
rm (Remove) - Delete a file or directory tree
sh-4.4$ rma.txt
b)
c)
d)
e)
f)
wc – Word/line/byte count
sh-4.4$ wc -l a.txt
2 aa.txt
sh-4.4$ wc -c a.txt
16 a.txt
#$wc –lwFile_Name - is used to calculate line and word for specific file.
#$wc –lcFile_Name - is used to calculate line and character for specific file.
2 4 aa.txt
g)
sh-4.4$ ls
x00 xaaa.txt
h)
2a3,5
Ex.No : 2
COMMANDS:
sh-4.4$ whoami
b) current shell , home directory , Operating System type , current path setting , current
working director
Current Shell
sh4.4$ echo $0
sh
Home Directory
/home/cg/root/users/desktop/a/·
NAME=Fedora
ID=fedora
VERSION_ID=26
ANSI_COLOR="0;34"
CPE_NAME="cpe:/o:fedoraproject:fedora:26"
HOME_URL="https://fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=26
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=26
PRIVACY_POLICY_URL=https://fedoraproject.org/wiki/Legal:PrivacyPolicy
/home/cg/root/a/
sh4.4$ pwd
/home/cg/root
sh4.4$ w
USER TTY
LOGIN@ IDLE JCPU PCPU WHATd) show CPU information like processor type ,
speed
processor:0
vendor_id: GenuineIntel
cpu family : 6
model: 63
stepping:2
microcode : 0x39
physical id : 0
siblings: 12
core id: 0
cpu cores: 6
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 15
wp : yes
constant_tscar
ch_perfmonpebsbtsrep_goodnoplxtopologynonstop_tscaperfmperfeagerfpupnipclm
rdrandlahf_lmabmidaaratepbpln pts
erms invpcidcqmxsaveoptcqm_llccqm_occup_llc
bogomips : 6984.03
clflush size : 64
cache_alignment : 64
power management:
processor:1
vendor_id: GenuineIntel
cpu family:6
model: 63
stepping:2
$ cat /proc/meminfo
Active: 12559184 kB
Active(anon): 9262084 kB
Inactive(anon): 308464 kB
Active(file): 3297100 kB
Inactive(file): 1225900 kB
Unevictable:0 kB
SwapTotal: 4194300 kB
SwapFree:
2898672 kB
Writeback:0 kB
AnonPages:9319384 kB
Shmem:174832 kB
SReclaimable: 4224068 kB
SUnreclaim: 2775868 kB
KernelStack: 111920 kB
PageTables:
123656 kB
NFS_Unstable: 0 kB
WritebackTmp:0 kB
CommitLimit: 136125132 kB
Committed_AS: 186068300 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 747216 kB
VmallocChunk: 34358861532 kB
HardwareCorrupted: 0 kB
AnonHugePages: 3532800 kB
HugePages_Total: 0
HugePages_Free:0
HugePages_Rsvd:0
HugePages_Surp:0
Hugepagesize:2048 kB
DirectMap2M: 7020544 kB
DirectMap1G: 263192576 Kb
Inactive:1534364 kB
Mlocked:0 kB
Dirty:456
kBMapped:Slab:146324 kB 6999936 kB
Bounce:0 kB
DirectMap4k:
Ex.No 3
COMMANDS:
# Use a pipe to send the content of input.txt to a command and then redirect the
OUTPUT:
to another file
# Use the tee command to simultaneously display the output and save it to a file
SCRIPT CODE:
disp_menu()
{
display_user()
{
echo "Current Username:"
echo "USERNAME:$(whoami)"
}
list_files()
{
echo "File List in the Directory:"
find -type f
}
list_dir()
{
echo "Directories in the Current directory:"
find -type d
}
while true
do
disp_menu
read choice
case $choice in
1)
display_date;;
2)
display_user;;
3)
list_files;;
4)
list_dir;;
5)
echo "Existing the script, Thank you..!"
exit 0;;*)
echo "Invalid choice, Please try again..!"
esac
echo "press Enter to continue"
read enter_key
done
OUTPUT:
==========main menu==========
1.Display Current Data
2.Display User Name
3.List of Files in the Current Directory
4.List Directories in the Current Directory
5.Exit
=============================
3
SCRIPT CODE:
#Function to Display Usage Information
usage()
{
echo "Usage: $0 <Command><Pattern>[File]"
echo "Available Commands: grep, sed, awk"
exit 0
}
#Check if the Correct No of Arguments is Provided
if [ $# -ne 3 ]
then
usage
fi
#Extract Arguments:
command="$1"
pattern="$2"
file="$3"
OUTPUT:
SCRIPT CODE:
#Set Directory Name
Directory=“/c/Users/ADMIN/Desktop”
#Check if file or folder and check size 0
find”$directory”-type f -size 0 -delete
#Delete Info
echo”zero byte file in $directory have been removed”;
OUTPUT:
$ ./Pro6.sh
zero byte file in /c/Users/ADMIN/Desktop/a/ have been removed
Ex.No : 7
SCRIPT CODE:
echo "enter a number:"
read number
sum=0
echo $digit
while [ $number -gt 0 ]
do
digit=$((number % 10))
sum=$((sum + digit))
number=$((number/10))
done
echo "The Sum of the Digit is:$sum"
OUTPUT:
Enter a Number:
1234
The Sum of the Digit is:10
Ex.NO : 8
SCRIPT CODE:
if [ "$#" -lt 2 ]; \
then
echo "Usage: $0 <number1><number2> ... <numberN>"
exit 1
fi
max=$1
for number in "$@"; do
if [ "$number" -gt "$max" ];
then
max=$number
fi
done
echo "The greatest number is: $max"
OUTPUT:
$ ./Pro8.sh 45 37 18 22 97 74
The greatest number is: 97
Ex.No : 9
SCRIPT CODE:
is_palindrome()
{
input=$(echo "$1" | tr -d ' ' | tr '[:upper:]' '[:lower:]')
reverse=$(echo "$input" | rev)
if [ $input = $reverse ]
then
echo "It is a Palindrome"
else
echo "It is not a Palindrome"
fi
}
if [ $# -eq 0 ]
then
echo "usage: $0 <word or phase>"
exit 1
fi
is_palindrome $1
OUTPUT:
$ ./PPP.sh amma
It is a Palindrome
Ex.No : 10
SCRIPT CODE:
if [ $# -eq 0 ]
then
echo "usage :$0<number>"
exit 1
fi
number=$1
for i in {1..100}
do
result=$((number*i))
echo "$number * $i = $result"
done
OUTPUT:
$ ./Pro.sh 5
1*5 =5
2 * 5 = 10
3 * 5 = 15
4 * 5 = 20
5 * 5 = 25
6 * 5 = 30
7 * 5 = 35
8 * 5 = 40
9 * 5 = 45
10 * 5 = 50
CONTENT
PAGE REMARK
Sl.No DATE TITLE OF THE SHELL SCRIPT
NO S
1 FILE COMMANDS
2 SYSTEM CONFIGURATION