An alias is nothing but shortcut to commands. The alias command allows user to launch any command or group of commands (including options and filenames) by entering a single word. Use alias command to display list of all defined aliases. You can add user defined aliases to ~/.bashrc file. You can cut down typing time with these aliases, work smartly, and increase productivity at the command prompt.
More about aliases
The general syntax for the alias command for the bash shell is as follows.
Task: List aliases
Type the following command:
alias
Sample outputs:
alias ..='cd ..' alias amazonbackup='s3backup' alias apt-get='sudo apt-get' ...
By default alias command shows a list of aliases that are defined for the current user.
Task: Define / create an alias (bash syntax)
To create the alias use the following syntax:
alias name=value alias name='command' alias name='command arg1 arg2' alias name='/path/to/script' alias name='/path/to/script.pl arg1'
In this example, create the alias c for the commonly used clear command, which clears the screen, by typing the following command and then pressing the ENTER key:
alias c='clear'
Then, to clear the screen, instead of typing clear, you would only have to type the letter 'c' and press the [ENTER] key:
c
Task: Disable an alias temporarily (bash syntax)
An alias can be disabled temporarily using the following syntax:
## path/to/full/command /usr/bin/clear ## call alias with a backslash ## \c
Task: Remove an alias (bash syntax)
You need to use the command called unalias to remove aliases. Its syntax is as follows:
unalias aliasname
In this example, remove the alias c which was created in an earlier example:
unalias c
You also need to delete the alias from the ~/.bashrc file using a text editor (see next section).
Task: Make aliases permanent (bash syntax)
The alias c remains in effect only during the current login session. Once you logs out or reboot the system the alias c will be gone. To avoid this problem, add alias to your ~/.bashrc file, enter:
vi ~/.bashrc
The alias c for the current user can be made permanent by entering the following line:
alias c='clear'
Save and close the file. System-wide aliases (i.e. aliases for all users) can be put in the /etc/bashrc file. Please note that the alias command is built into a various shells including ksh, tcsh/csh, ash, bash and others.
A note about privileged access
You can add code as follows in ~/.bashrc:
# if user is not root, pass all commands via sudo # if [ $UID -ne 0 ]; then alias reboot='sudo reboot' alias update='sudo apt-get upgrade' fi
A note about os specific aliases
You can add code as follows in ~/.bashrc using the case statement:
### Get os name via uname ### _myos="$(uname)" ### add alias as per os using $_myos ### case $_myos in Linux) alias foo='/path/to/linux/bin/foo';; FreeBSD|OpenBSD) alias foo='/path/to/bsd/bin/foo' ;; SunOS) alias foo='/path/to/sunos/bin/foo' ;; *) ;; esac
30 uses for aliases
You can define various types aliases as follows to save time and increase productivity.
#1: Control ls command output
The ls command lists directory contents and you can colorize the output:
## Colorize the ls output ## alias ls='ls --color=auto' ## Use a long listing format ## alias ll='ls -la' ## Show hidden files ## alias l.='ls -d .* --color=auto'
#2: Control cd command behavior
## get rid of command not found ## alias cd..='cd ..' ## a quick way to get out of current directory ## alias ..='cd ..' alias ...='cd ../../../' alias ....='cd ../../../../' alias .....='cd ../../../../' alias .4='cd ../../../../' alias .5='cd ../../../../..'
#3: Control grep command output
grep command is a command-line utility for searching plain-text files for lines matching a regular expression:
## Colorize the grep command output for ease of use (good for log files)## alias grep='grep --color=auto' alias egrep='egrep --color=auto' alias fgrep='fgrep --color=auto'
#4: Start calculator with math support
alias bc='bc -l'
#4: Generate sha1 digest
alias sha1='openssl sha1'
#5: Create parent directories on demand
mkdir command is used to create a directory:
alias mkdir='mkdir -pv'
#6: Colorize diff output
You can compare files line by line using diff and use a tool called colordiff to colorize diff output:
# install colordiff package :) alias diff='colordiff'
#7: Make mount command output pretty and human readable format
alias mount='mount |column -t'
#8: Command short cuts to save time
# handy short cuts # alias h='history' alias j='jobs -l'
#9: Create a new set of commands
alias path='echo -e ${PATH//:/\\n}' alias now='date +"%T' alias nowtime=now alias nowdate='date +"%d-%m-%Y"'
#10: Set vim as default
alias vi=vim alias svi='sudo vi' alias vis='vim "+set si"' alias edit='vim'
#11: Control output of networking tool called ping
# Stop after sending count ECHO_REQUEST packets # alias ping='ping -c 5' # Do not wait interval 1 second, go fast # alias fastping='ping -c 100 -s.2'
#12: Show open ports
Use netstat command to quickly list all TCP/UDP port on the server:
alias ports='netstat -tulanp'
#13: Wakeup sleeping servers
Wake-on-LAN (WOL) is an Ethernet networking standard that allows a server to be turned on by a network message. You can quickly wakeup nas devices and server using the following aliases:
## replace mac with your actual server mac address # alias wakeupnas01='/usr/bin/wakeonlan 00:11:32:11:15:FC' alias wakeupnas02='/usr/bin/wakeonlan 00:11:32:11:15:FD' alias wakeupnas03='/usr/bin/wakeonlan 00:11:32:11:15:FE'
#14: Control firewall (iptables) output
Netfilter is a host-based firewall for Linux operating systems. It is included as part of the Linux distribution and it is activated by default. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.
## shortcut for iptables and pass it via sudo# alias ipt='sudo /sbin/iptables' # display all rules # alias iptlist='sudo /sbin/iptables -L -n -v --line-numbers' alias iptlistin='sudo /sbin/iptables -L INPUT -n -v --line-numbers' alias iptlistout='sudo /sbin/iptables -L OUTPUT -n -v --line-numbers' alias iptlistfw='sudo /sbin/iptables -L FORWARD -n -v --line-numbers' alias firewall=iptlist
#15: Debug web server / cdn problems with curl
# get web server headers # alias header='curl -I' # find out if remote server supports gzip / mod_deflate or not # alias headerc='curl -I --compress'
#16: Add safety nets
# do not delete / or prompt if deleting more than 3 files at a time # alias rm='rm -I --preserve-root' # confirmation # alias mv='mv -i' alias cp='cp -i' alias ln='ln -i' # Parenting changing perms on / # alias chown='chown --preserve-root' alias chmod='chmod --preserve-root' alias chgrp='chgrp --preserve-root'
#17: Update Debian Linux server
apt-get command is used for installing packages over the internet (ftp or http). You can also upgrade all packages in a single operations:
# distro specific - Debian / Ubuntu and friends # # install with apt-get alias apt-get="sudo apt-get" alias updatey="sudo apt-get --yes" # update on one command alias update='sudo apt-get update && sudo apt-get upgrade'
#18: Update RHEL / CentOS / Fedora Linux server
yum command is a package management tool for RHEL / CentOS / Fedora Linux and friends:
## distrp specifc RHEL/CentOS ## alias update='yum update' alias updatey='yum -y update'
#19: Tune sudo and su
# become root # alias root='sudo -i' alias su='sudo -i'
#20: Pass halt/reboot via sudo
shutdown command bring the Linux / Unix system down:
# reboot / halt / poweroff alias reboot='sudo /sbin/reboot' alias poweroff='sudo /sbin/poweroff' alias halt='sudo /sbin/halt' alias shutdown='sudo /sbin/shutdown'
#21: Control web servers
# also pass it via sudo so whoever is admin can reload it without calling you # alias nginxreload='sudo /usr/local/nginx/sbin/nginx -s reload' alias nginxtest='sudo /usr/local/nginx/sbin/nginx -t' alias lightyload='sudo /etc/init.d/lighttpd reload' alias lightytest='sudo /usr/sbin/lighttpd -f /etc/lighttpd/lighttpd.conf -t' alias httpdreload='sudo /usr/sbin/apachectl -k graceful' alias httpdtest='sudo /usr/sbin/apachectl -t && /usr/sbin/apachectl -t -D DUMP_VHOSTS'
#22: Alias into our backup stuff
# if cron fails or if you want backup on demand just run these commands # # again pass it via sudo so whoever is in admin group can start the job # # Backup scripts # alias backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type local --taget /raid1/backups' alias nasbackup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01' alias s3backup='sudo /home/scripts/admin/scripts/backup/wrapper.backup.sh --type nas --target nas01 --auth /home/scripts/admin/.authdata/amazon.keys' alias rsnapshothourly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' alias rsnapshotdaily='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' alias rsnapshotweekly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' alias rsnapshotmonthly='sudo /home/scripts/admin/scripts/backup/wrapper.rsnapshot.sh --type remote --target nas03 --auth /home/scripts/admin/.authdata/ssh.keys --config /home/scripts/admin/scripts/backup/config/adsl.conf' alias amazonbackup=s3backup
#23: Desktop specific - play avi/mp3 files on demand
## play video files in a current directory ## # cd ~/Download/movie-name # playavi or vlc alias playavi='mplayer *.avi' alias vlc='vlc *.avi' # play all music files from the current directory # alias playwave='for i in *.wav; do mplayer "$i"; done' alias playogg='for i in *.ogg; do mplayer "$i"; done' alias playmp3='for i in *.mp3; do mplayer "$i"; done' # play files from nas devices # alias nplaywave='for i in /nas/multimedia/wave/*.wav; do mplayer "$i"; done' alias nplayogg='for i in /nas/multimedia/ogg/*.ogg; do mplayer "$i"; done' alias nplaymp3='for i in /nas/multimedia/mp3/*.mp3; do mplayer "$i"; done' # shuffle mp3/ogg etc by default # alias music='mplayer --shuffle *'
#24: Set default interfaces for sys admin related commands
vnstat is console-based network traffic monitor. dnstop is console tool to analyze DNS traffic. tcptrack and iftop commands displays information about TCP/UDP connections it sees on a network interface and display bandwidth usage on an interface by host respectively.
## All of our servers eth1 is connected to the Internets via vlan / router etc ## alias dnstop='dnstop -l 5 eth1' alias vnstat='vnstat -i eth1' alias iftop='iftop -i eth1' alias tcpdump='tcpdump -i eth1' alias ethtool='ethtool eth1' # work on wlan0 by default # # Only useful for laptop as all servers are without wireless interface alias iwconfig='iwconfig wlan0'
#25: Get system memory, cpu usage, and gpu memory info quickly
## pass options to free ## alias meminfo='free -m -l -t' ## get top process eating memory alias psmem='ps auxf | sort -nr -k 4' alias psmem10='ps auxf | sort -nr -k 4 | head -10' ## get top process eating cpu ## alias pscpu='ps auxf | sort -nr -k 3' alias pscpu10='ps auxf | sort -nr -k 3 | head -10' ## Get server cpu info ## alias cpuinfo='lscpu' ## older system use /proc/cpuinfo ## ##alias cpuinfo='less /proc/cpuinfo' ## ## get GPU ram on desktop / laptop## alias gpumeminfo='grep -i --color memory /var/log/Xorg.0.log'
#26: Control Home Router
The curl command can be used to reboot Linksys routers.
# Reboot my home Linksys WAG160N / WAG54 / WAG320 / WAG120N Router / Gateway from *nix. alias rebootlinksys="curl -u 'admin:my-super-password' 'http://192.168.1.2/setup.cgi?todo=reboot'" # Reboot tomato based Asus NT16 wireless bridge alias reboottomato="ssh admin@192.168.1.1 /sbin/reboot"
#27 Resume wget by default
The GNU Wget is a free utility for non-interactive download of files from the Web. It supports HTTP, HTTPS, and FTP protocols, and it can resume downloads too:
## this one saved by butt so many times ## alias wget='wget -c'
#28 Use different browser for testing website
## this one saved by butt so many times ## alias ff4='/opt/firefox4/firefox' alias ff13='/opt/firefox13/firefox' alias chrome='/opt/google/chrome/chrome' alias opera='/opt/opera/opera' #default ff alias ff=ff13 #my default browser alias browser=chrome
#29: A note about ssh alias
Do not create ssh alias, instead use ~/.ssh/config OpenSSH SSH client configuration files. It offers more option. An example:
Host server10 Hostname 1.2.3.4 IdentityFile ~/backups/.ssh/id_dsa user foobar Port 30000 ForwardX11Trusted yes TCPKeepAlive yes
You can now connect to peer1 using the following syntax:
$ ssh server10
#30: It's your turn to share...
## set some other defaults ## alias df='df -H' alias du='du -ch' # top is atop, just like vi is vim alias top='atop' ## nfsrestart - must be root ## ## refresh nfs mount / cache etc for Apache ## alias nfsrestart='sync && sleep 2 && /etc/init.d/httpd stop && umount netapp2:/exports/http && sleep 2 && mount -o rw,sync,rsize=32768,wsize=32768,intr,hard,proto=tcp,fsc natapp2:/exports /http/var/www/html && /etc/init.d/httpd start' ## Memcached server status ## alias mcdstats='/usr/bin/memcached-tool 10.10.27.11:11211 stats' alias mcdshow='/usr/bin/memcached-tool 10.10.27.11:11211 display' ## quickly flush out memcached server ## alias flushmcd='echo "flush_all" | nc 10.10.27.11 11211' ## Remove assets quickly from Akamai / Amazon cdn ## alias cdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai' alias amzcdndel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon' ## supply list of urls via file or stdin alias cdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile akamai --stdin' alias amzcdnmdel='/home/scripts/admin/cdn/purge_cdn_cache --profile amazon --stdin'
Conclusion
This post summaries several types of uses for *nix bash aliases:
- Setting default options for a command (e.g. set eth0 as default option - alias ethtool='ethtool eth0' ).
- Correcting typos (cd.. will act as cd .. via alias cd..='cd ..').
- Reducing the amount of typing.
- Setting the default path of a command that exists in several versions on a system (e.g. GNU/grep is located at /usr/local/bin/grep and Unix grep is located at /bin/grep. To use GNU grep use alias grep='/usr/local/bin/grep' ).
- Adding the safety nets to Unix by making commands interactive by setting default options. (e.g. rm, mv, and other commands).
- Compatibility by creating commands for older operating systems such as MS-DOS or other Unix like operating systems (e.g. alias del=rm ).
I've shared my aliases that I used over the years to reduce the need for repetitive command line typing. If you know and use any other bash/ksh/csh aliases that can reduce typing, share below in the comments.
See also
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop





![Sending Email With Attachments From Unix / Linux Command [ Shell Prompt ]](http://s13.cyberciti.org/images/shared/rp/3/18.jpg)








{ 73 comments… read them below or add one }
Nice list; found a couple new things I never thought of. To return the favor; my addon..
A nice shell is key in bash imo; I color code my next line based on previous commands return code..
bash_prompt_command() { RTN=$? prevCmd=$(prevCmd $RTN) } PROMPT_COMMAND=bash_prompt_command prevCmd() { if [ $1 == 0 ] ; then echo $GREEN else echo $RED fi } if [ $(tput colors) -gt 0 ] ; then RED=$(tput setaf 1) GREEN=$(tput setaf 2) RST=$(tput op) fi export PS1="\[\e[36m\]\u.\h.\W\[\e[0m\]\[\$prevCmd\]>\[$RST\]"And I liked your .{1,2,3,4} mapping; how I integrated it…
dotSlash="" for i in 1 2 3 4 do dotSlash=${dotSlash}'../'; baseName=".${i}" alias $baseName="cd ${dotSlash}" doneAnd two random quick short ones..
The following is my version of the “up function” I came up with this morning:
# Functions up () { COUNTER=$1 while [[ $COUNTER -gt 0 ]] do UP="${UP}../" COUNTER=$(( $COUNTER -1 )) done echo "cd $UP" cd $UP UP='' }Show text file without comment (#) lines (Nice alias for /etc files which have tons of comments like /etc/squid.conf)
Usage e.g.:
@linuxnetzer, nocommand is nice to dump squid, httpd and many others config files.
@mchris, I liked cp alias that can show progress.
Appreciate your comments.
Ctrl+L is also a nice quick way to clear the terminal.
Hi!
This isn’t an alias, but for clear screen is very handy the CTRL+L xDD
Have a nice day ;-)
TooManySecrets
One that I find useful is:
apt-get with limit
To open last edited file
Try !vim
Nice list. Never knew about some of these aliases and commands.
good list, an alias I use commonly
ll “ls -l”
Nice tricks.
But be careful with some aliases (typically the #7 mount), since you won’t be able to use them directly when you pass arguments .
[root@myhost ~]# alias mount=’mount |column -t’
[root@myhost ~]# mount myserver:/share /mnt
column: myserver:/share: No such file or directory
It’s better to use scripts whith these kinds of commands
You are very right in your appreciation. An alias is a “dumb” substitution in that it doesn’t interpret arguments.
Do it this way:
(note the double “t”) and than you can use the original mount command to do its job.
In reply to comment of “Reopen last edited file in vim”, alternative recommendation that will be more portable to other uses…
vim
Can also use history here; if you edited /etc/host 4 files ago; you can just type host and you’re good to go. Works with all commands; I use it constantly.
(Also, is also incredibly useful. Also accepts direct place in previous commands)
Don’t forget… sl=”ls”. Though Steam Locomotive is funny for a while, this is always the easier solution.
@oll
And you are done with it. No need to write scripts.
My bashrc has been with me for over a decade. I love to tinker and modify it a bunch, so I’ve added an alias I borrowed/stole/ganked from someone ages ago:
Hi esritter … I’m relatively new to Linux, so I don’t understand your alias. Can you please explain?
Like it ! Thanks.
Nice commands!
In case you would like to be shown the contents of a directory immediately after moving to it by cd DIRECTORY you could define the following function in .bashrc:
cdl() { cd"$@"; ls -al; } You can modify the options of ls to meet your needs of course. Next time you switch directories on the command line with 'cdl DIRECTORY' it will automatically execute the command 'ls -al', displaying all subdirectories and files (hidden ones as well when setting the option -a). I hope this will be useful for someone. In case you like the alias, do not forget to changeHere are 4 commands i use for checking out disk usages.
usage is better written as
alias usage=’du -ch 2> /dev/null |tail -1′
Thank you all for your aliases.
I found this one long time ago and it proved to be useful.
# shoot the fat ducks in your current dir and sub dirs
alias ducks=’du -ck | sort -nr | head’
I always create a ps2 command that I can easily pass a string to and look for it in the process table. I even have it remove the grep of the current line.
alias ps2=’ps -ef | grep -v $$ | grep -i ‘
Nice post. Thanks.
@oll & Vivek: I’m sure you know this, but to leave trace of it in this page I’ll mention that, at least in Bash, you have functions as a compromise between aliases and scripts. In fact, I solved a similar situation to what is described in #7 with a function:
I keep some files under version control, hard-linking to those files into a given folder, so I want find to ignore that folder, and I don’t want to re-think and re-check how to use prune option every time:
# This will move you up by one dir when pushing AltGr .
# It will move you back when pushing AltGr Shift .
bind ‘”…”:”pushd ..\n”‘ # AltGr .
bind ‘”÷”:”popd\n”‘ # AltGr Shift .
Hendrik
One more thing to keep in mind is the difference in syntax between shells. I used to work on a system that used HP-UX and Sun Solaris, and the alias commands were different. One system used
alias ll=’ls -l’
and the other one (I can’t remember which was which, sorry) was
alias ll ‘ls -l’
Something to be aware of!
Thanks for this article and the site, V! Keep ‘em coming!
I would use a function for df:
df () {
if [[ "$1" = "-gt" ]]; then
x=”-h”
shift
x=$x” $@”
fi
/bin/df $x -P |column -t
}
That way you can put “df -k /tmp” (etc).
… I work with AIX a lot, so often end up typing “df -gt”, so that’s why the if statement is there.
I also changed “mount” to “mnt” for the column’s:
alias mnt=”mount |column -t”
Any alias of rm is a very stupid idea (except maybe alias rm=echo fool).
A co-worker had such an alias. Imagine the disaster when, visiting a customer site, he did “rm *” in the customer’s work directory and all he got was the prompt for the next command after rm had done what it was told to do.
It you want a safety net, do “alias del=’rm -I –preserve_root’”,
Great post I’ve been looking for something like this I always tend to go about things the long way round. With these alias and some shell scripting I’m really starting to cut down on wasted time!
Thanks again!
I use this one when I need to find the files that has been added/modified most recently:
alias lt=’ls -alrt’
# file tree alias tree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'" #turn screen off alias screenoff="xset dpms force off" # list folders by size in current directory alias usage="du -h --max-depth=1 | sort -rh" # e.g., up -> go up 1 directory # up 4 -> go up 4 directories up() { dir="" if [[ $1 =~ ^[0-9]+$ ]]; then x=0 while [ $x -lt ${1:-1} ]; do dir=${dir}../ x=$(($x+1)) done else dir=.. fi cd "$dir"; }might be a repost, oops
# ganked these from people #not an alias, but I thought this simpler than the cd control #If you pass no arguments, it just goes up one directory. #If you pass a numeric argument it will go up that number of directories. #If you pass a string argument, it will look for a parent directory with that name and go up to it. up() { dir="" if [ -z "$1" ]; then dir=.. elif [[ $1 =~ ^[0-9]+$ ]]; then x=0 while [ $x -lt ${1:-1} ]; do dir=${dir}../ x=$(($x+1)) done else dir=${PWD%/$1/*}/$1 fi cd "$dir"; #turn screen off alias screenoff="xset dpms force off" #quick file tree alias filetree="find . -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"a little mistake, not really important if you don’t copy/paste like a dumbass :-)
alias iptlistfw=’sudo /sbin/iptables -L FORWORD -n -v –line-numbers’
it is “FORWARD”, not “FORWORD”
@em
Thanks for the heads up.
In “Task: Disable an alias temporarily (bash syntax)”
## path/to/full/command
/usr/bin/clear
## call alias with a backslash ##
\c ===> This should be \clear right?
No.
Previously he set the alias:
alias c=’clear’
so \c is correct.
True, but unless you have a program called ‘c’, this doesn’t do anything useful. The example doesn’t really illustrate the point. This one is better:
I used it this way.
I added myself to visudo file with nopasswd privileges.
so that I don’t have to type password when I do “sudo su -”.
Then created alias root=’sudo su -’
This enables me to log in to root with just “root”.
by the ways the article is very helpful for everyone who works on linux servers or desktops on everyday basis.
Regards,
Mac Maha.
I move across various *nix type OSes. I have found that it’s easiest to keep my login stuff (aliases & environment variables) in separate files as in .aliases-{OS}. E.g.:
All I have to do then in .bashrc, or .profile, whatever is do this:
OS=$( uname | tr '[:upper:]' ':[lower:]') . $HOME/.aliases-${OS} . $HOME/.environment_variables-${OS}and/or
for SCRIPT in $( ls -1 $HOME/scripts/login/*-${OS} ) do . ${SCRIPT} doneAnd Larry wins the thread going away!
i have 2 more that haven’t been posted yet:
helps with copy and pasting to and from a terminal using X and the mouse. (i chose the alias name according to what the internet said the corresponding macos commands are.)
and something I use rather frequently when people chose funny file/directory names (sad enough):
chr() { printf \\$(printf '%03o' $1) } ord() { printf '%d' "'$1" }edit:
the pb* aliases are especially for piping output to the clipboard and vice versa
That was a great list. Here are some of mine:
I use cdbin to cd into a bin folder that is many subdirectories deep:
I can never remember the sync command.
I search the command history a lot:
My samba share lives inside a TrueCrypt volume, so I have to manually restart samba after TC has loaded.
I’m surprised that nobody else suggested these:
I find these aliases are helpful
alias up1="cd .." # edit multiple files split horizontally or vertically alias e="vim -o " alias E="vim -O " # directory-size-date (remove the echo/blank line if you desire) alias dsd="echo;ls -Fla" alias dsdm="ls -FlAh | more" # show directories only alias dsdd="ls -FlA | grep :*/" # show executables only alias dsdx="ls -FlA | grep \*" # show non-executables alias dsdnx="ls -FlA | grep -v \*" # order by date alias dsdt="ls -FlAtr " # dsd plus sum of file sizes alias dsdz="ls -Fla $1 $2 $3 $4 $5 | awk '{ print; x=x+\$5 } END { print \"total bytes = \",x }'" # only file without an extension alias noext='dsd | egrep -v "\.|/"' # send pwd to titlebar in puttytel alias ttb='echo -ne "33]0;`pwd`07"' # send parameter to titlebar if given, else remove certain paths from pwd alias ttbx="titlebar" # titlebar if [ $# -lt 1 ] then ttb=`pwd | sed -e 's+/projects/++' -e 's+/project01/++' -e 's+/project02/++' -e 's+/export/home/++' -e 's+/home/++'` else ttb=$1 fi echo -ne "33]0;`echo $ttb`07" alias machine="echo you are logged in to ... `uname -a | cut -f2 -d' '`" alias info='clear;machine;pwd'A couple you might mind useful.
You should check $EUID, not $UID, because if the effective user ID isn’t 0, you aren’t root, but if the real/saved user UID is 0, you can seteuid(0) to become root.
Reply to Tom (#42):
(1) Using `hg’ for `history –grep’ is probably not a good idea if you’re ever going to work with Mercurial SCM.
(2) Using sudo for `yum search’ is entirely pointless, you don’t need to be root to search the package cache.
alias up1="cd .." # edit multiple files split horizontally or vertically alias e="vim -o " alias E="vim -O " # directory-size-date (remove the echo/blank line if you desire) alias dsd="echo;ls -Fla" alias dsdm="ls -FlAh | more" # show directories only alias dsdd="ls -FlA | grep :*/" # show executables only alias dsdx="ls -FlA | grep \*" # show non-executables alias dsdnx="ls -FlA | grep -v \*" # order by date alias dsdt="ls -FlAtr " # dsd plus sum of file sizes alias dsdz="ls -Fla $1 $2 $3 $4 $5 | awk '{ print; x=x+\$5 } END { print \"total bytes = \",x }'" # only file without an extension alias noext='dsd | egrep -v "\.|/"' # send pwd to titlebar in puttytel alias ttb='echo -ne "33]0;`pwd`07"' # send parameter to titlebar if given, else remove certain paths from pwd alias ttbx="titlebar" # titlebar if [ $# -lt 1 ] then ttb=`pwd | sed -e 's+/projects/++' -e 's+/project01/++' -e 's+/project02/++' -e 's+/export/home/++' -e 's+/home/++'` else ttb=$1 fi echo -ne "33]0;`echo $ttb`07" alias machine="echo you are logged in to ... `uname -a | cut -f2 -d' '`" alias info='clear;machine;pwd'I’m surprised no one has mentioned:
alias ls=’ls -F’
It will show * after executables, / after directories and @ after links.
John (Ko),
The variations of dsd that I gave all include -F
Give them a try.
And for you vi(m) lovers out there, in my .bashrc:
set -o vi
esc j,k for searching history using vi semantics. edit line using w, dw, b, F or whatever other as if in vi. Occasionally need to watch that if in command mode, need to press i first so you can actually go back to inserting as opposed to not seeing anything as you attempt to type.
set -o emacs
to get back out of this mode if you want to restore it what others have used.
Here are some tidbits I’ve setup to help troubleshoot things quickly
This one pings a router quickly
This export puts the current subnet as a variable (assuming class C) for easy pinging or nmaping
This command which I just named ‘p’ will call ping and auto populate your current subnet. You’d call it like this to ping the router p 1
Quickly reload your .bashrc or .bash_profile
Clear xterm buffer cache
Contrary to the clear command that only cleans the visible terminal area. AFAIK It’s not an universal solution but it worths a try.
Edited by Admin as requested by OP.
alias clear=’printf “33c”‘
I have been using this concept for many years and still trying to perfect the methodology. My goals include minimal keystrokes and ease of use. I use double quotes in my alias defn even though single quote delimiters are the normal convention. I use ‘aa’ for “add alias.” It is always the first alias I create. Each job and each environ begin with ‘aa’ alias creation. My aliases have evolved into productized command line interfaces and have been adopted by many others over the years. http://www.iboa.us/iboaview.html
Nowadays, git is so popular, we can not miss it
These are my git aliases
alias g=”git”
alias gr=”git rm -rf”
alias gs=”git status”
alias ga=”g add”
alias gc=”git commit -m”
alias gp=”git push origin master”
alias gl=”git pull origin master”
alias sd=”echo michoser | sudo -S”
alias ai=”sd apt-get –yes install”
alias as=”apt-cache search”
alias ar=”sd apt-get –yes remove”
alias .p=”pushd .”
alias p.=”popd”
Regarding the cd aliases (#2), you can use the autocd bash option (run ‘shopt -s autocd’) to change directories without using cd. Then, you can just type ‘..’ to go up one directory, or ‘../..’ to go up 2 directories, or type the (relative) path of any directory to go to it. Another trick is to set the CDPATH environment variable. This will let you easily change to directories in a commonly used sub-directories such as your home directory. For example, if you set the CDPATH to ‘.:$HOME’ (run ‘export CDPATH=.:$HOME’), then run ‘cd Documents’ you will change directories to the Documents/ directory in your home directory, no matter what directory you are currently in (unless your current directory also has a documents/ directory in it).
I don’t use aliases. As the bash man page says:
“For almost every purpose, aliases are superseded by shell functions.”
At the top of my .bashrc I have ‘unalias -a’ to get rid of any misguided aliases installed by /etc/profile.
The aliases that I use the most (also a lot of shell functions):
alias j=’jobs -l’
alias h=’history’
alias la=’ls -aF’
alias lsrt=’ls -lrtF’
alias lla=’ls -alF’
alias ll=’ls -lF’
alias ls=’ls -F’
alias pu=pushd
alias pd=popd
alias r=’fc -e -’ # typing ‘r’ ‘r’epeats the last command
Useful alias. Thanks mates.
I find the following useful too
alias tf='tail -f ' # grep in *.cpp files alias findcg='find . -iname "*.cpp" | xargs grep -ni --color=always ' # grep in *.cpp files alias findhg='find . -iname "*.h" | xargs grep -ni --color=always ' #finds that help me cleanup when hit the limits alias bigfiles="find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk '{ if ( \$1 > 5000) print \$0 }'" alias verybigfiles="find . -type f 2>/dev/null | xargs du -a 2>/dev/null | awk '{ if ( \$1 > 500000) print \$0 }'" #show only my procs alias psme='ps -ef | grep $USER --color=always 'Very nice alias list.
Here’s another very handy alias:
ex: looking for all samb processes:
Here is the most important alias:
alias exiy=’exit’
I did learn some new things. Thanks for that.
Regarding:
# Do not wait interval 1 second, go fast #
alias fastping=’ping -c 100 -s.2′
From reading the man page i gather the ‘-s’ should be ‘-i’ instead.
ping(8):
-s packetsize
Specifies the number of data bytes to be sent.
-i interval
Wait interval seconds between sending each packet. The
default is to wait for one second between each packet
normally, or not to wait in flood mode. Only super-user
may set interval to values less 0.2 seconds.
Back Up [function, not alias] – Copy a file to the current directory with today’s date automatically appended to the end.
bu() { cp $@ $@.backup-`date +%y%m%d`; }Add to .bashrc or .profile and type: “bu filename.txt”
-
I made this a long time ago and use it daily. If you really want to stay on top of your backed up files, you can keep a log by adding something like:
bu() { cp $@ $@.backup-`date +%y%m%d`; echo "`date +%Y-%m-%d` backed up $PWD/$@" >> ~/.backups.log; }I hope someone finds this helpful!
i did!
thanks a lot
I am learning to love simple functions in .bashrc
mcd () {
mkdir -p $1;
cd $1
}
But the great aliases are in the cmd prompt under windoze:
run doskey /macrofile=\doskey.mac
then set up a doskey,mac in root directory with the CORRECT commands
ls=dir $* /o/w
cat=type $*
rm=del $*
lsl=dir $* /o/p
quit=exit
yes, I have to work in the sludgepit, but I can fix the command set
Since I work in a number of different distributions, I concatenated 17 and 18:
case $(lsb_release -i | awk ‘{ print $3 }’) in
Ubuntu|Debian)
alias apt-get=”sudo apt-get”
alias updatey=”sudo apt-get –yes”
alias update=’sudo apt-get update && sudo apt-get upgrade’
;;
CentOS|RedHatEnterpriseServer)
alias update=’yum update’
alias updatey=’yum -y update’
;;
esac
Of course you could add Fedora, Scientific Linux, etc, to the second one, but I don’t have either of those handy to get the output of lsb_release.
alias gtl=’git log’
alias gts=’git status’