Terminal Exercises
Help 20 / 25
Shell Scripts

Longest file with a given extension

Go to the folder exercise-data/:

cd $TUTORIAL/exercise-data/

Write a shell script called longest.sh that takes the name of a directory and a filename extension as its arguments, and prints out the name of the file with the most lines in that directory with that extension. For example:

bash longest.sh alkanes pdb

would print the name of the .pdb file in alkanes/ that has the most lines.

Feel free to test your script on another directory e.g.

bash longest.sh writing txt
Exercise Criteria:
0 / 2
  • Script longest.sh exists
  • The output file longest.txt exists: bash longest.sh alkanes pdb > longest.txt
Loading...