Technology Support Center

Using the Bash Shell (BAsh) on BGUnix


In January 2008, the University replaced the bgunix system we have been using since 2002. The new system uses the bash shell, very similar to the ksh shell used in the previous bgunix.

The following table describes some common Unix commands and features, showing them for both ksh (old bgunix) and bash (new bgunix). Those that are different on the new system are shown in color.

Command or featureksh (previous bgunix)bash (new bgunix)
Commands executed when logging in



Commands executed with each process.kshrc.bashrc
Display the contents of a file on the screencatcat
Return to the login directorycdcd
Change default directory to directory-namecd directory-namecd directory-name
Clear the terminal screenclearclear
Copy file source to destcp source destcp source dest
Interrupt the execution of the current program[Control]-c[Control]-c
Log off the systemexit or [Control]-dexit or [Control]-d
List files waiting to be printedlpqlpq
Send a file to the printercslpr filenamecslpr filename
Lists the files in the current directorylsls
Lists the files in the current directory, with more -lls -l
Create a subdirectory called dir-namemkdir dir-namemkdir dir-name
Display information about a unix commandman commandman command
View a file one page at a timemore filenamemore filename
Rename a filemv old-name new-namemv old-name new-name
Change your passwordpasswdpasswd
Save a session in a photo filephoto log-file-namephoto log-file-name
Create or edit a filevi filename or
pico filename
vi filename or
pico filename
Display the current default directorypwdpwd
Delete (remove) a filerm filenamerm filename
Delete (remove) an empty directoryrmdir dirnamermdir dirname
Redirect standard output to a filecommand > filecommand > file
Redirect standard output and errors to a filecommand > file 2>&1command > file 2>&1
Create an aliasalias m='more'alias m='more'
Remove an aliasunalias munalias m
List command historyhistoryhistory
Reexecute the previous commandr!! (or press up arrow key)
Reexecute the previous command changing ab to xyr ab=xy(Press up arrow and edit command)
Reexecute the fifth command in the history listr 5!5
Reexecute the last command that started with vir vi!vi
Define a function

function fun {

function fun {
export -f fun

Execute a functionfunfun
Delete a functionunset -f fununset -f fun
Represents home directory of current user~~
Represents home directory of user jsmith~jsmith~jsmith
Represents current working directory. (period) or ~+. (period) or ~+
Represents previous working directory~-~-
Compile a C++ programg++ prog.cppg++ prog.cpp
Compile a C++ program for use with debuggerg++ -g prog.cppg++ -g prog.cpp
Complete a partial filenamePress [Esc] then \Press [Tab]

For those who write shell scripts, there are several differences between ksh and bash. You will need more information to be able to write shell scripts with bash.

Customizing your bgunix environment

You can customize your bgunix working environment by adding lines to the .bash_profile file found in your home directory. This is an invisible file, so you won't see it with the ls command unless you say "ls -a". However, you must be very careful when making changes to this file since errors in this file could prevent you from logging onto the system. Here are some sample lines you could add to this file:

export PS1="\w\$ "
This command will display the current directory as your command prompt.

function ls {
   command ls -F $@
export -f ls

These four lines change the ls command so that the -F flag is always added. The -F flag adds / to the end of directory names and * to the end of executable filenames.

If you make changes to .bash-profile, be sure that you don't delete any lines that are already there.