I need to Write a Unix shell script that accepts two or more arguments, a file mode, a command and an optional list of parameters and performs the given command with the optional parameters on all files with that given mode.
For example, mycode 644 ls -l should perform the command ls -l on all files in the current directory that have mode 644.
I use this code to change the file permission to numeric mode
#!/bin/sh
mode=$1
#it adds the numeric permission to the beginning of the line
ls -l |awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
*2^(8-i));if(k)printf("%0o ",k);print }'
.....
shift $1
$*
but I dont know how to ask the code to list only files with same permissions. how can I ask the code to do it?
Use the
findcommand for this. E.g.