Artificial intelligent assistant

Find owner of a file I am looking for a way inside a bash script to return the owner of a file. I'm guessing that this is possible using "gawk" but I've honestly got no clue and there doesn't seem to be a comprehensible answer already posted online.

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

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2c57f3b1fff4bf225128e4b2bc502447