您发现哪些别名对您的Ubuntu体验最有用或最有用?


22

自从首次成为Ubuntu用户以来,我已经开发了越来越多的别名,还有一些我无法想象没有的别名。这使我认为可能仍然有很多我从未想过要使用的别名,这会使我和ubuntu用户的生活更加轻松。

你们使用什么别名:
常规-它们适用于许多
有用的用户-您经常使用它们,或者在您使用它们时可以节省大量时间


如果认为这太主观,请提前道歉。我认为它可以成为很好的资源,因此我认为值得尝试。
安迪·格罗夫

5
社区Wiki-fied。
Marco Ceppi

1
alias lsa='ls --color -l -A -hF --group-directories-first'
EarthmeLon

Answers:


11

这是我喜欢的一些:

#Opens current directory in a file explorer
alias explore='nautilus .'

#Opens current directory in a file explorer with super user privileges
alias suexplore='sudo nautilus .'

#Opens current directory in Ubuntu's Disk Usage Analyzer GUI with super user privileges in the background
alias analyze='gksudo baobab . &'

#Opens a GUI text editor in the background. Can obviously be replaced with your favorite editor
alias text='gedit &'
#Same as above with super user privileges
alias sutext='gksudo gedit &'

#Opens a file with whatever program would open by double clicking on it in a GUI file explorer
#Usage: try someDocument.doc
alias try='gnome-open'

#lists contents of current directory with file permisions
alias ll='ls -l -sort'

#list all directories in current directories
alias ldir='ls -l | grep ^d'

#self explanatory
alias ..='cd ..'
alias ...='cd ../../'

#show aliases
alias a='echo "------------Your aliases------------";alias'
#Apply changes to aliases
alias sa='source ~/.bash_aliases;echo "Bash aliases sourced."'
#Edit Aliases
alias via='gksudo gedit ~/.bash_aliases &'

可悲的是dd命令已经存在
伯努瓦Legat

是的,这很不错。编辑为ldir
Andy Groff


6

这些是我的首选别名:

alias ll='ls -lAbhc'
alias l='ls -lBohc'

#History search (use: hs sometext)
alias hs='history | grep $1'

#Sudo vim
alias svim='sudo vim'

#Add extra protection against mistakes
alias rm='rm -I'

#Unrar alias
alias unrar='rar e'

1
我将完全使用历史记录搜索和rm保护。很棒的补充!
安迪·格罗夫

4

我最喜欢的几个(也是最常用的!)是:

alias tgz='tar -zxvf'

alias tbz='tar -jxvf'

2

这是我从这个github项目获得的设置:https : //github.com/roubles/bash_aliases

###############################################################################
##
## Essentials
alias rm="rm -i" # Confrim remove

###############################################################################
##
## ls variations
alias la="ls -AF"                   # List all files
alias ld="ls -d */"                 # List only directories
alias l.="ls -A | egrep '^\.'"      # List only dotfiles (hidden files)
alias l1='ls -1AF'                  # List files (one line at a time)
alias ll="ls -lhAF"                 # List all file details
alias lg="ls -AF | grep"            # Grep through filenames (also see, hg)
alias lp="ls -d `pwd`/*"            # List full paths
alias lpg="ls -d `pwd`/* | grep"    # Grep through filenames but list full path
alias lt="ls -Alt"                  # Sort by time
alias ltr="ls -Altr"                # Sort by time (reverse)
alias lss="ls -AFlS"                # Sort by size
alias lsr="ls -AFlSr"               # Sort by size (reverse)

###############################################################################
##
#typos
alias vi="vim"
alias vmi="vim"
alias sl="ls"
alias pdw="pwd"

###############################################################################
##
#tar
alias tarc="tar czvf"
alias tarx="tar xzvf"
alias tart="tar tzvf"

###############################################################################
##
#history
alias hg='history | grep'

###############################################################################
##
#chmod
alias ax="chmod a+x"

###############################################################################
##
# Jump down
alias 1d="cd .."
alias 2d="cd ..;cd .."
alias 3d="cd ..;cd ..;cd .."
alias 4d="cd ..;cd ..;cd ..;cd .."
alias 5d="cd ..;cd ..;cd ..;cd ..;cd .."

###############################################################################
##
# Jump down (reverse)
alias 1up='cd /$(echo $PWD | cut -f 2 -d /)'
alias 2up='cd /$(echo $PWD | cut -f 2,3 -d /)'
alias 3up='cd /$(echo $PWD | cut -f 2,3,4 -d /)'
alias 4up='cd /$(echo $PWD | cut -f 2,3,4,5 -d /)'
alias 5up='cd /$(echo $PWD | cut -f 2,3,4,5,6 -d /)'

您是否发现alias ld="ls -d */"干扰“真实” ld(链接器)?
Scott Odle's

1

我目前使用122个别名,因此我不会列出所有别名,但这是一些有用的别名的简短列表:

 # Key press savers
 #  Naturally, key press saving aliases like these are really user-dependent.
 #  These are just a few examples.
alias s='sudo ' # the space allows for command name expansion.
alias g='git'
alias q='exit'

alias ls='ls --color=auto' # color
alias l='ls -F'            # classify
alias la='l -A'            # classify, hidden

alias ll='l -lh'  # human readable
alias lla='ll -A' # hidden

alias x='clear;'
alias xl='clear; l'
alias xla='clear; la'

# not really an alias, but it can be useful
cl () { cd $@ && ls -F; }

alias rs='rsync -avz --progress --fuzzy -e "ssh"'
alias rsd='rsync -avz --progress --delete-after --fuzzy -e "ssh"'

我曾经有一个小的shell函数,它可以根据传递给它的内容而更改为目录或编辑文件。当您转到目录但决定在此处编辑文件时,这将非常有用。我编写了一个源程序化的shell函数,该函数可以执行此操作以及更多操作:https : //github.com/Paradoxial/fin/blob/master/forward.sh。我目前正在重写它以处理各种文件:https : //github.com/Paradoxial/fin/blob/super-f/forwards.sh


别名的用途是什么exit?ctrl-d仅是两次按键,比q-enter所需的操作少。
左右左转

1

这是我的别名列表。其中很少有人已被列入他人的名单。

# Very frequently used. Use: psg java
alias psg='ps aux | grep -i $1'

alias ..='cd ..'
alias ...='cd ../../'

# Updates repo cache and installs all kinds of updates
alias update='sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade'

# Frees up the cached memory
alias freemem='sync && echo 3 | sudo tee /proc/sys/vm/drop_caches'

# Useful for history searching. Use: hs java
alias hs='history | grep -i $1'

1

有一个名为alias.sh的网站。其他用户定义了很多别名,您可以将自己的别名添加到网站,其他人将对其进行评分。您甚至可以将一些喜欢的别名添加到列表中并使用它们。我什至通过创建别名来添加别名列表来更新别名列表~/.bashrc

alias s-update-aliassh='curl -s https://alias.sh/user/{Your User}/alias > ~/.bash_aliases; exec bash'

0

我真的很喜欢使用别名来更快地创建别名。这与在Fish shell中可以使用“函数”和“函数保存”的方式类似-无需在文本编辑器中打开任何文件。

尽管部分出于这个原因,我使用Fish壳,但是您可以在Bash中进行类似的操作:

$ echo -e "function alia { \n echo -e \"\n function \$1 { \n \$2 \n }\" >> ~/.bashrc \n }" >> ~/.bashrc

# restart shell to use
# usage: $ alia "name" "cmd"
#  e.g.: $ alia "gac" "git add -A; git commit -m \"\$1\" "
#        $ bash
#        $ gac "my commit message"
#         
#         $1 refers to a variable
#         note that $ and " characters are escaped in the alias content

0

这是我用来备份PPA的一个。

#List all of my ppas in a text file dumpable form that can be fed into a script 
#     for re-loading them. Perfect for backup prior to an upgrade.
#Note the ppasrestore function below.  
alias lsppas="grep -RoPish '(?<=ppa.launchpad.net/)[^/]+/[^/ ]+' /etc/apt | sort -u | sed 's/^/ppa:/'"

function ppasrestore {

    for I in `cat $1`
    do 
        sudo add-apt-repository $I
    done
}
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.