Basic Linux Training
Basic Linux Training
User Track
Linux is UNIX
Linux is Multi-user
Linux uses a hierarchical file system
Access to the OS through the shell
Offers a text based command interface
You can always use ‘find’, which works for pretty much
anything
The vi editor
— source .bashrc
csh
Note: Some Operating Systems have default cshrc and login files. Each
version puts them in different places. Consult your vendor
documentation.
Startup (in this order): .cshrc (always) and .login (if it's a login shell)
Upon exit: .logout (if it's a login shell)
Other dot files: .history (saves command history)
# chkconfig --list
# echo $PATH
Note that just because something is not in your path doesn’t mean you
can’t run it, if you know where it is. You could run
# /sbin/chkconfig --list
Environment variables are used as a way to represent a value. They are automatically
exported to all subprocesses of the shell they were created in including shell scripts,
applications and subshells. They are commonly used to pass information such as a
directory location or a flag. Example:
MGC_HOME=/apps/mentor/en2002
NUT_SEC_ATTR_OFF=true
If this were defined in the user’s login shell, then all subsequent shells and
applications could refer to these $VARNAME
The proper syntax for creating environment variables depends on which shell is
used. In the bash shell the export command is used to create and export an
environment variable.
export VARNAME=value
Traditionally, all capital letters are used for environment variable names. This is simply
convention not a requirement. They are case sensitive, though. Value must be
quoted if it contains spaces or other special characters. Example:
Use the env command without options to display all environment variables currently
defined.
# env
MACHINE=RED HAT LINUX
...
Once an environment variable is defined, its name can be used in place of its value.
Example:
# echo $MACHINE
RED HAT LINUX
To remove an environment variable, the Bourne shell and its derivatives (including
bash) use the unset command.
unset VARNAME
The c-shell and its derivatives use the unsetenv command.
unsetenv VARNAME
The shell often uses built-in environment variables. Built-in environment variables
are environment variables that have special meaning to the shell. For example, the
USER environment variable contains your username.
# echo $USER
fredf
Others:
Command history
Background and foreground jobs
File completion
Scripting on the fly
Colorization
The shell will save a command history, and allow you to refer to
commands by number to run them again. This can save a lot of
typing. Example:
If I wanted to run that xterm command again, I could either type it all in, or I could do
a !26
This starts xclock in the background, so I can run xclock and then use the shell
window to do something else. Without the ‘&’, I would not be able to use the shell
window until xclock was terminated
If I started xclock in the foreground then changed my mind, I could still put it in the
background by doing a ^z (control z) then the command ‘bg’. Note that I can use
the shell window, and the xclock client will still update the display
If I want to bring the application back into the foreground, I simply enter the command
‘fg %(n)’, where (n) is the job number
# cat sup<esc><esc>
# ps -auxww | more
#! /bin/sh
while read line
do
cat $line
done < /tmp/foofile
exit 0
finger
— Find out information about your current session
Linux supports both ‘flavors’ of ps; SYSV and BSD UNIX. So both
these commands will work, and do pretty much the same thing
# ps -ef
# ps aux
Examples:
# kill -1 1
Send a soft reset to process number 1 (the init process) which causes it to reread
its config file (/etc/inittab)
# kill -9 1171
Send a signal to process 1171 that basically says “die, you gravy sucking pig!”
Unconditional termination of the process.
# ping elvis
returns elvis’s name and IP address if elvis is ‘alive’
# ping -c 4 dino
pings dino 4 times then quits
What command would you use to find out if the file named ‘yabbadabbado’ was
in your file?
Customize the shell color scheme, or turn it off, as you prefer
Create a new file, with all these Flintstones characters in it, in this order: Fred,
Wilma, Barney, Betty, Pebbles, Bam-Bam, Dino, Hoppy, Mr. Slate, Great Gazoo
— Sort the contents of the file and save it into a new file
Any time you are faced with a repetitive task, consider writing a
shell script to do the job. Shell scripts are easily portable, and
can be written so that they will run on any UNIX platform.
# This script sends a reminder about relevant dates (via email) to the user. It reads the file $HOME/special_dates.dat to get
# this information. This script is usually set up as a cron job, so you can get the reminder the morning of the special day.
#
# The data in the special_dates.dat file can be set up to remind once a year, once a month, or on a particular day of the week.
MYPATH="/user/kfoster"
MYNAME="[email protected]"
day_of_wk=`date '+%a'`
day_of_month=`date '+%d'`
month=`date '+%h'`
if [ "$1" = "$day_of_wk" ]
then
echo "$line" >> /tmp/log_$$_spc.dates
fi
done
This line gives you an indication of what commands and syntax is supported when you run the
script.
The shell that the script runs does not necessarily have to match the shell that you invoke it
from.
For the most part, shell scripts are pretty linear. They do however, support functions.
sh is the Bourne shell, csh is the C shell, ksh is the Korn shell, and bash is…. Well it’s the
Bourne Again shell.
An X server is ‘owned’ by the user who starts the X session. Any user,
including root on the same host, must be granted permissions to
display a client
If a X host has only one display, then you can usually connect to the X
server by using the display variable ‘hostname:0’ Example:
Depending on how the installation was done, the X Window System should
already be started. If not, you can start it up with the following
command (after you login)
# startx
If you selected a non-graphical interface when you installed (but you did
install the X windows software) then the system comes up in run level
3 (text interface)
The /etc/inittab file is where you define the default run level.
The second field of this line is where the default run level is set. In this
case, it defaults to a graphical interface. I strongly recommend this, as
it is very simple to go back to the text based interface. The graphical
interface makes using tools like VNC much nicer.
id:5:initdefault:
If you’ve started the system in graphical mode but want to get back text
mode, do a ‘alt-ctl-f3’ to get back to text mode.
The config files for the environment are numerous, and can be found in
/etc/kde/kdm. Actually, these are for the most part links to the files in
the /etc/X11/xdm directory.
If you want to use a broadcast service like xdmcp on a client machine to run the
desktop on a foreign host, you have to modify the /etc/kde/kdm/kdmrc file and
uncomment the Enable entry under [Xdmcp]. If you don’t you will not see this
machine in your XDM Chooser
[Xdmcp]
# Whether KDM should listen to XDMCP requests. Default is true.
Enable=true
If you add your new font path to the catalogue section of the configuration
file, you must restart the font server
#!/bin/sh
#
# xfs: Starts the X Font Server
#
# Version: @(#) /etc/init.d/xfs 2.0
#
# chkconfig: 2345 90 10
Use the same basic process for Xvision, Exceed, etc. The specific process
for each is not covered in this class (Primus records on these subjects
abound)
# export DISPLAY=mymachine:0
# $MGC_HOME/bin/dmgr&
Remember the X server process is owned by the user who started the
session. In some cases, you may have to grant permissions for a
remote machine to connect to your X display. You do this with the
xhost command as the user who owns the display
1) Right click on the desktop, go to the ‘Create New’ menu, and select
either CD/DVD ROM device or Floppy Device
2) In the General tab, enter the desired name in the dialog box (eg
floppy, CDROM, /dev/fd0)
3) In the Device tab, select the appropriate device from the drop down
box.
4) Select OK. The device icon appears on the desktop.
Add mgc fonts from a Solaris machine to your font path, so you can use your Linux
machine as an X terminal to run the Sun version of the tools.
Experiment with kde and gnome. Poke around in the menus, run commands, etc.
Create desktop icons for your floppy and CDROM in the Window Manager of your
choice
file
tar
zip, unzip
gzip, gunzip
compress, uncompress
top
The system log file (/var/log/messages)
Verifying installed software
Getting the OS version
top allows you to monitor processes, determine what is running, who owns it, how much cpu
and memory the process is consuming, and how much memory and swap are available.
Example:
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
4078 root 17 0 1196 1196 928 R 2.3 0.3 0:01 top
1 root 8 0 468 468 400 S 0.0 0.1 0:04 init
2 root 9 0 0 0 0 SW 0.0 0.0 0:00 keventd
3 root 9 0 0 0 0 SW 0.0 0.0 0:00 kapm-idled
4 root 19 19 0 0 0 SWN 0.0 0.0 0:00 ksoftirqd_CPU0
5 root 9 0 0 0 0 SW 0.0 0.0 0:00 kswapd
6 root 9 0 0 0 0 SW 0.0 0.0 0:00 kreclaimd
7 root 9 0 0 0 0 SW 0.0 0.0 0:00 bdflush
8 root 9 0 0 0 0 SW 0.0 0.0 0:01 kupdated
boot.log - records last time system was shut down, and booted up
cron - records the cron activity
maillog - records sendmail activity
messages - The main system log file, records all system messages
rpmpkgs - Records all the rpms that have been installed
lastlog - keeps track of who logged in, when and from where (requires the
lastlog program to read)
secure - records results of login attempts
XFree86 - records information about the X server
— K scripts
— Run levels
When the system starts up, a series of RC scripts are automatically run.
These scripts live in the /etc/rc.d/* directories. The directory number
corresponds to the run level that the script is invoked in. There are 2
kinds of scripts: S scripts and K scripts. S stands for ‘start’, which
means the script is run when the system starts up. The S is followed by
a number, which determines its start order in relation to the other
scripts. K scripts (K is for kill) work the same way, except they are only
invoked when the system is shut down.
If you don’t want to shut all the way down, you can easily move between
run levels (if you are root) with the init command.
# rpm -qa
lists all installed packages
# uname –a
Linux driver 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
# dmesg | head –n 1
Linux version 2.4.7-10 ([email protected]) (gcc version 2.96
20000731 (Red Hat Linux 7.1 2.96-98)) #1 Thu Sep 6 17:27:27 EDT 2001
What package does the command ‘mcopy’ come from? What version of the
Netscape package is installed on your system?
Create a tar file that contains the contents of the /var/run directory
— Compress the file
— uncompress it
— untar it
Run the top command, wait 20 seconds, and determine the following:
— What process is currently using the most resources?
rlogin
rsh
rcp
Files that effect remote access
ssh
# rlogin bedrock
Start a remote terminal on the host bedrock
# rcp dino:/etc/hosts .
Copies the /etc/hosts file on dino to the current directory
# rcp -r dino:/tmp/bedrock .
Copies the bedrock directory (and all files within it) on dino to the
current directory
/etc/hosts.equiv
$HOME/.rhosts
# ssh bedrock
Start a login shell on bedrock
# scp bedrock:/etc/hosts .
Remote copies the /etc/hosts file from bedrock to the current directory
Once a file system is shared, there are three ways a client might mount it.
1) mount command
2) entry in /etc/fstab
3) automount
In the first two cases, a mount point must be manually created. You do
not need to configure anything in most cases to be a simple NFS client.
The service netfs is enabled by default.
You can setup an entry in your /etc/fstab file to mount a file system at
boot time. Example:
This means at boot time, mount the file system /freds_disk that is being
exported by the machine bedrock, on the mount point /mnt/bedrock,
file system type is nfs, use the default options and don’t do any file
system checks on it.
# umount /mnt/bedrock
# umount bedrock:/tmp
With hyperthreading, Intel effectively replicates many of the internal components of the
Pentium 4 micro architecture, creating a virtual image of a second processor running within
the same silicon. Through a clever manipulation of the CPU's internal "architecture state"
(the contents of various control registers and external interfaces), a hyperthreading CPU
can execute two unrelated code paths in parallel, with instructions from each path vying for
resources in a shared execution core.
Of course, there isn't really a second CPU; it just looks that way to the operating system. In
fact, the illusion is so complete that when you first power up a hyperthreading-enabled
system, the BIOS POST (Power-On Self Test) reports the total number of virtual (as opposed
to physical) processors. And as goes the BIOS, so does the operating system.
The cleanest way to disable hyperthreading is in the system bios. Not all systems have an
option to turn this off. If the option isn’t there, you can try to update the bios.
Given an HT-enabled hardware configuration, use the following steps to enable HT in a 2.4 kernel:
1. First, confirm that your kernel is version 2.4.18 or later, with SMP support. There are many ways to do
this, the easiest is to execute the "uname -a" command in a shell. For Red Hat users, Red Hat 7.3 was the
first distribution release to support HT, incorporating a 2.4.18 kernel. If you are using another distribution,
check the kernel version before attempting to use HT.
2. Next, modify your bootloader (grub or lilo), adding the following parameter to any other boot parameters
currently necessary for your system:
acpismp=force
It would be wise to add this as a different boot configuration so that you can boot HT or non-HT. (To create an
explicitly non-HT configuration, add the 'noht' boot flag.)
3. Finally, reboot the system. Before it restarts, enter the BIOS setup program. Under the processor options you
will be able to enable or disable HT. Enable HT, and boot to the 2.4.18 or later SMP kernel with the
additional parameters.
Once you have successfully booted the HT configuration, run top. If HT is properly configured, you should see
twice as many CPU states as you have physical processors (two virtual CPUs per physical cpu)
Discover what file systems are available on other machines in the class
room, and practice NFS mounting and unmounting a few of them