Unix - System Commands
TechNotes      |     Unix Home
System Commands:
 

 INIT & Run Levels

 

INIT Manpage
At any given time, the system is in one of eight possible run levels. A run level is a software configuration under which only a selected group of processes exists. Processes spawned by INIT for each of these run levels are defined in /etc/inittab. INIT can be in one of eight run levels, 0-6 and S or s (S and s are identical).
 
init 0 Go into firmware.
init 1 Put the system in system administrator mode. All local file systems are mounted. Only a small set of essen- tial kernel processes are left running. This mode is for administrative tasks such as installing optional utility packages. All files are accessible and no users are logged in on the system.
init 2 Put the system in multi-user mode. All multi-user environment terminal processes and daemons are spawned. This state is commonly referred to as the multi-user state.
init 3 Extend multi-user mode by making local resources available over the network.
init 4 Is available to be defined as an alternative multi- user environment configuration. It is not necessary for system operation and is usually not used.
init 5 Shut the machine down so that it is safe to remove the power. Have the machine remove power, if possible.
init 6 Stop the operating system and reboot to the state defined by the initdefault entry in /etc/inittab.
init a, b, c process only those /etc/inittab entries having the a, b, or c run level set. These are pseudo-states, which may be defined to run certain commands, but which do not cause the current run level to change.
init Q, q Re-examine /etc/inittab.
init S, s Enter single-user mode. This is the only run level that doesn't require the existence of a properly for- matted /etc/inittab file. If this file does not exist, then by default, the only legal run level that init can enter is the single-user mode. When in single-user mode, the filesystems required for basic system operation will be mounted. When the system comes down to single-user mode, these file systems will remain mounted (even if provided by a remote file server), and any other local filesystems will also be left mounted. During the transition down to single- user mode, all processes started by init or init.d scripts that should only be running in multi-user
  1. Processes that must start up during a run level are defined in the /etc/rc*.d directory. (ie: /etc/rc3.d). The processes are defined with an "S##" to designate a start script and the process order (##). For instance S01-whatever will start before S99-whatever. There is a specific order to the start ups. Certain services must be started before you can begin application start ups for instance. So you need to be familiar with what's starting on a server before you add a start up process to the run control list.
  2. For the shutdown run levels (ie: init 0), processes are placed in their corresponding runlevel directory (ie: rc0.d). Process scripts are defined as "K##", to designate a kill script and the process order (##) for shutdowns.
 Server start up mountings
  1. view the vfstabb file
 NFS Mounts on the box
  1. > df -k : grep
 Display Disk Usage
View all allocations on the server
  1. from the root du > filename
filename = the name of the file that will contain the generated report.
If no name is given, the report will be displayed on the screen.
 
View allocations from the root:
  1. > du -sk
s = space
k - kilobytes
View allocations for a specific directory
  1. > du -sk directory name
  2. or
  3. > cd into the desired directory
  4. > du -sk .
 Display status of disk space on file systems
ie: Find free space in a partition
View the entire box
  1. > df -k -F ufs
View a specific directory
  1. > df -k .
 Display current ports being used
View the entire box
  1. > netstat
 
View a specific port
  1. > netstat -an | grep port#
 
To see who's using the specified port
  1. > telent boxname port#
Change users
View all allocations on the server
  1. login as yourself
  2. > su user
 
To login as a super user for root
  1. > su - root
 
To see what user you're logged in as
  1. > whoami
  • (doesn't always work)
 Display the box you're logged onto
  1. uname -a
    Will return, the type of OS, the name of the box, the current patch level, the type of hardware. Ie:
    SunOS mybox002 5.8 Generic_117350-18 sun4u sparc SUNW,Sun-Fire-280R
 Find a file on a server
 To find a specific file on a server,
  1. Go to the file system you think the file might be in. Ie: /MYFiles/
  2. find . -name "ABC.file" -type f
    Will return:
    ./App/WEB-INF/classes/ABC.file
    ./WEB-INF/classes/ABC.file
    ./WEB-INF/lib/ABC.file
 
To find the same file, with it's details:
  1. Go to the file system you think the file might be in. Ie: /MYFiles/
  2. find . -name "ABC.file" -type f -ls
    Will return:
    3682565 1 -rwxrwxr-x 1 mgrid other 117 Nov 8 2002 ./App/WEB-INF/classes/ABC.file
    3682571 4 -rwxrwxr-x 1 mgrid other 3196 Nov 10 2002 ./WEB-INF/classes/ABC.file
    3655683 1 -rwxrwxr-x 1 mgrid other 108 Nov 10 2002 ./WEB-INF/lib/ABC.file
 
File Manipulation Commands:
 Copy directories / files
Copy a file
  1. > cp source-file destination-file
 
Copy a file and maintain it's permissions (if you're not the owner, you need to be root)
  1. > cp -p source-file destination-file
 
Copy a directory and it's contents
  1. > cp -r directory-source directory-destination
 Display directory contents
List all the files in a directory (lists subdirectories and files)
  1. > ls
 
List all the files in a directory, with their attributes (lists subdirectories and files)
  1. > ls -la
 
List all the subdirectories in a directory
  1. > ls -d
 
List all the subdirectories in a directory, with their attributes
  1. > ls -lad
 
List certain files in a directory (ie: only the files starting with http)
  1. > ls -la https*
 Find a string in multiple files
egrep
To find a specified string within multiple files, use egrep.
This will look in all the files in the current directory for the string "Listen". The results returned will be {filename : line containing the searched for string}
  1. > egrep Listen *
will return:
vhost-order:Listen 6300
vhost-purchase:Listen 6301
vhost-delivery:Listen 6302
 Tar and gzip
Tar ManPage
Create a tar file (tarball)
  1. > tar -cvf filename.tar directory/file-to-tar
  2. ie: tar -cvf vanilla.tar /www/covalent
 
To create a tar file with only certain files or directories, use an include file:
  1. Create (with VI) a file named include that contains the full path of the directories, (and files) to be included.
    • > cd to the directory where the tar will be stored.
    • > vi include
    • > insert the directories (1 on each line - NO spaces or trailing spaces)
    • :> wq!
      • the file "include" looks like this:
      /www/covalent
      /www/approot/vanilla
      /www/docroot/vanilla
  2. Create the tar file:
    • > tar -cvf filename.tar -I include-file name created in the previous steps.
    • ie: tar -cvf vanilla.tar -I include
 
To view the contents of the tar file you just created:
  1. > tar -tvf filename.tar
  2. If you need to see one page of the contents at a time:
  3. > tar -tvf filename.tar | more
    • If you need to go back after a page has been displayed, use cntl + b
 
To extract a tar:
  1. Make sure you're in the directory where you want to explode the contents of the tar. (if you used the full path name to create the tar, you can be anywhere when it explodes).
  2. > tar -cvf filename.tar
 
To compress a tar file into a .gz file
  1. Note: gzip will delete .tar file once the .tar.gz file has been created, so only the .gz remains on the box.
  2. > gzip filename.tar
 
To explode a .gz file
  1. You have to uncompress a .gz file before you can untar it.
  2. > gunzip filename.tar.gz
  3. > tar -xvf filename.tar
 Find a string in compressed .gz files
gzmore
To find a specified string within compressed files: *.gz
This command works similarly to the more command, and uses basically the same parameters.
  1. > gzmore *2005* | grep /lmpweb
will return the lines in all the *2005* files within the selected directory that contain the /lmpweb directive.