How can i get my apple id by terminal in MacBook?

The information about the currently logged in Apple ID can be retrieved with the following command: defaults read MobileMeAccounts Accounts Alternatively, you can take a look at the tool mas-cli. With the command mas account you can also query the Apple ID.


I improved @rollcoaster answer as bellow :

user$ defaults read MobileMeAccounts Accounts | grep AccountID | cut -d \" -f2

The output of defaults read MobileMeAccounts Accounts statement is a json, so i applied grep command on this json to get AccountID field. Finally i extracted the content of quoted string from the output.