.bashrc: Difference between revisions

From Thom Group Wiki
Jump to navigation Jump to search
import>Tes36
(Created page with "Upon startup the .bashrc file is executed. It contains command line inputs. Add new inputs to this file if you find yourself wanting to issue the same shell commands over and ...")
 
import>Tes36
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
== Nature of the beast ==
== Nature of the beast ==
The .bashrc file is hidden, and lives in the home (~) directory of the user. To see hidden files in a list, use ls -a.
The .bashrc file is hidden, and lives in the home (~) directory of the user. To see hidden files in a list, use ls -a.
If you have made changes to .bashrc, you can rerun the file while in the home directory rather than restarting the terminal. E.g. ". .bashrc"
If you have made changes to .bashrc, you can rerun the file while in the home directory rather than restarting the terminal.


<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">". .bashrc"</div>


== Path ==
== Path ==
The path statement is where the shell checks for executable files. These files must be in the path, else they will not be found. Your path always includes the directory you are currently browsing, but you can add other directories to be permanently in the path by writing a line of the form:
The path statement is where the shell checks for executable files. These files must be in the path, else they will not be found. Your path always includes the directory you are currently browsing, but you can add other directories to be permanently in the path by writing a line of the form:

"export PATH=~/qcmagic:$PATH"
<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">export PATH=~/qcmagic:$PATH</div>

Python also uses a path statement to execute its files. The syntax is exactly similar:

<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">export PYTHONPATH=~/qcmagic:$PYTHONPATH:</div>


== Alias ==
Sometimes you will find yourself entering the same keypresses over and over again. An alias replaces a certain word, whenever you input it, with another series of key presses. You can use this facility to reduce long, commonly-encountered combinations or addresses to a single word. You can also alias common typos to their correct input, so that even if you misspell 'mkdir' as 'mdkri' or 'mdkir' it still works!

<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">work="~/qchem/MnO4/scratch/manout"</div>

<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">ll="ls -lrt -a"</div>

<div class="center" style="width: auto; margin-left: auto; margin-right: auto;">mdkir="mkdir"</div>


== User Function ==
An alias is not always enough. We can go further and define a word to execute an entire series of commands. Even take inputs or arguments!

A function to remove all files and directories below the current one:
ded () {
printf "\033[0;32mYou Are Here:\033[0m\n"
ls
printf "Are you \033[0;31msure\033[0m you want to do this?\n"
read yon
if [ $yon = yes ]; then
printf "\033[0;31mFire in the hole!\033[0m\n"
rm -rf *
else
printf "\033[0;32mStand Down\033[0m\n"
fi
}

A function to print the directory contents whenever you change directory:
function cd {
builtin cd "$@" && ls
}

A function to perform the grep command and then edit the output:
grepl () {
grep energy $1 | awk '{print $4,$3}' | sort -n | head -1
}

Latest revision as of 09:42, 21 August 2015

Upon startup the .bashrc file is executed. It contains command line inputs. Add new inputs to this file if you find yourself wanting to issue the same shell commands over and over, such as modifying the $PATH. You can also create alias, and short functions.

Nature of the beast

The .bashrc file is hidden, and lives in the home (~) directory of the user. To see hidden files in a list, use ls -a. If you have made changes to .bashrc, you can rerun the file while in the home directory rather than restarting the terminal.

". .bashrc"

Path

The path statement is where the shell checks for executable files. These files must be in the path, else they will not be found. Your path always includes the directory you are currently browsing, but you can add other directories to be permanently in the path by writing a line of the form:

export PATH=~/qcmagic:$PATH

Python also uses a path statement to execute its files. The syntax is exactly similar:

export PYTHONPATH=~/qcmagic:$PYTHONPATH:


Alias

Sometimes you will find yourself entering the same keypresses over and over again. An alias replaces a certain word, whenever you input it, with another series of key presses. You can use this facility to reduce long, commonly-encountered combinations or addresses to a single word. You can also alias common typos to their correct input, so that even if you misspell 'mkdir' as 'mdkri' or 'mdkir' it still works!

work="~/qchem/MnO4/scratch/manout"
ll="ls -lrt -a"
mdkir="mkdir"


User Function

An alias is not always enough. We can go further and define a word to execute an entire series of commands. Even take inputs or arguments!

A function to remove all files and directories below the current one: ded () {

   printf "\033[0;32mYou Are Here:\033[0m\n"
   ls
   printf "Are you \033[0;31msure\033[0m you want to do this?\n"
   read yon
   if [ $yon = yes ]; then
       printf "\033[0;31mFire in the hole!\033[0m\n"
       rm -rf *
   else
       printf "\033[0;32mStand Down\033[0m\n"
   fi

}

A function to print the directory contents whenever you change directory: function cd {

   builtin cd "$@" && ls

}

A function to perform the grep command and then edit the output: grepl () {

   grep energy $1 | awk '{print $4,$3}' | sort -n | head -1

}