JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Mac Modify the host name and prompt in terminal and iterm

Author:JIYIK Last Updated:2025/04/07 Views:

Commonly used terminals on Mac are terminal and iterm. In many cases, we need to modify the host name displayed in these terminals.

Mac Terminal

As shown in the figure above, we use the command hostnameto view the current host name

mac hostname command to view the host name

From the results we can see that the host name is "Ji Yi Ke".

To change the host name, use the following command

$ sudo scutil --set HostName newHostName

For example, we change the host name to "迹忆"

$ sudo scutil --set HostName 迹忆

After the above command, restart the terminal and we can see that the host name has been changed.

mac View the modified host name

Sometimes we need to modify the prompt in the terminal. For example, we want to modify the jiyik.com displayed in the terminal. If you want to modify this, you need to edit the /etc/bashrc filePS1

Now let's take a look at the contents of /etc/bashrc on my machine

# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then
   return
fi

PS1='\h:\W jiyik.com\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize

[ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM"

Let's do a simple analysis of the contents of PS1: -hit represents the host name; \Wit represents the current directory; followed by a fixed string - jiyik.com; and then the prompt$

These items constitute the prompt displayed by our terminal

Mac terminal prompt components

At this point, it is relatively easy to modify the content of the terminal prompt. We only need to replace "jiyik.com" with another string. For example, we change it to "jiyik". We only need to modify PS1 as shown below

PS1='\h:\W jiyik\$ '

After saving and exiting, restart the terminal and you can see that the prompt has been changed.

Mac Modify Terminal Prompt

We have learned about the composition of the terminal prompt, which is mainly PS1controlled by . In this way, we can construct our favorite terminal prompt.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Creating a signature from Hash_hmac() and Sha256 in PHP

Publish Date:2025/04/13 Views:107 Category:PHP

PHP has one of the best encryption functions for data security. Hash_hmac() The encrypt function is one of the most famous encryptors. We'll show you how to use hash_hmac and sha256 encryptors to create 安全签名 one that you can store i

Running PHP on Mac

Publish Date:2025/04/12 Views:183 Category:PHP

In this article, we'll show you how to run PHP on your Mac. php -S Run PHP on Mac using command PHP is a server-side language. It runs on a server. Therefore, it requires a web server to run. There are different web servers like Apache HTTP

How to use clion to debug redis source code on mac system

Publish Date:2025/04/09 Views:172 Category:Redis

clion mainly uses cmake + make for compilation. So for redis4, the main thing is to write the CMakeLists.txt file first. CmakeLists.txt file redis4/CMakeLists.txt cmake_minimum_required (VERSION 3.15 ) project (redis4) set (CMAKE_BUILD_TYPE

Mac system uses clion to remotely debug redis4 source code

Publish Date:2025/04/09 Views:129 Category:Redis

The remote host uses the Linux system. The first step is definitely to establish a code synchronization mechanism on the local and remote hosts - sftp is the first choice. The second step is to write the CMakeLists.txt file of redis4. There

Solve the problem of gdb debugging on Mac system

Publish Date:2025/04/07 Views:93 Category:OPERATING SYSTEM

On a Mac, you may encounter the following error when using gdb for the first time: (gdb) run Starting program: /usr/ local /bin/order_monitor Unable to find Mach task port for process-id 26551: (os/kern) failure (0x5). (please check gdb is

PHPStorm shortcut keys for Win/Linux/Mac

Publish Date:2025/04/07 Views:125 Category:OPERATING SYSTEM

edit Win / Linux Mac Notes Frequency of use Ctrl + Space ⌃Space Code auto-completion (usually conflicts with input method) ★☆☆☆☆ Ctrl + Shift + Enter ⌘ ⇧ ↩ Intelligent code completion (such as: if ()) ★☆☆☆☆ Ctrl

Mac shuts down BaiduNetdiskSync service

Publish Date:2025/04/07 Views:193 Category:OPERATING SYSTEM

I don't know if you have installed Baidu Netdisk on your Mac. If you have installed and used it, we will find through Activity Monitor that there is a baiduNetdiskSync service that has always existed. It is very distressing. Let's shut down

Installing and configuring Redis on Mac OS X via Homebrew

Publish Date:2025/04/07 Views:108 Category:OPERATING SYSTEM

By using Homebrew, you can greatly reduce the cost of setting up and configuring a development environment on Mac OS X. Let's install Redis. $ brew install redis After installation, we will see some notifications about configuration conside

PBKDF2+HMAC Hash Conflict

Publish Date:2025/04/06 Views:56 Category:OPERATING SYSTEM

Cryptocurrency enthusiast Christian 'CodesInChaos' Winnerlein once wrote: plnlrtfpijpuhqylxbgqiiyipieyxvfsavzgxbbcfusqkozwpngsyejqlmjsytrmd and eBkXQTfuBqp'cTcarg* have the same PBKDF2-HMAC-SHA1 hash. This intrigued me, so I decided to find

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial