Lecture Seven

Linking; Process Management; Shell Startup; Command History; alias

Linking

  • ln (link) command gives a file an additional name, or pointer, from the same or a different directory
  • one common use of links is to give a long pathname an easy to remember shortcut
  • hard links
    • ln file1 file2 - gives file1 the additional name file2 (hard link)
    • ls -i file1 - and
    • ls -i file2 - will give same index (or inode) numbers, they are physically the same file
    • a file will not be removed until all of its hard links are removed (using rm)
  • symbolic links (or soft links)
    • ln -s file1 file2 - gives file1 the additional name file2, as an indirect pointer
    • a file can be removed even if it still has symbolic links
    • ln -s path/dir1 dir2 - gives dir1 the additional name dir2 in the current directory
    • directories can only be linked symbolically (except by the administrator)
    • symbolic links are useful where you wish to recreate a file without having to remove and recreate a lot of links

Process Management

  • a process is the execution of a command
  • every process has a process id
  • a parent process forks (or spawns) a child process
  • & at the end of a command line will run the command in the background, and gives the unique process identification (PID) and a job number
    • eg. ls -lR / > test 2> testerror & (recursive listing of all files and directories under the root directory)
    • eg. tail -f test & (endless loop waiting for additional lines)
  • ps - will display process status with PID, for current terminal only
  • ps -U username - will display status for all terminals belonging to specified username
  • ps -f - will display additional info, such as parent PID (PPID) of each process
  • ps f - will display processes showing parent/child relationships
  • there are LOTS of ps options, varies by system
  • top - will display resource usage, continually updated (end with 'q')
  • jobs - will show job number of processes
  • kill pid# (or %job) - will abort process with specific PID or job number
  • kill -9 pid# - will abort process that has been written to ignore other signals
  • kill -stop pid# - will suspend (stop) a background job
  • -z - will suspend a foreground job
  • bg %job - will start running a suspended process in the background, defaults to last suspended job
  • fg %job - will start running a suspended process in the foreground

Shell Startup

bash startup

  • upon login, /etc/profile executes
    • controlled by system administrator
    • common to all shells
  • then ~/.bash_profile executes
    • used to customize environment for each user (eg. set PATH, umask, mesg, aliases, etc.)
    • .bash_login is used if .bash_profile doesn't exist
    • .profile is used if .bash_profile and .bash_login don't exist
  • .bashrc is used for interactive sub-shells
  • .bash_logout is executed when shell is exited

ksh startup

  • upon login, /etc/profile executes, then .profile in home directory
  • .kshrc is used for interactive sub-shells

Command History

  • .bash_history is used to store recently executed command lines
  • allows use of arrow keys to move back and forth within history
  • -r can be used to search history by keyword

alias

  • assigns a new name to an existing utility
  • eg. alias dir=ls
  • eg. alias ls='ls -al'
  • eg. alias clearfile='cat /dev/null >'
  • can be useful, but can also make your scripts cryptic