last edit: 2012-0723
Notes: If you see brackets "[ ]" in code, that indicates you supply your own variable in place of the brackets. Example: [date] = You type in "2012-0723". Quotes do not have to be included.
One of the things I enjoy about Linux is the fun and power of the scripting with bash and python. However there comes a time when you accumulate so many scripts that you can't remember their names to run them. One solution is to create a keyboard short cut that lists all the scripts in your script directory. So instead of typing:
> clear; ls -l /home/chad/Documents/scriptsThe short cut would be:
> llsAliases are created in two places: /etc/bash.rc or ~/.bash_aliases (~ is a shortcut for your home directory, ex. /home/chad). For this example we will add entries to /etc/bash.rc will allow short cuts to all users including root.
Backup /etc/bash.rc in case you make a mistake
> cp /etc/bash.rc /etc/bash.rc.[date].bak orEdit bash.rc with your favorite text editor
> cp /etc/bash.rc /etc/bash.rc.2012-0723.bak
> nano /etc/bash.rcor if using gnome shell or default Ubuntu
> gksudo gedit /etc/bash.rc
Find section labeled "# Alias definitions." and add your alias commands below this section. My examples are below. The first example lists all files in my script directory.
alias lls='clear; ls -l --almost-all --classify /home/chad/Documents/bin'Next save your file and then update your alias variables so that your terminal shell will we aware of them. You update your bash.rc file using the "source" shell command. The source command is useful to load function or variables stored in another file.
alias ll='ls --almost-all -l --classify' # classify indicates file type
alias la='ls --almost-all' # long, shows hidden files
alias l='ls -C --classify' #Columns, file types
> source /etc/bash.rcNow test your new alias shortcut and you should see all the files listed in your scripts directory.
> llsYou can change formatting of the ls command. See man ls for options.
No comments:
Post a Comment