linux终端不现实路径,【已解决】Ubuntu中让终端只显示当前路径,而不显示绝对路径...

【问题】

Ubuntu下,默认情况下,对于终端,是显示出绝对的路径的,比如:

027e7eb1ad5071897d5a2791b26fa04a.png

现在想要让其只显示相对路径。

【解决过程】

1.参考:

去将.bashrc中的,有关PS1的部分,从:if [ “$color_prompt” = yes ]; then

PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ‘

else

PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ‘

fi

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir

case “$TERM” in

xterm*|rxvt*)

PS1=”\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1″

;;

*)

;;

esac

改为:if [ “$color_prompt” = yes ]; then

PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ‘

else

PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ‘

fi

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir

case “$TERM” in

xterm*|rxvt*)

PS1=”\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \W\a\]$PS1″

;;

*)

;;

esac

1a02755fc63b592a933f5d59f0d835cb.png

2.保存修改,退出gedit。然后再source一下,发现终端的标题变成当前路径了:

0724417de182704f1601d5ecc65cc854.png

3.再重启终端,看看是否生效,结果还是不行。

4.再去把上面那个PS1中的值,变成:if [ “$color_prompt” = yes ]; then

PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ ‘

else

PS1=’${debian_chroot:+($debian_chroot)}\u@\h:\W\$ ‘

fi

unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir

case “$TERM” in

xterm*|rxvt*)

PS1=”\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \W\a\]$PS1″

;;

*)

;;

esac

然后保存退出gedit,再source一下,结果就可以了:crifan@ubuntu:~/develop/crosstool-ng/crosstool-ng-1.18.0_build$ gedit ~/.bashrc

crifan@ubuntu:~/develop/crosstool-ng/crosstool-ng-1.18.0_build$ source ~/.bashrccrifan@ubuntu:crosstool-ng-1.18.0_build$

效果如下:

ec35151f43f6da3f1fba3bf3f2747487.png

【总结】

想要将Ubuntu的终端,中的绝对路径的显示,变成当前路径(文件夹)的话,则需要去修改自己的.bashrc,将其中的小写的w,改为大写的W即可:

(1)针对终端的标题title

从:# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

;;

*)

;;

esac

改为:# If this is an xterm set the title to user@host:dir

case "$TERM" in

xterm*|rxvt*)

PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \W\a\]$PS1"

;;

*)

;;

esac

(2)针对终端的当前显示prompt

从:if [ "$color_prompt" = yes ]; then

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

else

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

fi

unset color_prompt force_color_prompt

改为:if [ "$color_prompt" = yes ]; then

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '

else

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '

fi

unset color_prompt force_color_prompt

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 要运行一个.o文件,需要使用终端命令进行操作。首先,你需要确认.o文件是否已经编译成可执行文件。如果没有,请使用以下命令将其编译: ``` gcc -o filename filename.o ``` 其,filename是你的.o文件名。使用此命令将生成一个可执行文件,其文件名与输入的.o文件名相同。 接下来,你可以使用以下命令来运行可执行文件: ``` ./filename ``` 这将运行你的程序,并在终端显示输出。 ### 回答2: 在Linux使用终端运行.o文件的步骤如下: 1. 打开终端:在桌面的左上角或者导航栏找到终端图标,点击打开。 2. 切换到.o文件所在的目录:使用cd命令切换到.o文件所在的目录。例如,如果.o文件在桌面上的一个文件夹,使用cd命令切换到该文件夹。可以使用"cd 桌面/文件夹名称"来进入该文件夹。 3. 编译.o文件:在终端输入"gcc 文件名.o -o 可执行文件名"进行.o文件的编译,并指定生成的可执行文件的名称。例如,如果.o文件的名称为test.o,可执行文件的名称为test,那么输入的命令为"gcc test.o -o test"。按下回车键执行命令。 4. 运行可执行文件:在终端输入"./可执行文件名"来运行可执行文件。例如,如果可执行文件的名称为test,那么输入的命令为"./test"。按下回车键执行命令。 需要注意的是,编译和运行.o文件需要确保系统已经安装了gcc编译器。如果系统没有安装gcc编译器,可以使用以下命令进行安装: 在Debian或Ubuntu上,运行"sudo apt-get install build-essential"命令安装gcc编译器。 在CentOS或Fedora上,运行"sudo yum groupinstall 'Development Tools'"命令安装gcc编译器。 通过以上步骤,可以使用终端Linux运行.o文件。 ### 回答3: 在Linux,可以使用终端运行.o文件。.o文件是编译完成的目标文件,需要链接器将其与其他目标文件和库文件一起链接,生成可执行文件。 首先,在终端进入到包含.o文件的目录。可以使用cd命令切换目录。 然后,使用gcc命令进行链接,将.o文件与其他目标文件和库文件一起链接。例如,如果要链接test.o文件和libtest.a静态库文件,可以运行以下命令: gcc -o executable test.o -L. -ltest 其,-o指定生成的可执行文件的名称,executable为可执行文件的名字;test.o是要链接的.o文件;-L.表示链接器在当前目录查找库文件;-ltest表示链接libtest.a库文件。 接着,可以运行生成的可执行文件。在终端输入可执行文件的名称,即可运行。例如,运行上述命令生成的可执行文件,可以输入以下命令运行: ./executable 注意,如果在链接过程有依赖的库文件缺失,需要在链接命令指定其所在的路径或安装相应的库文件。 总结起来,要在Linux使用终端运行.o文件,需要进入到包含该文件的目录,使用gcc命令进行链接,并指定生成的可执行文件名称及其他依赖的目标文件和库文件,然后通过在终端输入可执行文件名称进行运行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值