AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题

问题[alias](ubuntu)

Martin Hope
Octopus
Asked: 2022-04-23 09:12:39 +0800 CST

如何在鱼的别名中运行别名?

  • 1

sudo我用please 空格别名:

$ alias please='sudo '
$ please ll

我已经在 Fish 中尝试过,但它不起作用:

$ alias please='sudo '
$ please ll
sudo: ll: command not found
alias
  • 1 个回答
  • 215 Views
Martin Hope
Rajesh Chaudhary
Asked: 2020-12-10 06:59:33 +0800 CST

“watch”命令不适用于别名

  • 3

watch 命令不适用于别名命令。

没有别名

➜  scrcpy git:(master) git -P branch
* master
➜  scrcpy git:(master) watch git branch

在此处输入图像描述

带别名

➜  scrcpy git:(master) which gb
gb: aliased to git branch
➜  scrcpy git:(master) watch gb

在此处输入图像描述

alias 20.04 watch-command
  • 1 个回答
  • 1217 Views
Martin Hope
Daniel
Asked: 2020-12-01 12:08:52 +0800 CST

bash.bashrc 不适用于所有用户

  • 0

因此,当我在 /etc/bash.bashrc 文件中添加该行并重新登录时,我的 PC 上有 2 个用户alias abc='echo Hello',它仅适用于第一个用户。(我更改文件的那个)我什至重新启动了我的电脑,但仍然没有工作。

这是我的 bash.bashrc 文件(我知道这不是必需的,只是为了提供更多信息):

alias abc='echo Hi' # <<< Here's the line I've added



# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
# but only if not SUDOing and have SUDO_PS1 set; then assume smart user.
if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
#    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
#    ;;
#*)
#    ;;
#esac

# enable bash completion in interactive shells
#if ! shopt -oq posix; then
#  if [ -f /usr/share/bash-completion/bash_completion ]; then
#    . /usr/share/bash-completion/bash_completion
#  elif [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#  fi
#fi

# sudo hint
if [ ! -e "$HOME/.sudo_as_admin_successful" ] && [ ! -e "$HOME/.hushlogin" ] ; then
    case " $(groups) " in *\ admin\ *|*\ sudo\ *)
    if [ -x /usr/bin/sudo ]; then
    cat <<-EOF
    To run a command as administrator (user "root"), use "sudo <command>".
    See "man sudo_root" for details.
    
    EOF
    fi
    esac
fi

# if the command-not-found package is installed, use it
if [ -x /usr/lib/command-not-found -o -x /usr/share/command-not-found/command-not-found ]; then
    function command_not_found_handle {
            # check because c-n-f could've been removed in the meantime
                if [ -x /usr/lib/command-not-found ]; then
           /usr/lib/command-not-found -- "$1"
                   return $?
                elif [ -x /usr/share/command-not-found/command-not-found ]; then
           /usr/share/command-not-found/command-not-found -- "$1"
                   return $?
        else
           printf "%s: command not found\n" "$1" >&2
           return 127
        fi
    }
fi

我也在运行 xubuntu 18.04.5 LTS。

bash user-management bashrc alias users
  • 1 个回答
  • 906 Views
Martin Hope
elanozturk
Asked: 2020-10-30 12:23:54 +0800 CST

关于终端错误的 .bashrc 别名帮助

  • 0

我在 .bashrc 文件上有别名,例如;

alias modemreboot="IP=$(/sbin/ip route | awk '/default/ { print $3 }');echo "reboot" | sshpass -p "12345" ssh admin@$IP"

用于通过命令行重新启动我的调制解调器。当我键入或复制并粘贴到终端时,它可以工作,但是作为别名,我收到此错误;

Pseudo-terminal will not be allocated because stdin is not a terminal.
ssh: Could not resolve hostname : Name or service not known
command-line bashrc alias 20.10
  • 1 个回答
  • 93 Views
Martin Hope
Yehuda
Asked: 2020-08-11 16:37:12 +0800 CST

使用 apt-get 为 apt-get update 创建别名

  • 1

我注意到我看到的很多博客都建议apt-get update在运行任何apt-get install. 考虑到我对 apt-get 的许多(大多数?)使用涉及安装,它似乎永远不会受到伤害,而且只需要几秒钟,在我看来,创建一个alias apt-get="apt-get update; apt-get". 作为 Linux 和一般命令行的新手,我可以想象这里有很多我忽略的东西,而且我知道从命令行破坏计算机非常容易。有什么特别的理由建议不要使用这个别名吗?(我知道这可能会作为一个基于意见的问题而结束。我想澄清一下,我对基于事实的可靠建议而不是意见感兴趣。)

package-management updates apt alias
  • 1 个回答
  • 1490 Views
Martin Hope
Vima
Asked: 2020-07-28 04:30:25 +0800 CST

别名转到文件夹中的最新文件夹

  • 14

我们以“result-yyyy-mm-dd-hh-mm-ss”的格式将机器人结果创建到单独的文件夹中,我目前在我的 bash_aliases 中有这个

alias res="VAR=$(ls --directory /path/to/results/res* | tail -n 1); cd $" 

它工作正常一次..然后我必须重新加载我的 bashrc 以使其再次工作。尝试将重新加载烘焙到一个新的别名中,但在切换到较新的文件夹之前仍然必须使用 2-3 次。

bash alias
  • 4 个回答
  • 1330 Views
Martin Hope
amortaza
Asked: 2020-07-06 08:13:37 +0800 CST

在调用 `source .profile` 之前无法识别 `.profile` 中的 `alias` 命令

  • 5

.profile我的主目录中的文件中有以下行:

alias flux='redshift -O 2500'

但是每当我登录并输入时,flux我都会得到一个flux is not a recognized command.

然后我再次source .profile输入并输入flux,它工作得很好。

我在 Ubuntu 20.04

为什么alias我.profile不工作,除非我做一个source .profile?

编辑:我现在明白这.profile不是放置这个的正确位置。

我最终使用以下命令从.bashrc文件中加载别名:source

for file in ~/.dotfiles/.{exports,aliases}; do
    [ -r "$file" ] && source "$file"
done
unset file
alias .profile
  • 1 个回答
  • 1479 Views
Martin Hope
code-8
Asked: 2020-06-04 14:24:48 +0800 CST

多个别名触发相同的功能

  • 0

我正在尝试创建一个函数,但我想通过任一别名触发:debugApp,debugApi

而不是创建 2 个函数来做同样的事情

debugApp() {

    #update .env to generate log
    sed -i -e 's/.*API_DEBUG=.*/API_DEBUG=true/g' /Users/jdoe/laravel/.env
    echo "-----------------------"
    cat /Users/jdoe/laravel/.env | grep API_DEBUG


    #remove old logs
    # rm -rf /Users/jdoe/laravel/storage/logs/*
    ls /Users/jdoe/laravel/storage/logs/

    #display correct logs
    tail -f /Users/jdoe/laravel/storage/logs/laravel-$(date "+%Y-%m-*").log
}


debugApi() {

    #update .env to generate log
    sed -i -e 's/.*API_DEBUG=.*/API_DEBUG=true/g' /Users/jdoe/laravel/.env
    echo "-----------------------"
    cat /Users/jdoe/laravel/.env | grep API_DEBUG


    #remove old logs
    # rm -rf /Users/jdoe/laravel/storage/logs/*
    ls /Users/jdoe/laravel/storage/logs/

    #display correct logs
    tail -f /Users/jdoe/laravel/storage/logs/laravel-$(date "+%Y-%m-*").log
}

有没有更好的办法?

command-line bash bashrc alias functions
  • 1 个回答
  • 49 Views
Martin Hope
Sanjay Prajapat
Asked: 2020-03-07 05:46:16 +0800 CST

“echo $?”的别名 不工作

  • 0

我正在尝试为其echo $?返回最近执行的命令的退出状态设置别名。我已经投入alias status="echo $?"了~/.bashrc。但它不起作用,它总是返回 0。

user@host:~$ lll
bash: lll: command not found
user@host:~$ echo $?
127
user@host:~$ lll
bash: lll: command not found
user@host:~$ status
0
user@host:~$ 

如何为此设置别名。

command-line bash alias
  • 1 个回答
  • 886 Views
Martin Hope
Galz
Asked: 2020-02-21 10:15:22 +0800 CST

带有多个命令的 ZSH 别名给出“找不到命令”

  • 0

我正在使用这一系列命令来构建和运行一个 docker 容器。这些命令在结合&&并给出如下输出时起作用:

> docker stop $(docker ps -a -q  --filter ancestor=redoc1) && docker build -t redoc1 . && docker run  -p 8070:80 -d redoc1 
4127c16715e8
3995f290bcf3
60cacd2d669b
7e509bd0f443
69e186743360
1caad359f950
Sending build context to Docker daemon  113.7kB
Step 1/2 : FROM redocly/redoc:v2.0.0-rc.18
 ---> 262cf1bbd824
Step 2/2 : COPY config/docker/index.tpl.html /usr/share/nginx/html/index.html
 ---> Using cache
 ---> a8b03c1555c5
Successfully built a8b03c1555c5
Successfully tagged redoc1:latest
183bd1af2d61968e67c6b0eec27d24a5892851ddc15b41bc155b8335de83f0ac

我正在使用 Z Shell,并且通常为这些重复的命令集设置别名。成功,直到现在。

我在中创建了以下内容~/.zshrc:

alias redocly-local-deploy="docker stop $(docker ps -a -q  --filter ancestor=redoc1) && docker build -t redoc1 . && docker run  -p 8070:80 -d redoc1"

它与上面的命令完全相同,直接在 shell 中工作。

但是在运行别名时(在重新加载 zshrc 之后),它在第一个(或第二个?)命令之后失败:

> redocly-local-deploy 
4127c16715e8
zsh: command not found: 3995f290bcf3
zsh: command not found: 60cacd2d669b
zsh: command not found: 7e509bd0f443
zsh: command not found: 69e186743360
zsh: command not found: 1caad359f950

看起来第一个命令的输出把它扔掉了。我尝试添加> /dev/null到第一个命令,但得到了相同的结果。

感谢任何帮助!

command-line zsh alias
  • 1 个回答
  • 1715 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve