----------- #!/bin/bash read -p "Enter package name: " name echo "Package name is $name" read -p "Enter path for package source files (ex: /home/jon/$name): " dir_path year_s=2005 year_e=2018 cd $dir_path ----------- In first section of script we declare wich language we use (bash), we enter path of package that will be analize with slocount (variable dir_path) and we declare variables for start year (year_s) and end year (year_e) that will be parsed in package directory. We change working directory in path dir_path. ----------- for year_dir in `seq $year_s $year_e` do cd $dir_path/$year_dir/03 echo `pwd` ----------- We start loop for years directory parsing and we change directory in every year to 03 directory (month directory). In evrey year will have 2 subdirectory (03 and 07). With line echo `pwd` we will print our path (just for control). The loop itself has two similar sections for month 03 and for month 07. ----------- archive_f=`ls -S | grep ".tar." | grep ".orig" | grep -v ".diff" | head -1` echo $archive_f ----------- At this section to archive_f variable will take the value from "ls -S" (-S param is for sort descending, largest first) output, and we will do grep on this output after 3 diferent strings (".tar.", ".orig", ".diff") and after that we print only first line (head -1) With echo $archive_f we print on screen value of archive_f variable. ----------- if [[ $archive_f =~ ".gz" ]]; then echo "File with GZ extension" tar xvzf $archive_f source_dir=`ls --file-type -1 | grep "/" | awk -F '/' '{print $1}'` cd $dir_path/$year_dir/03/$source_dir source_dir_path=`pwd` sec_archive_f=`find $source_dir_path -print | grep -E 'tar.gz|tar.xz|tar.bz2' | grep -v ".diff"` if [[ $sec_archive_f =~ ".gz" ]]; then tar xvzf $sec_archive_f elif [[ $sec_archive_f =~ ".xz" ]]; then tar xvf $sec_archive_f else tar xvjf $sec_archive_f fi cd ../ sloccount $source_dir_path > sloccount.log ----------- Here is section were will be identified typs of archives and which one contain source files (in many cases we have archive in archive) The other "elif" sections are similar with this "if" section. In this "if" section we will check tar archives with .gz extension if [[ $archive_f =~ ".gz" ]]; then and in elif sections will check achive files with .xz extension and .bz2 extension. So if archive is with .gz extension then we will unpack archive in line tar xvzf $archive_f After that in new created directory from archive we will have source files of package or another archive (tar.gz, tar.xz or tar.bz2), we will do that here source_dir=`ls --file-type -1 | grep "/" | awk -F '/' '{print $1}'` cd $dir_path/$year_dir/03/$source_dir source_dir_path=`pwd` sec_archive_f=`find $source_dir_path -print | grep -E 'tar.gz|tar.xz|tar.bz2' | grep -v ".diff"` If we will find another archive in source directory we will check what kind of archive is and we will unpack in next if and elif statements if [[ $sec_archive_f =~ ".gz" ]]; then tar xvzf $sec_archive_f elif [[ $sec_archive_f =~ ".xz" ]]; then tar xvf $sec_archive_f else tar xvjf $sec_archive_f fi After all this checks we will change one directory up and we will do slocount on source directory. All this will apply for principal archive with .xz or .bz2 extension. After this script will do same verifications for month 07.