Use `stat` for that.
In a GNU system:
* To get the username of the owner:
stat -c '%U' file.txt
* To get the user ID (UID) of the owner:
stat -c '%u' file.txt
Assuming the file is `file.txt`.
* * *
For FreeBSD and Mac OS X _(thanks to @cas)_ :
* For username:
stat -f '%Su' file.txt
* For UID:
stat -f '%u' file.txt