Hi!I'm new in this forum,also in shell scripting! 
I'd like to help me with an issue!the project wants to make a variable with a directory(any) and then print all executable files of this directory,sorted by size!Thank you!
seems like a homework
post this in homework section
Nope!just practicing!i found random exercises and i'm trying to practice on shell scripting!(sorry for my terrible english! )
what you tried so far ?
my problem is passing a directory into a variable...i've thought this : dir_name=$(dirname $0)
now to print the executable files sorted by size i wrote this:
echo "executable files by size order:"
find $dir_name -type -f -perm -og+x | sort -nr
First let's get the "find" right: We're looking for any executable file so we need to check User, Group and Other permissions for the Executable bit. Within the protected brackets of this command the two standalone "-o" switches mean "OR".
find "${dir_name}" -type f \( -perm -u+x -o -perm -g+x -o -perm -o+x \)
Now ... the output from "find" will be a straight list of filenames which does not mention the size of the file.
ok!thanks for this by the way!now with this i can have a list with the executable file in directory dir_name...
i can sort them now with this command?
find "${dir_name}" -type f \( -perm -u+x -o -perm -g+x -o -perm -o+x \) | sort -nr
Nope, your command just sorts the name of the file.
This is where it would help to know what Operating System and version you have.
We need to use the list of filenames to get the size of the file, then sort on the field containing the file size. A generic response (assuming that the size field is the 5th field in "ls -la") would be:
find "${dir_name}" -type f \( -perm -u+x -o -perm -g+x -o -perm -o+x \) -exec ls -lad {} \; | sort -n -r -k 5
Yes. This will sort.