You could use a for loop in bash to test for each user's home directory in turn, e.g.:
for d in /Users/*
do
if [ -e "$d/Desktop/file" ]
then
echo "The file existed under $d"
else
echo "The file was not found under $d"
fi
done
The /Users/*
is expanded into /Users/alice /Users/bob /Users/charles
(or whatever) and then $d
is given the value of each of those in turn inside the loop. Obviously you can replace the echo
statments with whatever you want to do in either case.
The bash manual's section on looping constructs, including for loops, is here - that might not be the best place to start, but you can find plenty of examples with Google.
One thing to note about this answer is that if you're being strict, a user's home directory doesn't have to be called /Users/username - strictly speaking you need to look in /etc/passwd
to find all users and their corresponding home directories. However, for what you want to do, this might be enough.
Update 1: It sounds from the comment below as if you want to take an action if no file matching /Users/*/Desktop/file
exists for any user. This sounds surprising to me, but if you really want to do that, you could use one of the recipes from this other Stack Overflow question, for example:
if [ -z "$(shopt -s nullglob; echo /Users/*/Desktop/file)" ]
then
echo "No one had a file in ~/Desktop/file"
fi
Update 2: Your comments on Dennis Williamson's answer indicate that this script is expected to be run by non-root users on this machine. If that's the case then I think his suggestion in the comments is the right one - you just want to test:
if [ -e "$HOME/Desktop/file" ]
then
echo "Found the file"
else
echo "Failed to find the file"
fi
... and then you just just need to make sure you test it as a non-root user.