Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Trying to write a short script that will tell me whether the permissions for 2 files, whose names are given as arguments to the script, are identical. If the permissions are the same, output the common permission field. If they are different, I need to output each file name followed by its permission field. I've been trying to use the cut command but seem to be missing something. Any suggestions would be appreciated. Thanks,
Al
Click here to see the post LQ members have rated as the most helpful post in this thread.
This is kinda hacky but it's short and simple to understand and doesn't use many tools.
Code:
#!/bin/bash
FILEP1=`ls -l $1 | cut -f1 -d' '`
FILEP2=`ls -l $2 | cut -f1 -d' '`
FILEN1=`ls $1`
FILEN2=`ls $2`
DIFF=0
for i in `seq 1 10`; do
VAL1=`echo $FILEP1 | cut -c$i`
VAL2=`echo $FILEP2 | cut -c$i`
if [ $VAL1 == $VAL2 ]; then
echo "Bit $i is the same ($VAL1)";
else
echo "Bit $i is different ($VAL1 vs $VAL2)";
DIFF=1
fi
done
if [ $DIFF -gt 0 ]; then
echo "$FILEP1 $FILEN1"
echo "$FILEP2 $FILEN2"
fi
Needs error checking and probably won't function with special characters as written.
#Uncomment and comment above for drwxr-xr-x format
#MODE=$(stat --format=%A ${FILENAME})
#MODE1=$(stat --format=%A ${FILENAME1})
if [ "${MODE}" = "${MODE1}" ]
then
echo "Both files have permissions of ${MODE}"
else
echo "${FILENAME} Permissions are ${MODE} : ${FILENAME1} Permissions
are
${MODE1}"
fi
I can get the user to input the files they wish to compare but it dies after that.
AL
Thanks for the help folks. Even though I was "looking" at it, I missed the "exit". Must of had a senior moment that lasted longer than normal. Works as advertised.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.