Register
It is currently Thu Oct 23, 2014 3:14 pm

Jbsnakes ALIAS tutorial - a quick overview.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue May 17, 2005 10:43 am   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 669
Location: Des Moines, Iowa
I kind of borrowed this from usalug's site, jbsnake posted it there and it's a pretty good overview for someone that may not know what an alias IS. :)

--------------------

an alias is sort of like a one-line script. it can be used to group together like commands or shorten common ones. you can add some into your ~/.bashrc file or add them into the profile file or even the /etc/skel/.bashrc file (for new users) or you can even just use one during a shell session.
i suggest doing it in a shell session first, just to test it. then commiting it to a static location for constant adding.
i have tons of aliases in my bashrc file just because i want to use them all the time (not to mention i'm lazy). since i use sudo, i get tired of typing "sudo shutdown -h now" everytime i want to shutdown my computer, so i made an alias
Code:
alias shutdown='sudo shutdown'

that one only eliminates the need to type the word sudo
Code:
alias sd='sudo shutdown -h now'

that makes it so i just have to type "sd" to shutdown like i want

ofcourse you can get tricky with them, say you changed to a particular directory all the time (like /home/jbsnake/scripts :))? i like to use
Code:
alias scripts='cd /home/jbsnake/scripts'


Important: DO NOT name an alias the same as a command that doesn't do the same thing(i.e. alias df='do something that df doesn't do')

ofcourse you can pass an alias more than one command, just use a semi-colon ( ; ) as a seperator.
Syntax: alias <nameofalias>='command1;command2;etc.'

suppose instead of just changing to the best directory ever :) i wanted to list the contents once i was there. i would use this alias
Code:
alias scripts='cd /home/jbsnake/scripts; ls'

if you don't like adding symbolic links within your path using neat scripts :)
::cough::
you can reference different files as aliases, like
Code:
alias link2path='/home/jbsnake/scripts/link2path'

as you can tell from the first couple posts i made here, you can use an alias for many monotonous things (mounting removable media). if your like me (hopefully you aren't) i never label my floppy disks, or if i do, the name is not acurate anymore :), so this alias is great when i have to search through every one
Code:
alias floppy='LAST_DIR=`pwd`; mount /dev/fd0; cd /mnt/floppy; ls'

that alias takes my current directory and stores it into a variable called "LAST_DIR", then it mounts the floppy drive, then changes to the floppy drives directory, then lists the contents. if you havn't noticed yet, aliases are very handy things to have around.


Top
 Profile WWW  
 PostPosted: Sat Feb 09, 2013 7:20 am   

Joined: Sat Feb 09, 2013 4:41 am
Posts: 1
my aliases are
alias distup='sudo apt-get update; sudo apt-get upgrade'
alias apinst='sudo apt-get install'
alias ls='ls --color=auto'
alias grep=grep --color=auto'
alias h='history'
alias root='sudo -i'
alias su='sudo -i'
=D>


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP