How to create a summary file of all files in a directory sorted in reverse alphabetical order.?

I have an interactive script which works terrific at processing a folder of unsorted files into new directories.

I am wondering how I could modify my script so that( upon execution) it provides an additional labelled summary file on my desktop that lists all of the files in each directory that the script has sorted in reverse alphabetical order.

NB. The script as it stands is executed on an unsorted folder containing (jpg,gif,docx, aif, wav).The script runs and moves all files of type jpg, gif,docx to newly formed directories and everything else gets bumped into a miscellaneous. I would like a summary file on the desktop that lists all of these files in reverse alphabetical order based on the executed sort process that has finalised.

#!/bin/bash
read -p "Good Morning, Please enter your file type name for sorting [ENTER]:" all_extensions
if cd /Users/christopherdorman/desktop
  then	while read extension
	  do 	destination="folder$extension"
	  	mkdir -p "$destination"
	  	mv  -v unsorted/*."$extension" "$destination"
	  done   <<< "${all_extensions// /$'\n'}"
		mkdir -p foldermisc	
		if mv  -v unsorted/* "foldermisc"
	  then	echo "Good News, the rest of Your files have been successfully processed"
		fi
	for i in folder*/; do
  		ls -S "$i" > "${i}filelist"
	done
fi

man ls reveals that there is a -r option. Alternatively you might want to look into the find command.

1 Like

Thank you.

ls -r certainly works in the terminal in terms of reverse sorting.

However, Can terminal commands be directly nested in a shell script. ??

Whatever you mean by "nested" - yes, commands do behave identical, be they issued on the command line or run within a script.

1 Like

encapsulated within the code block, nested. thanks