"Dot" files and key shell variables =================================== Your home directory contains a number of configuration files whose names begin with a dot "." You can see these guys if you issue : :: % ls -a Recall that the ``-a`` switch for ``ls`` means show me all files. Files that contain the string "bash" (for Bourne again shell, Bourne being being a prominent UNIX person's name and hardcore linuxers being susceptible to punning) are particularly important. You should see ".bashrc", "bash_profile", ".bash_history" and ".bash_logout". The shell, the outer layer of software that interprets what you type at the keyboard and transmits it to deeper parts of the operating system, you are using now is "bash." This is the typical default shell for linux. Another common shell is the "TC-shell" (tcsh), which is what I first learned back in the day and is nowadays somewhat disparaged. bash is powerful, straightforward to write scripts in and if you are going to learn one shell, it would be my recommendation. When you login, bash executes the commands in /etc/profile. Next it looks for ~/.bash_profile and executes commands contained there. This file then typically executes ~/.bashrc (for bash run control). Finally, when you logout, the commands in .bash_logout are executed. There are 2 important builtin shell variables in .bash_profile that affect your life at the keyboard. The first of these tells the shell where to find commands that you type. Commands are nothing more than executable files and all files live in a directory somewhere on the machine's hard drive(s). If the shell cannot find the command you want, even if the file is on your hard drive, it does not get executed. The variable that contains this list of directories to search for the command is PATH (note the uppercase). To see it for your self, issue the ``echo`` command :: % echo $PATH ``echo`` just says write to the shell window the value of the thing coming behind me. The thing coming behind is the value of the variable PATH. The syntax is that a $ sign is attached to the front of the variable name that you want to see the value of. Note, you want to see the *value* of a variable, not its name. Note what happens here: :: % echo PATH Not exactly the same thing. Another key variable is the variable CDPATH that holds the list of directories that contain, in turn, directories you want to access by using just relative path names. For example, if you ``cd` to a directory directly beneath your working one, you do not want to type anything other than the directory name. linux is smart enough to know you want to descend. However, if you often go to a directory that is not immediately beneath your working directory, the shell has no idea where you want to go. How would it? Hence when you ``cd some_where`` the shell looks in the list of directories in CDPATH to see if any of those guys contain some_where. If so, your command executes. if not, then you have to give the full pathname of "some_where". For some reason, your CDPATH does not seem to be set. This means the shell only looks immediately beneath your working directory. We can fix that in the workshop. You examine it by issuing: :: % echo $CDPATH ,bash_logout contains the useful command ``clear``, which clears the shell window of all prior output. this is useful if you need to produce a white screen to hide something you do not want that nosy neighbor of yours to see. Try it: :: % clear You can define your own commands in linux, and even redefine builtin commands. This is a big topic and related to another large topic, 'shell scripting." We don't have time today to really discuss them. Before we leave, we need to redefine two builtin commands in the interest of self-preservation. The ``rm`` command is powerful. Combined with the wildcard * it is potentially nuclear. You could, in one command, delete ALL of your files. Yikes! More practically, you can inadvertently delete files you do not want to delete. To prevent the former and minimize the possibility of the latter, we will redefine ``rm`` to mean ``rm -i``. To see what this does examine the ``man`` pages for ``rm``. Next create a temporary file, say, "testo.txt", and then attempt to delete using ``rm -i``: :: % touch testo.txt % rm -i testo.txt What happens? See the point? So, how to make this sanity saver permanent? You need to edit your .bash_profile file. At the file's bottom, add :: % alias rm='rm -i' There are zero spaces around the = sign and use single quotes. You are not done yet because the change will not take place until you logout/login (works but is a bit vulgar). You need to re-execute your .bash_profile file. Do this by issuing: :: % . .bash_profile Note the leading dot and the space between it and .bash_profile. To verify things went well, use the ``which`` command which tells you what command will be executed. (Remember that since you can redefine commands it is important to know which one will be launched before you actually launch it and ``which`` does the trick.) Issue: :: % which rm You should see that ``rm`` is aliased to ``rm -i``. While we are at it, we should redefine the ``mv`` command in the same fashion to save us some grief. Edit ".bash_profile' (remember the the leading dot!) by adding just below the alias for ``rm``: :: % alias mv='mv -i' Again, you need to re-execute your ".bash_profile" file before this redefinition takes place. Do so now. Feel safer? Summary ------- ======================= =============== Command Meaning ======================= =============== echo $PATH displays value of variable PATH clear clears window of all previous output alias censor='rm *.txt' defines censor to be command to delete all .txt files which *command* identifies *command* ======================= ===============