Unix commands Quick reference

Special commands and characters:

Converting DOS commands to UNIX commands

There are a few command line questions that are asked very often. These questions, with answers that should be typed at your shell prompt are printed below:

DOS                 UNIX
dir ............... ls
cls ............... clear
del ............... rm
copy .............. cp
move / rename ..... mv
type .............. cat
cd ................ cd
more < file ....... more file
md ................ mkdir
rd ................ rmdir
win ............... startx
(Note:  Unlike DOS, commands and their arguments MUST be separated by a space. 
For example, "cd/" doesn't work, but "cd /" does.)

Redirection

< Routes input to command from file
> Routes output from command to file
>> Appends output to existing file
| Routes output between commands

Pipes and redirection

command < file

Use the contents of file as the input for command

command > file

Send the output of command to file

command >> file

Append the output of command to the end of file

command1 | command2

Use the output of command1 as the input of command2 This is the Unix “pipe”. The “|” is called the “pipe” symbol.

Wildcards used in filenames

* Matches any number of characters
? Matches one character

Control codes

<Control>s Suspends the screen display
<Control>q Restarts suspended display
<Control>d Signals end of file
<Control>c Cancels a command
<Control>z Suspends a process or job:
use fg to restart
<Control>u Clears the command line
!string Repeat last shell command that began with string (for example, type “!m” to repeat the last command that began with “m”)

Daemon Process

In Unix and other computer multitasking operating systems, a daemon is a computer program that runs in the background, rather than under the direct control of a user; they are usually initiated as background processes. Typically daemons have names that end with the letter “d”: for example, syslogd, the daemon that handles the system log, or sshd, which handles incoming SSH connections.

In a Unix environment, the parent process of a daemon is often (but not always) the init process (PID=1). Processes usually become daemons by forking a child process and then having their parent process immediately exit, thus causing init to adopt the child process. This is a somewhat simplified view of the process as other operations are generally performed, such as disassociating the daemon process from any controlling tty. Convenience routines such as daemon(3) exist in some UNIX systems for that purpose.

Systems often start (or “launch”) daemons at boot time: they often serve the function of responding to network requests, hardware activity, or other programs by performing some task. Daemons can also configure hardware (like devfsd on some Linux systems), run scheduled tasks (like cron), and perform a variety of other tasks.

Types of daemons

In a strictly technical sense, a Unix-like system process is a daemon when its parent process terminates and is therefore ‘adopted’ by the init process (process number 1) as its parent process and has no controlling terminal. However, more commonly, a daemon may be any background process, whether a child of init or not.

The common method for a process to become a daemon involves:

  • Disassociating from the controlling tty
  • Becoming a session leader
  • Becoming a process group leader
  • Staying in the background by forking and exiting (once or twice). This is required sometimes for the process to become a session leader. It also allows the parent process to continue its normal execution. This idiom is sometimes summarized with the phrase “fork off and die”
  • Setting the root directory (“/”) as the current working directory so that the process will not keep any directory in use that may be on a mounted file system (allowing it to be unmounted).
  • Changing the umask to 0 to allow open(), creat(), et al. calls to provide their own permission masks and not to depend on the umask of the caller
  • Closing all inherited open files at the time of execution that are left open by the parent process, including file descriptors 0, 1 and 2 (stdin, stdout, stderr). Required files will be opened later.
  • Using a logfile, the console, or /dev/null as stdin, stdout, and stderr

This is a list of Unix daemons that are found on various flavors of Unix. Unix daemons will typically consist of an abbreviation ending with a d. The current state of these processes can be listed with the full-output option of the process status (ps) command.

Process

Description

init

The Unix program which spawns all other processes.

biod

Works in cooperation with the remote nfsd to handle client NFS requests.

dhcpd

Dynamically configure TCP/IP information for clients.

fingerd

Provides a network interface for the finger protocol, as used by the finger command.

ftpd

Services FTP requests from a remote system. It listens at the port specified in the services file for ftp.

httpd

Web serve daemon.

inetd

Listens for network connection requests. If a request is accepted, it can launch a background daemon to handle the request. Some systems use the replacement command xinetd.

lpd

The line printer daemon that manages printer spooling.

nfsd

Processes NFS operation requests from client systems. Historically each nfsd daemon handled one request at a time, so it was normal to start multiple copies.

ntpd

Network Time Protocol daemon that manages clock synchronization across the network. xntpd implements the version 3 standard of NTP.

rpcbind

Handles conversion of remote procedure calls (RPC), such as from ypbind.

sshd

Listens for secure shell requests from clients.

sendmail

SMTP daemon.

swapper

Copies process regions to swap space in order to reclaim physical pages of memory for the kernel. Also called sched.

syslogd

System logger process that collects various system messages.

syncd

Periodically keeps the file systems synchronized with system memory.

xfsd

Serve X11 fonts to remote clients.

vhand

Releases pages of memory for use by other processes. Also known as the “page stealing daemon”

ypbind

Find the server for an NIS domain and store the information in a file.

System Security

The following mechanism is the ONLY guaranteed method of protecting your work.

Each file and directory is owned by a user, and each user belongs to a group. By default, users own their home directory (the current directory when the user logs in) and the contents of the home directory. Most other files and directories are owned by “root” and other special users. The user assigns a type of privilege to each file and directory owned by the user. By default, the privilege is rwxr-xr-x.

The first three characters of rwxr-xr-x indicate that the owner can read, write, and execute the file (or directory). The middle three characters indicate that all other users in the same group as the owner can read and execute the file (or directory), but cannot write onto the file (or directory), as indicated by the middle “” character. The last three characters indicate that everyone else on the system can read and execute the file (or directory), but cannot write onto the file (or directory), as indicated by the last “” character.

To change the owner’s permissions of a file (or directory), the owner can type:

chown u+r file.1   chown u+w file.1   chown u+x file.1
chown u-r file.1   chown u-w file.1   chown u-x file.1

To change the group’s permissions of a file (or directory), the owner can type:

chown g+r file.1   chown g+w file.1   chown g+x file.1
chown g-r file.1   chown g-w file.1   chown g-x file.1

To change the permissions of a file (or directory) for everyone else, the owner can type:

chown o+r file.1   chown o+w file.1   chown o+x file.1
chown o-r file.1   chown o-w file.1   chown o-x file.1


Typing Shortcuts

  • file* specifies all files and sub-directories that start with “file” and have 0 or more extra characters. *file* specifies all files and sub-directories that contain the string “file” anywhere in their name. fi*le specifies all files and sub-directories that start with “fi” and end with “le”, with 0 or more extra characters.
  • file? specifies all files and sub-directories that start with “file” and have one extra character.
  • The current directory can be specified as “.”, and the parent directory of the current directory can be specified as “..”. For example, if the current directory is /usr/people/mpagel, I can copy the file /usr/people/huffman/Crambin.pdb to /usr/people/mpagel/pdb/ by typing:
     cp  ../huffman/Crambin.pdb  ./pdb/
  • Text on the screen can be highlighted by sweeping the mouse cursor over the text while pressing and holding the left mouse button. This text can be inserted at the command line by clicking the center mouse button, regardless of the mouse cursor position (as long as the mouse cursor remains in the window).
  • If you type the first part of the name of a file or sub-directory in the current directory and then hit the <Esc> escape key, the workstation will complete the name for you. For example, if the current directory contains the files template.001 and temporary.stuff, then I can type:
    more templ<Esc>
    and the workstation will complete the name template.001. Note that if I type:
    more temp<Esc>
    then the workstation will NOT complete the file name, since I have not specified enough characters to unambiguously specify template.001 instead of temporary.stuff.
  • history Shows list of last 100 commands

!! Repeats last command

!32 Repeats command #32 in the history list

!mor Repeats last command starting with “mor”

•·         If I type mv file.1 dir.1 to move file.1 to dir.1, then I can move file.2 to dir.1 by typing ^1^2, which does the following command: mv file.2 dir.1. Note that the only the first “1” (in file.1) changes, and the “1” in dir.1 does NOT change.

•·         Many commands have ‘modifiers’. For example, ls -l has a modifier “-l” which specifies that the LONG listing of the directory contents should be printed. Many modifiers can be combined in any order in one command. For example ls -la specifies the LONG listing of ALL directory contents.

•·         The “|” character is called the PIPE character. This character is located on the key just above the <Enter> key on the SGI keyboard (you must also hold down the <shift> key). The pipe character is used to direct the output of one command into the input of a second command. For example,

ps -ef | grep biosym
first creates a list of processes (ps -ef) and then filters this list to show all lines that contain “biosym” (grep biosym).

Jun 24th, 2009 | Posted by Tushar Thakker | In Linux/Unix/Solaris, Shell scripting
No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>