Home > HowTos > Use aliases to ease your (linux) life…

Use aliases to ease your (linux) life…

Using aliases on linux can really save you some time and hassle.

If you have to type some more complex commands quite frequently, you should consider building some aliases for them.
I always load a set of basic aliases via an include in my ~/.bashrc :

if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi

On Ubuntu distros ~/.bash_profile will include ~/.bashrc where the real action takes place. Might be different on other distros though.

Now, here are some of the aliases I use day by day and which really save me some time. (Of course I obfuscated users and Ips a bit… )

alias ll='ls -hals --color=auto'

-> coloured dir-listings with all the details

alias l='ls -hls --color=auto'

-> same, but without hidden files

alias upgrade='sudo aptitude update && sudo aptitude dist-upgrade'

-> completely upgrade whole system to latest version; should work on ubuntu and debian based distros

alias ports='netstat -tulpen'

-> lists open/used ports without too much details

alias sp='ps faux|grep -v grep|grep -i'

-> if you provide a string as an argument to the command, it´ll grep for it in the output of ‘ps faux’

E.g.:

[12:36:37][gerrit@neuromancer:~]$ ps faux|grep -v grep|grep -i ssh
gerrit    5879  0.0  0.0   4424   544 ?        Ss   09:51   0:00          _ /usr/bin/ssh-agent /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /usr/bin/startkde
gerrit    5880  0.0  0.0   4424   944 ?        Ss   09:51   0:00          _ /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /usr/bin/startkde
root      5127  0.0  0.0   5268   984 ?        Ss   09:51   0:00 /usr/sbin/sshd

versus

[12:34:28][gerrit@neuromancer:~]$ sp ssh
gerrit    5879  0.0  0.0   4424   544 ?        Ss   09:51   0:00          _ /usr/bin/ssh-agent /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /usr/bin/startkde
gerrit    5880  0.0  0.0   4424   944 ?        Ss   09:51   0:00          _ /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session /usr/bin/startkde
root      5127  0.0  0.0   5268   984 ?        Ss   09:51   0:00 /usr/sbin/sshd

Also nice for quick ssh-logins:

alias server1='ssh user@192.168.0.1'

-> if you´ve also implemented public-key authentication, this is going to be a one command login :-)

alias ovpn='sudo openvpn --config /etc/openvpn/configfile.conf'

-> start openvpn-client with certain config-file

alias mntfs='sshfs user@192.168.0.1:/ /mnt/fs'

-> mount your fileserver´s home-dir to your local filesystem via sshfs

This one is nice, too:

alias bru='ssh -X user@obelix 'bru-server''

It performs a ssh login to my company´s backup-server with activated Xserver redirection and spawns the backup-program´s admin-console on the remote server. The gui output is then redirected to my local Xserver.

I hope you got the hang of it. Possibilities are endless :-)

KategorienHowTos Tags:
  1. 20. September 2007, 08:37 | #1

    Thanks for the nice summary :)

  2. 6. Januar 2008, 18:01 | #2

    instead for alias sp I’d put in ‘ps -ef | grep -v grep | grep -i’ I use Ubuntu, and this alias is cleaner. thank you

  1. Bisher keine Trackbacks

Please copy the string OucBdT to the field below: