FREEBSD SHELL CONFIGURATION
ASSUMPTIONS:
You have already installed FreeBSD. If not, then
click here:
How to Install FreeBSD
NOTE WELL:
We will be making an number of changes to the FreeBSD
startup file named '.cshrc' which is located on the
FreeBSD hard drive in the user's home directory.
For the 'root' user, this would be:
/root/.cshrc
For your convenience, we have included the .cshrc
start up file
linked
here.
BOOT UP AND LOGIN
- If the computer isn't running turn it on and let it boot up.
- When it shows:
Login:
- Enter:
root
BEGIN CONFIGURATION
- Since we will be editing various configuration files,
we will need to use an editor program. First of all,
do not use 'vi'! 'vi' is a very difficult program
to learn and is very counter-intuitive.
Because of this, the first thing we will do is to install
'Pico':
- At the command prompt '#', enter:
cd /usr/ports/editors/pico/
- Enter:
make install
The process to install Pico will begin. It
will most likely try to download the source
code it needs from an
FTP
server. The file is about 4 MB, and you
should see a progress line indicating about how
long it will take to download.
After the Pico source code has been downloaded,
the 'executable' will be 'built'. You may
see some other programs, like a spelling checker
also being built.
- Once the 'make' and 'install' has finished,
you see the command prompt '#'. Now enter:
pkg_info | more
(The pipe character '|' is probably located on your
keyboard as the shifted version of the '\' key).
(The 'more' command after the pipe character tells
the computer to only show a page of data at a time.
In order to see other pages, use the 'Pg Dn', 'Pg Up',
'Enter' keys, space bar, or arrow keys.)
This command, 'pkg_info' will give information about
which packages are installed on your computer.
- Reboot by entering:
shutdown -r now
- Once the computer reboots and you have
again logged in, enter:
pico
- Pico should come up. To exit
Pico, enter:
Ctrl-X
(Hold the 'Ctrl' key down, and simultaneously
press the 'X' key.)
- Now that we have Pico loaded let's edit
some configuration files to our taste.
The file named '.cshrc' is a start-up file
like 'autoexec.bat' in DOS. The dot '.' at
the beginning of the file name tells the operating
system (OS) that the file is ordinarily hidden.
The 'csh' stands for 'C-shell'. 'C' is the
programming language that it is written in. 'Shell'
refers to the outer layer of the operating system that
a person usually interacts with. The 'kernel' of an
OS, just like a kernel of a nut, is the
inner, meaty part of the operating system. The
final part of this file name, 'rc' stands for 'runtime
commands'. So, '.cshrc' contains the startup
runtime commands for the C-shell command line.
The .cshrc file for each user is kept in their home
directory. So, for the 'root' user, this file
is kept in '/root/'.
- Enter the following:
cd /root/
- To confirm that you actually are in the
/root/ directory, enter:
pwd
This command will give you the Present Working Directory
that you are located in.
- To confirm that the '.cshrc' file exists, enter:
ls -lt
You should see .cshrc listed.
- Before we edit this file, let's make a duplicate,
backup copy, for safety's sake. Enter:
cp -p .cshrc .cshrc.1.bak
(That's the number 'one' not the letter 'ell')
This command tells the system to copy (cp), [p]reserving
file attributes, the file named '.cshrc' to a new file,
'.cshrc.bak1'.
- To confirm that we have made a backup copy, enter:
ls -lt
You should see both files, and they should have the
same size and date.
- Now let's edit the .cshrc file by entering:
pico .cshrc
You now see the contents of this file before you.
- The first change that we want to make is for
ensuring that we don't overwrite files inadvertently.
Note that when ever you see a '#' (number sign, hash mark)
at the beginning of a line, it is a comment line.
It's there for our benefit--the computer just ignores
it.
Just before the line that says:
alias h history 25
Let's add 3 aliases by inserting the following lines:
# Change the 'rm' (remove) command to interactive mode for safety:
alias rm 'rm -i'
# Copy Interactively with a prompt before overwriting
alias cp 'cp -i'
# Move or Rename Interactively with a prompt before overwriting
alias mv 'mv -i'
The 'rm' command is extremely powerful. It will
ReMove files and directories very quickly and efficiently.
By forcing this command to work in the 'Interactive' mode,
(-i), you will have to confirm any deletions before rm
will proceed. Similarly, by adding '-i' to 'cp' and
'mv' they will be forced into interactive mode as well.
Note that if you press the TAB key between 'rm' and 'rm -i',
you will align up the columns of the aliases properly.
- Now let's add 8 shortcut aliases to the list.
Just below the lines we just typed in, let's add:
# LiSt files with Largest last:
alias lsl
'ls -ablprtFT | sort -n +4'
# LiSt files a page at a time with Largest shown first:
alias lslm
'ls -ablprtFT | sort -n +4 -r | more'
# LiSt files with Smallest shown last:
alias lss
'ls -ablprtFT | sort -n +4 -r'
# LiSt files a page at a time with the Smallest shown first:
alias lssm
'ls -ablprtFT | sort -n +4 | more'
# LiSt files with the newly modified (Time) shown last:
alias lst
'ls -ablprtFT'
# LiSt files a page at a time with the newly modified (Time) shown first:
alias lstm
'ls -ablptFT | more'
# LiSt files sorted by name:
alias lsn
'ls -ablptFT | sort +9'
# LiSt files a page at a time sorted by name:
alias lsnm
'ls -ablptFT | sort +9 | more'
- Next let's move the following 2 lines:
alias h history 25
alias j jobs -l
Move them to just before this line:
# a righteous umask
- While we are here, let's comment them and tidy
them up a bit. Change them to:
# Show the last 25 commands entered:
alias h 'history 25'
# Show the status of tasks that you typed in on the command line:
alias j 'jobs -l'
- Now let's backtrack by going back a bit to
these 3 lines:
alias la ls -a
alias lf ls -FA
alias ll ls -lA
Let's add comments and tidy them up so that they look
like this:
# LiSt (a)ll files, even those that are hidden:
alias la 'ls -a'
# LiSt (A)ll files except for '.' & '..'; show (F)iletype symbol.
alias lf 'ls -FA'
# LiSt (A)ll files except for '.' & '..'; show in (l)ong format (wide).
alias ll 'ls -lA'
- Frequently we will need to use CDROM disks and
floppy disks, so let's set up some convenient aliases
for them.
- Let's start with the floppy disk. We need
to set up a directory before we create an alias so,
let's switch to another 'terminal window'.
Enter:
Alt-F2
(This means hold the Alt key down while simultaneously
pressing the 'F2' key.)
For your information: FreeBSD allows for eight (8)
different terminal windows (labeled ttyv0
through ttyv7).
They are accessed using Alt-F1
through Alt-F8. This
is very convenient for multitasking.
- Login as you usually do.
Enter:
cd /
- Enter:
pwd
This shows us the (p)resent (w)orking (d)irectory. It should
show:
/
- Now enter:
mkdir /floppy
- Now we are going to create a file that will
help us know if the floppy is mounted. Enter the
following:
cd /floppy
- Now enter:
touch Floppy-NOT-mounted-mflop.txt
This creates a file that will show up if the
floppy disk is not mounted. By the way,
a removable drive like a floppy or CDROM needs
to 'mounted' before the operating system will
be able to use it. Also, the removable
drive will need to be unmounted before it
is removed from the computer.
- To confirm that this file was actually created, enter:
ls -lt
- Let's go back to the /root directory and
edit our .cshrc file:
Press:
Alt-F1
- It is assumed here that the floppy disks
that we are working with have an MS-DOS format.
(If not, type 'man mount' to learn more.)
Let's go down below our 'LiSt' aliases and
add the following:
# An alias for mounting a MS-DOS floppy disk:
alias mflop
'mount -t msdos /dev/fd0 /floppy'
# An alias for unmounting a floppy disk:
alias uflop
'umount /floppy'
- Once the changes in this file are implemented,
when we want to use a floppy disk, we
just put it in the floppy drive and enter:
mflop
- Next let's create a similar alias for mounting
a CD-ROM disk:
Let's setup a directory for the CD-ROM. To switch to the
other terminal window, enter:
Alt-F2
- You should be logged in. If not, login as you usually do.
- To change to the top directory, enter:
cd /
- To create a directory called '/cdrom', enter:
mkdir /cdrom
Now we are going to create a file that
will help us know if the CD is mounted.
Enter the following:
cd /cdrom
- To create a file that will show
up if the CD-ROM disk is not mounted, enter:
touch CD-is-NOT-mounted-mcd.txt
- Let's go back to the /root
directory and edit our .cshrc file:
Press:
Alt-F1
- Just below the floppy
aliases, add the following:
# An alias for mounting a CD-ROM disk:
alias mcd
'mount -t cd9660 /dev/acd0c /cdrom'
# An alias for unmounting a CD disk:
alias ucd
'umount /cdrom'
- Once the changes in this file are implementd,
when we want to use a CD-ROM disk,
we just put it in the CD-ROM drive and enter:
mcd
- Let's create some other useful aliases.
Enter these 8 next in our '.cshrc' file:
# Move UP one directory:
alias up 'cd ..'
# Move DowN to subdir:
alias dn 'cd ./\!*'
# Move OVer to different directory at same level:
alias ov 'cd ../\!*'
# Make a directory:
alias md 'mkdir'
# Make a directory, then go to it:
alias mdc
'mkdir \!* && cd \!*'
# Remove a directory:
alias rd 'rmdir'
# Remove a subdirectory and EVERYTHING that it contains, (i)nteractively:
alias treedel 'rm -dirv'
# Remove a subdirectory and EVERYTHING that it contains, WITHOUT PROMPTS:
alias treezap 'rm -dfrv'
- Let's comment these next 2 'history' and 'jobs'
aliases like this:
# Show the last 25 commands entered:
alias h 'history 25'
# Show the status of tasks that you typed in on the command line:
alias j 'jobs -l'
- Let's customize our command prompt to include our
computer's name, our UserName, and the current
directory. Because the Present Working Directory
(pwd) changes frequently, we'll need to make changes
to the command prompt every time this occurs.
Because of this we will need to make changes in 2 different
places.
- First, just after these 2 lines:
# A righteous umask
umask 22
let's add this alias:
# Set up the 'cd' command to trigger a change in the command prompt:
alias cd
'chdir \!* && set prompt="`hostname -s` ${USER} `pwd` # "'
Note that there are three (3) types of quotation
marks being used in this line. The quote mark
just before 'chdir' and on the end are single
quote marks ('). The 'set prompt' command
is bounded on both sides by double quote marks
("). The 'back tick' quote marks
surround `hostname -s` and `pwd`. You should
be able to find the back tick on the same key
as the tilde (~) on your keyboard.
- The second place that we need to make a command
prompt change is a bit below in this same file,
.cshrc. Change the following from:
# An interactive shell -- set some stuff up
set prompt = "`hostname -s`# "
to:
# An interactive shell -- set some stuff up
set prompt = "`hostname -s` ${USER} `pwd` # "
- Next, let's back up a few lines and change
our default editor from 'vi' to 'pico'.
Cursor to the line that shows:
setenv EDITOR vi
Change it to:
setenv EDITOR pico
- We have made quite a few changes, so
lets save them to disk by pressing the following
key combination:
Ctrl-O
(That's the letter 'oh', not the number 'zero')
This will write the changed file 'Out' to disk.
Press the Enter key as required.
- We are done editing the '/root/.cshrc' file. Again,
it should now pretty much look like this file
linked
here.
- Now exit pico by entering:
Ctrl-X
- For safety's sake, let's make a backup of our
hard work by entering:
cp -p .cshrc .cshrc.2.bak
- In order for all the changes that we made to
be activated, we need to reboot. Enter the
following command:
shutdown -r +1
- Once the computer reboots, login and try
out your new commands. You can see a
summary of all of them by entering:
alias | more
- Our next item on our configuration agenda is
to set up a procedure that will update the FreeBSD
ports tree in the middle of the night. To do
this we will need to edit a different file.
Quick! Think of a number between 15 and 45!
Write it down now. _________________ You'll
find out why you need this number shortly.
The update file we are going to edit is
usually located in:
/var/cron/tabs/
and has the exact name as the user. So, since
we are currently logged in as 'root', that is the
name of our file.
- To edit this file, let's first move over to that
directory. Enter:
cd /var/cron/tabs/
- To invoke the special editing program, enter:
crontab -e -u root
Since we have set up our default editor to be pico, we
see a blank file show up.
OK, start typing the following lines. Fill in
the dates and times as appropriate. Where you
see '3:XX', put in your magic number you thought
of a moment ago in place of the 'XX'.
Also put it at the beginning
of the next line where you again see 'XX'.
Where you see 'ZZ', put the CVSup server number that
is nearest you. You ascertained this when
you installed FreeBSD. If you don't recall,
you can
click
here for CVSup servers
On the line
with 'Min' 'Hr' etc.,
press the TAB key to put the proper spaces between
these headings. Use the TAB key on the actual
'cron job' line too. (It's the last one that doesn't have a
'#' at the beginning.)
#^^^^^^^The above comments were generated by 'crontab -e -u root' ^^^^^^^
# Crontab file created 200_ September 27, 23:45
#Min Hr
DOM Mnth
DOW command
# At 3:XX in the morning, everyday, as root, update the ports tree:
XX 3
* *
*
/usr/local/bin/cvsup -h cvsupZZ.FreeBSD.org
/usr/share/examples/cvsup/ports-supfile
- Double check your typing. Make sure the lines
are entered as shown here. The line that starts
with your magic number (XX) is on ONE LINE. It may
look like it wraps around--it doesn't. That's just
the way your Internet browser might be showing it.
There is only ONE LINE that doesn't have a '#' at the
beginning, and that's the actual crontab line that has
XX at the beginning. Some other lines may also wrap
because of your browser.
Here are the same lines in teeny-weeny fonts so you
can get a better idea:
#^^^^^^^The above comments were generated by 'crontab -e -u root' ^^^^^^^
# Crontab file created 200_ September 27, 23:45
#Min Hr
DOM Mnth
DOW command
# At 3:XX in the morning, everyday, as root, update the ports tree:
XX 3
* *
*
/usr/local/bin/cvsup
-h
cvsupZZ.FreeBSD.org
/usr/share/examples/cvsup/ports-supfile
Here is a
third
version in plain text format
- Pico may try to wrap lines on you, but diddle around
with it so that the actual crontab line doesn't wrap and
is on one line.
- To save your work, enter:
Ctrl-O
This will write 'O'ut the file to the disk
- To exit pico, enter:
Ctrl-X
- As soon as you do this, the computer will
monitor your newly created file once every minute
and when it get to be the proper time, will execute
what you have programmed it to do.
Congratulations! Your shell is now configured
with some handy-dandy aliases, and your computer will
update its ports tree every night. Of course,
you need to leave it turned on and connected to the
Internet for this to happen. It won't hurt
to leave it off, but your ports tree won't be updated.
Here are some other FreeBSD related links:
How to Install FreeBSD
Shell Configuration
FreeBSD Device List
Hardware
Burn-In Test Using FreeBSD
FreeBSD
Commands Cheat Sheet
'make
install' fails on FreeBSD
The
FreeBSD 'Handbook' online
Search
for Answers to Questions about FreeBSD
How
to Install NTP (Network Time Protocol) software on FreeBSD
How
to Install Samba file server software on FreeBSD
Mounting
and Using the Floppy Drive in FreeBSD
Mounting
and Using the CD-ROM Drive in FreeBSD
How to Find or Search for a Directory or a file
How to Preserve the Date and Time Stamp When Copying Files
How to Copy Files, and Directories recursively in FreeBSD / unix
How To Fix The 'Read Only File System' Problem When rc.conf is Corrupted on Freebsd
Random Passwords Generator
URL Decoder / Link Maker
AT YOUR OWN RISK: These instructions have no guarantee or
warrantee of fitness for any purpose whatsoever--and none
shall be implied or inferred. If you use these
and incur any kind of damage--it is your responsibility.
FreeBSD Shell Configuration, Linux, Unix, Nix, Hard Disks, CD, CDROM, Floppy, Keyboard, Cheat Sheet for FreeBSD Installation, Configure, Options, Configuration, Howto, How To, Red Hat, FreeBSD
|
|
|