Q1. hell scripts to print system status , usage and memory.
#!/bin/bash
# Print disk and memory usage
echo "Disk and Memory Usage Report"
echo "============================"
# Display disk usage
echo "Disk Usage:"
df -h
# Display memory usage
echo "Memory Usage:"
free -h
# Disk Usage (df -h) // Memory Usage (free -h )
# -h Displays the output in a human-readable format (e.g., GB, MB
out put :-
Q2. Shell script to count the files in the current directory
file_count=$(ls -1 | wc -l)
echo "Number of files in the current directory: $file_count"
#!/bin/bash
name="Pratik"
echo "Enter the name:"
read username
echo "You entered $username"
~ ---------------------------------------------------------
#!/bin/bash
read -p "Enter username: " username
echo "You entered: $username"
New user added (etc /cat/passwd) on this path new user will added after adding name
#!/bin/bash
read -p "Enter username: " username
echo "You entered: $username"
sudo useradd -m $username
echo "New user added"
#!/bin/bash
read -p "Enter the girl's name: " girl
if [[ $girl == "BUBU" ]]; then
echo "Dudu is loyal"
else
echo "Dudu is not loyal"
fi
IF else then elseif Example
#!/bin/bash
# Prompt the user to enter a girl's name
read -p "Enter the girl's name: " girl
# Prompt the user to enter a percentage value for love
read -p "Enter the percentage of love Dudu has not seen Bubu: " love
# Check if the entered girl's name is "bubu"
if [[ $girl == "bubu" ]]; then
echo "Dudu is loyal because the girl's name is Bubu."
# Check if the love percentage is 100 or more
elif [[ $love -ge 100 ]]; then
echo "Dudu is loyal because the love percentage is 100 or more."
# If neither condition is met, Dudu is not loyal
else
echo "Dudu is not loyal because neither condition is satisfied."
fi
This script prompts the user to input a girl's name and a percentage value representing love. It then evaluates the inputs: if the girl's name is "bubu," it confirms Dudu's loyalty. Alternatively, if the love percentage is 100 or more, it also confirms loyalty. If neither condition is met, it concludes that Dudu is not loyal.
For Loop (This will create files numbered 1 to 10. If you replace touch
with mkdir
, it will create folders instead.)
for ((i=1; i<=10; i++)); do
touch file$i
done
ย