我是Kubuntu用户。

如果我输入
$ apt-get(标签)
在终端上,壳牌提供了以下建议:
自动清理,生成,检查,...,清理,下载,安装,删除,更新

如果要在路径中使用别名或Shell脚本的选项中使用自定义命令,如何使Terminal(或Shell)建议选项?

例如,命令为“ myclock”,其选项为“ us”和“ korea”。
如果我输入
$ myclock韩国
->(打印韩国时间)
如果我输入
$我的时钟
->(打印美国时间)
键入时如何使终端机建议选项(“我们”或“韩国”)
$ myclock(标签)

先感谢您!

最佳答案

您将需要通过.bash_profile或kubuntu .profile添加自定义别名。

sudo进入root并使用您选择的文本编辑器。我更喜欢vi,但您可以使用nano!

 sudo -i
  root@server vi .profile


默认情况下,您的个人资料应如下所示

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

mesg n


所以现在添加一个别名。您可以为别名命名!这是我使用的.profile的自定义别名。我在旧金山工作,居住在奥克兰,所以天气可能会略有不同,所以我创建了一个自定义别名来适应天气

alias weatherSF="curl -s 'http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=en|us|san-francisco-ca|94103' | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'"
alias weatherOak="curl -s 'http://rss.accuweather.com/rss/liveweather_rss.asp?metric=1&locCode=en|us|Oakland-ca|94612' | sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \1/p'"


现在请注意,如果您尝试使用制表符将无法使用..因此,您需要做的是

source ~/.profile


在来源之后,您应该可以选择新的别名!

如果您对其他别名感兴趣,这里有一些其他示例

alias myip='curl ip.appspot.com'                    # myip:         Public facing IP Address
alias netCons='lsof -i'                             # netCons:      Show all open TCP/IP sockets
alias flushDNS='dscacheutil -flushcache'            # flushDNS:     Flush out the DNS Cache
alias lsock='sudo /usr/sbin/lsof -i -P'             # lsock:        Display open sockets
alias lsockU='sudo /usr/sbin/lsof -nP | grep UDP'   # lsockU:       Display only open UDP sockets
alias lsockT='sudo /usr/sbin/lsof -nP | grep TCP'   # lsockT:       Display only open TCP sockets
alias ipInfo0='ipconfig getpacket en0'              # ipInfo0:      Get info on connections for en0
alias ipInfo1='ipconfig getpacket en1'              # ipInfo1:      Get info on connections for en1
alias openPorts='sudo lsof -i | grep LISTEN'        # openPorts:    All listening connections
alias showBlocked='sudo ipfw list'                  # showBlocked:  All ipfw rules inc/ blocked IPs


check this website for some tips

10-08 10:54
查看更多