Given a list of filenames as input, this script queries each target file (parsing the output of the file
command) for the type of compression used on it. Then the script automatically invokes the
appropriate decompression command (gunzip, bunzip2, unzip, uncompress, or whatever). If a target
file is not compressed, the script emits a warning message, but takes no other action on that particular
Unique System ID
Generate a "unique" 6-digit hexadecimal identifier for your computer. Do not use the flawed hostid
command. Hint: md5sum /etc/passwd, then select the first 6 digits of output.
Archive as a "tarball" (*.tar.gz file) all the files in your home directory tree
(/home/your-name) that have been modified in the last 24 hours. Hint: use find.
Optional: you may use this as the basis of a backup script.
Checking whether a process is still running
Given a process ID (PID) as an argument, this script will check, at user-specified intervals, whether
the given process is still running. You may use the ps and sleep commands.
Print (to stdout) all prime numbers between 60000 and 63000. The output should be nicely
formatted in columns (hint: use printf).
One type of lottery involves picking five different numbers, in the range of 1 - 50. Write a script that
generates five pseudorandom numbers in this range, with no duplicates. The script will give the
option of echoing the numbers to stdout or saving them to a file, along with the date and time the
particular number set was generated. (If your script consistently generates winning lottery numbers,
then you can retire on the proceeds and leave shell scripting to those of us who have to work for a
Integer or String
Write a script function that determines if an argument passed to it is an integer or a string. The
function will return TRUE (0) if passed an integer, and FALSE (1) if passed a string.
Hint: What does the following expression return when $1 is not an integer?
expr $1 + 0
ASCII to Integer
The atoi function in C converts a string character to an integer. Write a shell script function that
performs the same operation. Likewise, write a shell script function that does the inverse, mirroring
the C itoa function which converts an integer into an ASCII character.
Managing Disk Space
List, one at a time, all files larger than 100K in the /home/username directory tree. Give the user
the option to delete or compress the file, then proceed to show the next one. Write to a logfile the
names of all deleted files and the deletion times.
Simulate the functionality of the deprecated banner command in a script.
Removing Inactive Accounts
Inactive accounts on a network server waste disk space and may become a security risk. Write an
administrative script (to be invoked by root or the cron daemon) that checks for and deletes user
accounts that have not been accessed within the last 90 days.
Enforcing Disk Quotas
Advanced Bash-Scripting Guide
Appendix O. Exercises