HOWTO: Change the Unix prompt and windows title. PDF Print E-mail
User Rating: / 24
PoorBest 
Written by Patrick Prevoo   
The default user prompt on Unix is "$" and the root prompt is "#". In this article you will find how you can change the prompt to display a lot of useful information. The same or other information can also be displayed in the windows title. The prompt is set by changing the PS1 environment setting.  
 
Some examples:
 
1. Username in prompt
PS1="$USER >"
Result: “user1 >”
 
2. Username and hostname in prompt
PS1="$USER@$(hostname) >"
Result: “ This e-mail address is being protected from spam bots, you need JavaScript enabled to view it >”
 
If your hostname is the hostname including your domain name you can truncate the domain name.
 
3. Username with truncated hostname in prompt
PS1="$USER@$(hostname| awk -F . '{print $1}' ) >"
Result: “user1@host1 >”
 
3. Username, hostname and current path in prompt
PS1=$(echo "$USER@$(hostname| awk -F . '{print $1}') "'$PWD'" >")
Result: “user1@host1 /home/user1 >”
 
4. Username, hostname, current Oracle SID and current path in prompt  
PS1=$(echo "$USER@$(hostname| awk -F . '{print $1}') "'$ORACLE_SID'" "'$PWD'" >")
Result: “user1@host1 MainDB /home/user1 >”
 
By putting all this information in the prompt the prompt can get extremely long. In the next example all the information is on one line and the prompt on the next line.
 
5. Prompt on two lines
PS1=$(echo "\n[$USER@$(hostname| awk -F . '{print $1}') "'$ORACLE_SID'" "'$PWD'"] $(echo "\n")> ")
Result: [user1@host1 MainDB /home/user1 ]
            >  
 
All the information can also be set in the windows title. This only works on “terminals” that support this option. So in the profile you best test the “TERM” environment setting first. This option also works with putty ssh sessions.
 
Below a little script you can add to your personal profile or to your system profile.
 
The prompt will look like:  
[ user1@host1 MainDB /home/user1 ]
$
 
The windows title will look like:
host1 as user1 {MainDB} <The first user> /home/user1
 
When this user switches to root the prompt will look like:
[ root@host1 / ]
$
 
The windows title will look like:
host1 as root {} <The first user> /
 
The name between <> is the real user name so it will always be “The first user” and will not change to the display name of root. Running a lot (putty) sessions to different Unix systems from windows you will get one grouped putty item. When clicking on this taskbar group you can quickly find the session you are looking for. The hostname is at the front of the windows title to make it easier to find the right session.
 
When activating this script on every Unix system in your environment you can telnet, rsh, ssh and “su” as much as you want, the information on the prompt AND in the windows title will always be accurate.  
 
See Microsoft article kb#281628 (http://support.microsoft.com/kb/281628) to change the behavior of the grouping on windows. Changing the grouping setting to “2”, windows will always group all applications.
 
 
# Prompt settings
REALUSER=$(who am i |head -1 |awk '{print $1}')
REALNAME=$(cat /etc/passwd |grep "^$REALUSER:" |awk -F ':' '{print $5}')
HOSTNAME=`hostname | awk -F . '{ print $1 }'`
 
if [ "$USER" = "root" ]
then
  PS2='# '
else
  PS2='$ '
fi
 
PS1=""
if [ "$TERM" = "xterm" -o "$TERM" = "dtterm" -o "$TERM" = "aixterm" ]
then
  PS1=$(echo "\033]0;$HOSTNAME as $USER {"'$ORACLE_SID'"} <$REALNAME> "'$PWD'"\007")
fi
PS1=$PS1$(echo "\n[ $USER@$HOSTNAME "'$ORACLE_SID'" "'$PWD'" ]$(echo "\n$PS2")")
 
export PS1
 
< Prev   Next >
Login
61 queries executed
1
SET sql_mode = 'MYSQL40'
2 SELECT folder, element, published, params FROM jos_mambots WHERE published >= 1 AND access <= 0 AND folder = 'system' ORDER BY ordering
3 SELECT template FROM jos_templates_menu WHERE client_id = 0 AND ( menuid = 0 OR menuid = 309 ) ORDER BY menuid DESC LIMIT 1
4 DELETE FROM jos_session WHERE ( ( time < '1548314729' ) AND guest = 0 AND gid > 0 ) OR ( ( time < '1548314729' ) AND guest = 1 AND userid = 0 )
5 SELECT COUNT(*) FROM jos_stats_agents WHERE agent = 'Unknown' AND type = 0
6 UPDATE jos_stats_agents SET hits = ( hits + 1 ) WHERE agent = 'Unknown' AND type = 0
7 SELECT COUNT(*) FROM jos_stats_agents WHERE agent = 'Unknown' AND type = 1
8 UPDATE jos_stats_agents SET hits = ( hits + 1 ) WHERE agent = 'Unknown' AND type = 1
9 SELECT COUNT(*) FROM jos_stats_agents WHERE agent = 'com' AND type = 2
10 UPDATE jos_stats_agents SET hits = ( hits + 1 ) WHERE agent = 'com' AND type = 2
11 SELECT * FROM jos_menu WHERE id = 309
12 SELECT a.*, u.name AS author, u.usertype, cc.name AS category, s.name AS section, g.name AS groups, s.published AS sec_pub, cc.published AS cat_pub, s.access AS sec_access, cc.access AS cat_access, s.id AS sec_id, cc.id as cat_id FROM jos_content AS a LEFT JOIN jos_categories AS cc ON cc.id = a.catid LEFT JOIN jos_sections AS s ON s.id = cc.section AND s.scope = 'content' LEFT JOIN jos_users AS u ON u.id = a.created_by LEFT JOIN jos_groups AS g ON a.access = g.id WHERE a.id = 186 AND ( a.state = 1 OR a.state = -1 ) AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2019-01-24 08:40' ) AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2019-01-24 08:40' ) AND a.access <= 0
13 SELECT a.id FROM jos_content AS a WHERE a.catid = 19 AND a.state = 1 AND a.access <= 0 AND ( a.state = 1 OR a.state = -1 ) AND ( a.publish_up = '0000-00-00 00:00:00' OR a.publish_up <= '2019-01-24 08:40' ) AND ( a.publish_down = '0000-00-00 00:00:00' OR a.publish_down >= '2019-01-24 08:40' ) ORDER BY a.created DESC
14 SELECT ROUND( v.rating_sum / v.rating_count ) AS rating, v.rating_count FROM jos_content AS a LEFT JOIN jos_content_rating AS v ON a.id = v.content_id WHERE a.id = 186
15 UPDATE jos_content SET hits = ( hits + 1 ) WHERE id = '186'
16 SELECT hits FROM jos_core_log_items WHERE time_stamp = '2019-01-24' AND item_table = '#__content' AND item_id = '186'
17 INSERT INTO jos_core_log_items VALUES ( '2019-01-24', '#__content', '186', 1 )
18 SELECT folder, element, published, params FROM jos_mambots WHERE access <= 0 AND folder = 'content' ORDER BY ordering
19 SELECT value FROM jos_bookmarks_prefs WHERE userid = '-1' AND category = 'params' AND name = 'urlkey'
20 SELECT value FROM jos_bookmarks_prefs WHERE userid = '-1' AND category = 'params' AND name = 'snapshotactiv'
21 SELECT value FROM jos_bookmarks_prefs WHERE userid = '-1' AND category = 'params' AND name = 'snapshotother'
22 SELECT id FROM jos_mambots WHERE element = 'mosbookmarks' AND folder = 'content'
23 SELECT * FROM jos_mambots WHERE id = '32'
24 SELECT name, value FROM jos_bookmarks_prefs WHERE userid = '-1' AND category = 'params' ORDER BY name
25 SELECT c.id, c.parent FROM jos_bookmarks_categories as c WHERE c.id = -1
26 SELECT * FROM jos_bookmarks_columns WHERE category='' AND custom='0'
27 SELECT * FROM jos_bookmarks_columns WHERE category='' ORDER BY ordering
28 SELECT * FROM jos_bookmarks_columns WHERE category='admin'
29 SELECT * FROM jos_bookmarks_columns WHERE category='admin' ORDER BY ordering
30 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
31 SELECT * FROM jos_mambots WHERE id = '27'
32 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
33 SELECT * FROM jos_mambots WHERE id = '27'
34 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
35 SELECT * FROM jos_mambots WHERE id = '27'
36 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
37 SELECT * FROM jos_mambots WHERE id = '27'
38 SELECT params FROM jos_mambots WHERE element = 'mosemailcloak' AND folder = 'content'
39 SELECT a.* FROM jos_components AS a WHERE ( a.admin_menu_link = 'option=com_syndicate' OR a.admin_menu_link = 'option=com_syndicate&hidemainmenu=1' ) AND a.option = 'com_syndicate'
40 SELECT m.id FROM jos_modules AS m WHERE m.module = 'mod_rssfeed' AND m.published = 1
41 SELECT id, title, module, position, content, showtitle, params FROM jos_modules AS m INNER JOIN jos_modules_menu AS mm ON mm.moduleid = m.id WHERE m.published = 1 AND m.access <= 0 AND m.client_id != 1 AND ( mm.menuid = 0 OR mm.menuid = 309 ) ORDER BY ordering
42 SELECT id FROM jos_menu WHERE link = 'index.php?option=com_search' AND published = 1
43 SELECT m.*, sum(case when p.published=1 then 1 else 0 end) as cnt FROM jos_menu AS m LEFT JOIN jos_menu AS p ON p.parent = m.id WHERE m.menutype='rt_splitSuckerFish' AND m.published='1' AND m.access <= '0' GROUP BY m.id ORDER BY m.parent, m.ordering
44 SELECT m.* FROM jos_menu AS m WHERE menutype='rt_splitSuckerFish' AND m.published='1'
45 SELECT * FROM jos_banner WHERE showBanner=1
46 SELECT id FROM jos_mambots WHERE element = 'mosbookmarks' AND folder = 'content'
47 SELECT * FROM jos_mambots WHERE id = '32'
48 SELECT name, value FROM jos_bookmarks_prefs WHERE userid = '-1' AND category = 'params' ORDER BY name
49 SELECT c.id, c.parent FROM jos_bookmarks_categories as c WHERE c.id = -1
50 SELECT * FROM jos_bookmarks_columns WHERE category='' AND custom='0'
51 SELECT * FROM jos_bookmarks_columns WHERE category='' ORDER BY ordering
52 SELECT * FROM jos_bookmarks_columns WHERE category='admin'
53 SELECT * FROM jos_bookmarks_columns WHERE category='admin' ORDER BY ordering
54 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
55 SELECT * FROM jos_mambots WHERE id = '27'
56 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
57 SELECT * FROM jos_mambots WHERE id = '27'
58 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
59 SELECT * FROM jos_mambots WHERE id = '27'
60 SELECT id FROM jos_mambots WHERE element = 'plugin_jw_allvideos' AND folder = 'content'
61 SELECT * FROM jos_mambots WHERE id = '27'