Question

Is there a way I can hide the hostname on the terminal without updating the /etc/hosts or related files.

Generally we see the server details on screen as below

[root@ServernamE /]#

So, I don't want the hostname = ServernamE to be displayed on terminal. The reason for doing this is, I will be recording a web session. I know that I can morph the desired part but that is time consuming and depend on other softwares.

Thanks

Was it helpful?

Solution

If you want a temporary solution(since you are talking about a screencast), you can set your PS1 variable to change the prompt.

For example, if you want your prompt to be:

$

Then set your PS1 variable as follows on the terminal:

export PS1='$ '

Likewise, you can have it to whatever you want the prompt to look like. If you want the path to be displayed, set it as:

export PS1='\w '

For a permanent solution, you can set this in your shell configuration script, which is your ~/.bashrc file in case you have bash as your shell.

OTHER TIPS

alot answer just suggest paste this PS1='\w....... ' without telling what the variables are, basically we only need to know 3 variables; \u = username, \h = hostname, \w = current directory then for example

PS1='\u@\h:\w \$ '

will become

john@mypc:/home/dir $

and here the complete list

Special prompt variable characters:
 \d   The date, in "Weekday Month Date" format (e.g., "Tue May 26"). 
 \h   The hostname, up to the first . (e.g. deckard) 
 \H   The hostname. (e.g. deckard.SS64.com)
 \j   The number of jobs currently managed by the shell. 
 \l   The basename of the shell's terminal device name. 
 \s   The name of the shell, the basename of $0 (the portion following the final slash). 
 \t   The time, in 24-hour HH:MM:SS format. 
 \T   The time, in 12-hour HH:MM:SS format. 
 \@   The time, in 12-hour am/pm format. 
 \u   The username of the current user. 
 \v   The version of Bash (e.g., 2.00) 
 \V   The release of Bash, version + patchlevel (e.g., 2.00.0) 
 \w   The current working directory. 
 \W   The basename of $PWD. 
 \!   The history number of this command. 
 \#   The command number of this command. 
 \$   If you are not root, inserts a "$"; if you are root, you get a "#"  (root uid = 0) 
 \nnn   The character whose ASCII code is the octal value nnn. 
 \n   A newline. 
 \r   A carriage return. 
 \e   An escape character (typically a color code). 
 \a   A bell character.
 \\   A backslash. 
 \[   Begin a sequence of non-printing characters. (like color escape sequences). This
      allows bash to calculate word wrapping correctly.
 \]   End a sequence of non-printing characters.

source

If you frequently want to hide the terminal info temporarily, you can create a bash alias for this in the .bashrc:

# hti - hide terminal info
alias hti='clear && export PS1="$ "'

And use the alias instead:

$ hti

To get back the terminal info, do (you can create an alias for this as well):

exec "$BASH"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top