Linux LAB
Linux LAB
PROGRAM 3:
Create a script that displays the disk space usage of each directory in the
current location
indent is a variable that generates spaces for indentation. The deeper the directory level,
the more spaces are added.
du -sh "$path" calculates the size of the directory in a human-readable format (-sh).
2>/dev/null suppresses any error messages.
cut -f1 extracts the size from the du output.
echo prints the directory path and its size with the appropriate indentation.
The for loop iterates over all items in the directory ("$path"/*/), matching only
directories ([ -d "$dir" ]).
For each subdirectory, the function calls itself recursively, increasing the indentation level.
main is the main function that initializes the script.
current_directory=$(pwd) gets the current working directory.
echo prints a header indicating the start of disk usage reporting.
display_disk_usage "$current_directory" 0 starts the recursive process from the
current directory with an initial indentation level of 0.
PROGRAM 4:
Write a script that compresses a given file using both gzip and bzip2, creating two
compressed versions.
Running the Script:
WORKING
"$#": The special variable that holds the number of arguments passed to the script.
[ "$#" -ne 1 ]: Checks if the number of arguments is not equal to 1.
If the condition is true (i.e., the script does not receive exactly one argument), it prints the
usage message and exits with a status code of 1.