You might have noticed that I have a very short prompt in Terminal, just the character `>` followed by a space. That's because I have an (invisible) file in my home directory named
.bash_profile
, containing this line:We can change back to the original behavior by changing the name of the file or moving it, and then re-starting Terminal:
We could comment out that line of the file (now that it's visible with no leading `.` in the filename, we can easily open it in TextEdit).
But I like it, so I'll revert to the original situation.
I think there is a way to get TextEdit to show hidden files in the Open dialog, but I forget how at the moment. In any event, it's interesting that having opened and closed the file while it was visible on the Desktop, Open Recent now shows
.bash_profile
as an option.Another way to edit the file is to use
pico
(a command line editor):I'm sure you can figure out how to use
pico
.One more useful thing in
.bash_profile
is modification to the $PATH variable. Let's look at that from the command line:When I call
ls
, for example, these directories are searched in turn until the program is discovered finally. It is in:If I wanted to modify the $PATH variable I could do:
My $PATH is pretty complicated for several reasons: use of MacPorts, some things related to ncbi and X11, etc. It would take too long to explain.
The shell has command history. If you want to repeat a command, just press the up arrow key. To repeat a command further back, keep pushing until you see the one you want. Then press Return. Suppose you have a series of commands (say 3 in a row), and the first of these is 6 commands ago. Press the arrow 6 times, then return. Press the arrow 6 times, then return. Press the arrow 6 times, then return. Because the command history is updated each time, 6 arrow presses gets you back exactly where you need to be for each of the three commands in the sequence.
Alternatively you could do
history
:which lists each command I've entered since the last time I booted my machine (even saves between Terminal sessions). One can select a command from the history by number or by partial name match:
First it prints the command, and then the result. You can combine commands on a single line with `;`
We're getting pretty good with this stuff! We don't really want to list all 500+ commands in the history, just the last two. So we feed the results of
history
to the Unix tool called tail
through a `|`, a Unix "pipe." tail
takes an option for how many lines at the end of the "file" to display.The Unix command
grep
searches lines of text for those matching a pattern. It's particularly useful in combination with `|`.Here, I edited some file with pico but I can't remember which one it was. So the entire output of the
history
is fed through the pipe to grep
, searching for lines containing the pattern. Now I can just do:I won't show you the file.
The last command for this post is
ln
with the option -s
which makes a "soft link" to a file. I can never remember, but you want to put the existing file first (that's the opposite of the way I would design it):Now the listing for foo shows an `l` as the first character in the file mode, and it also shows
-> temp/y.txt
, where it links to.