Is there a command line to see what computer I'm actually on ?

I extensively use terminals, and my PS1 between sessions and computers are alike so I get confused what machine I am currently using. By machine I mean local computer or server, not the current user (because the PS1 is showing this information). Is there a command line for that ?

(ps: I request a command line, not how to change the PS1 because sometimes I am working on a small screen and I try to manage relatively short lines)


  • I don't think this question has a reliable general answer, but localised answers are of course possible. Hostnames can be the same, the same goes for IP addresses, and even MACs. HDDs UUIDs or MB SN are possibly unique, but usually not human usable for this purpose
    – Dani_l
    Sep 16, 2017 at 5:44
  • @Fox thanks, perfect, this is what I wanted.
    – vdegenne
    Sep 16, 2017 at 5:47
  • Does not your terminal prompt include the hostname OOB? What UNIX system are you running and what is your shell?
    – ajeh
    May 12, 2018 at 23:22

4 Answers 4


IMHO, the prompt is the best thing to use to remind you of where you are. It can be used to remind you about the machine, the current user name, the directory etc. The prompt is always there on the command line, so it will be difficult to ignore it. Using some other command to look up what the current machine name is (like hostname) will obviously also work, but you'll forget to do it.

Set your primary prompt to a string that includes the host name:

PS1="$(id -un)@$(hostname) \$ "

This will, on my current machine, and for my user, set the prompt to

[email protected] $ 

You may want to use hostname -s instead of just hostname to remove the domain part of the host name.

Some shells, like bash, have shorthand notations that you may use for the same thing. For bash (replace \H with \h to get the shorter version of the host name):

PS1='\u@\H \$ '

Note that there is no need to export PS1 as it's only used by the current shell process.

Changes to this variable may be done in your shell initialization file. For bash, modify ~/.bashrc. Read your shell's manual about PS1.

For really small screens, you may want to come up with your own dynamic prompt:

case "$(hostname)" in
    bigserver*)  promptstr='bs'  ;;
    srv-*)       promptstr='srv' ;;
    accounting*) promptstr='a'   ;;
    web-dev-*)   promptstr='wd'  ;;
    *)           promptstr=$(hostname -s) ;;

PS1="$promptstr \$ "

Or just use the first three characters of the hostname:

PS1="${HOSTNAME:0:3} \$ "

(this requires a shell that know how to do that sort of variable substitution, obviously, but bash does)

... or just some other indicator to remind you that you're not local anymore, like using a * before the $ (PS1='*$ ') remotely while not using that indicator locally. Or any other of many possible prompts.


There are plenty of ways depending on what information you need to distinguish your machines.

dmidecode -t1 shows information about the computer you're on, including manufacturer and model, e.g.

> dmidecode -t1 | grep Version
    Version: ThinkPad T520

uname -a prints system information like the network node hostname (-n) and the kernel release (-r).

lsb_release -a shows distribution-specific information, e.g.

> lsb_release -d
Description:    Ubuntu 16.04.3 LTS
  • No, hm.. sorry maybe my question was a bit abstract, I didn't mean informations about the computer, instead informations to distinguish my local from my remote computer (when using ssh sessions for instance) but thanks
    – vdegenne
    Sep 16, 2017 at 5:49
  • 2
    @ballangddang No need to be sorry, just edit your question and make it more accurate, I will do the same with my answer.
    – dessert
    Sep 16, 2017 at 5:52

Try command uname -a OR hostname, ip a ..etc


write in the terminal


  • Technically correct, but it might be nice to show an example of its output.
    – roaima
    May 12, 2018 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .