Reputation: 318
So I have recently begun using the terminal on my Macbook air and was wondering if anyone could provide an explanation of the first 2 lines that pop up when you open Terminal. They are as follows:
Last login: Sat Feb 20 11:53:48 on ttys000
emilys-iphone-2:~ AidanTakami$
More specifically, who is emily and why is her iPhone shown on my terminal?
Upvotes: 0
Views: 637
Reputation: 84531
You will find no other piece of software on your macbook that allows you to do more than the terminal. It may not seem like it at first, looking at that simple prompt, but the terminal literally gives you the keys-to-the-kingdom.
That said, back to your two lines. The first is a standard login response telling you when and from where your user last logged into that machine (the data is usually read from /var/log/wtmp, see man last
).
The second line, your prompt, is controlled by the PS1
shell variable (see man bash
(or your shell's manual)). It can be configured to your liking using the various well-documented escape codes and any constant data you include. You can temporarily change the prompt by simply typing PS1=<your wanted string>
. A helpful link is Prompt magic - IBM. My favorite is PS1="\[\e[0;37m\]\D{%R}\[\e[1;34m\] \h:\w> \[\e[0m\]"
, which results in a prompt containing the time , hostname and path information. (in a form that can be cut-and-pasted for shell operations (e.g. cp, mv, ssh, rsync, etc...
) :
14:25 alchemy:~/dev/src-c/tmp/refmt>
(note: you can adjust the colors by changing the escape codes to set the color of choice. Also above \D{%R}
is the formatted time, \h
is the hostname and \w
is the path information. The remaining escapes set the colors and \[\e[0m\]
terminates a sequence of escape codes (necessary so the proper prompt length can be computed by the shell))
There are a number of shell variables that control how the PS1 prompt behaves, such as PROMPT_DIRTRIM
(which controls how many directory levels are shown in the path
component if included) This information is available in your shell's manual page. You can also set separate prompts for each user. For example, for root
I generally use, PS1="\[\e[1;34m\][\[\e[1;31m\]\A \[\e[1;34m\]\h\[\e[0;31m\]:\w\[\e[1;34m\]] # \[\e[0m\]"
which provides immediate visual indication that I am working as root (so you can do what you need, and quickly exit to your normal user again). e.g.:
[14:27 alchemy:.../src-c/tmp/refmt] #
To make your prompt changes permanent, set the desired value in your startup file (like in your ~/.bashrc
for your individual user, or in the system startup file for all users)
Hope this has helped.
Upvotes: 1