|
|
This manual is designed to provide a "Getting Started" or
"Beginner's Guide" to the most useful commands in Unix, as
well as examples of how to use them. More information on most
commands may be obtained by typing "man <command>" on
the command line. It is recommended that users get a book for
better reference. O'Reilly's, Unix in a Nutshell 2nd
Edition, is the reference for this manual.
| File Managment
Commands | | cat | Join files or display them
Read one or more files and print them on the screen (or
standard output). You can then use the > operator to
combine several files into a new file. Examples:
| cat
hello.txt | Displays the file
hello.txt |
| cat hello.txt world.txt >
helloworld.txt | Combines files hello.txt and
world.txt into one file called helloworld.txt |
| | cd | Change working directory
Examples:
| cd | Changes working
directory to user's home directory. |
| cd dir1 | Changes
working directory to dir1. |
| cd .. | Changes
working directory one level up. |
| | chmod | Change access modes on files
Only the owner of a file or a privileged user may change its mode.
Syntax: chmod [option] mode files
Options: -R Recursively descend thgrough directoy setting modes to files
Mode: Composed of who, opcode and permission.
| Who | u | User |
| g | Group |
| o | Other |
| a | All (default) |
| Opcode | + | Add permission |
| - | Remove permission |
| = | Assign permission (and remove permission of the unspecified fields) |
| Permission |
r | Read | OR* | 4 | Read |
| w | Write | 2 | Write |
| x | Execute | 1 | Execute |
*Permissions may also be specified by a 3 digit sequence.
The first digit designates owner permission; the second, group permission; and the
third, others permission. Permissions are calculated by adding the values in the table.
Examples:
| chmod u+x file | Adds execute-by-user permission to file |
chmod 751 file
chmod u=rwx,g=rx,o=x file |
Both these examples assign read-write-execute permission by owner (7),
read-write permission by group (5), and execute-only permission by others (1) to
file. |
| | cp | Copy files
Syntax: cp [options] file1 file2
cp [options] files directory
Examples:
| cp file1 file2 | Copies file1 into file2. |
| cp file1 file2 file3 dir1 |
Copies file1, file2 and file3 to directory dir1, preserving the files' names |
| cp -r dir1 dir2 | Recursivle copy directory dir1, its files and
subdirectories to a destination directory dir2 (duplicating the tree structure). |
| | head | Show the first few lines of a file
Examples:
| head -20 file1 | Displays the first 20 lines of file1 |
|
| ls | List files or directories
Syntax: ls [options] [names]
If no names are given, list the files in the current directory. With one or more names, list files contained in a directory name or that match a file name.
Some Options:
| -a | List all files, including the normally hidden . files |
| -c | List files by creation/modification time |
| -l | Long format listing (includes permissions, owner, size, modification time, etc.) |
| | mkdir | Create a directory
Syntax: mkdir directories
Create one or more directories. You must have write permission in the parent
directory in order to create a directory.
Examples:
| mkdir dir1 | Creates a directory named dir1. |
| mkdir dir1 dir2 dir3 | Creates directories named dir1, dir2 and dir3. |
|
| more | Display files by screenful
Syntax: more files
Display the named files on a terminal, one screenful at a time.
After each screen is displayed, press RETURN to display the next
line or press the spacebar to display the next screenful.
| | mv | Move or rename files or directories
Syntax: mv sources target
Basic command to move files and directories around on the system or to rename them.
The following table summarizes how mv works.
| | pwd | Print your working directory | | rm | Remove files | | rmdir | Remove directories | | tail | Show the last few lines of a file | | wc | Count lines, words, and characters | | Back to top |
| Miscellaneous Commands |
|---|
| bc | Precision calculator Input can
be taken from files or read from the standard input. To exit,
type "quit" or "EOF". For mor information type "man
bc". | | cal | Display calendar
With no arguments, cal prints the calendar for
the current month. Otherwise, print either a 12-month
calendar (beginning with January) for the given
year or a one-month calendar of the given
month and year. Examples:
| cal 10
2003 | Displays one-month calendar for
October, 2003 |
| cal 2005 | Displays 12-month
calendar for 2005 |
| | clear | Clear the screen | | man | Display information from the on-line reference manuals.
Syntax: man [command]
Example: man mkdir Display manual pages for command "mkdir". | | tar | Tape archiver
Syntax: tar [options] [files]
Copy files to or restor files from tape. If any files are directories, tar acts on the entire
subtree.
| Options | -zcvf arch | Create a new tape arch. |
| -ztvf arch | Print names of files in arch. |
| -zrvf arch | Append files to tape arch. |
| -zxvf arch | Extract files from tape arch. |
Examples:
| tar -zcvf arch file1 file2 | Creat an archive of file1 and file2
and store it in arch |
| tar -zxvf arch | Extract all the files in arch. |
| | vi | Visual text editor
Syntax: vi [file]
If file exists, open file for editting. Otherwise, create file and open for editing.
If no file is specified, vi opens wiht an empty buffer.
Some vi commands:
| a | Append after the cursor. |
| A | Append at end of line. |
| i | Insert before cursor. |
| I | Insert at beginning of line. |
| o | Open a line below current line. |
| O | Open a line above current line. |
| dd | Delete current line. |
| :w | Write to file. (use :w! to force write) |
| :q | Quit vi. (use :q! to force quit) |
| h | Move one character to the left. |
| j | Move one line down. |
| k | Move one line up. |
| l | Move one character to the right. |
| | Back to top |
| System
Status Commands |
|---|
| chgrp | Change file group
Syntax: chgrp [options] newgroup files
Change the ownership of one or more files to newgroup.
You must own the file or be a privileged user to suceed this command.
Example:
| chgrp hello.txt group1 | Changes the group for file hello.txt to group1 |
| chgrp -R dir1 group1 | Recursively descends through directory dir1, including subdirectories, setting group to group1 |
| | chown | Change file owner
Syntax: chown [options] newowner files
Change the ownership of one or more files to newowner.
Example:
| chown user1 file1 file2 |
Changes the owner of file1 and file2 to user1. |
| chown -R user1 dir1 |
Recursively descends through directory dir1, including subdirectories, setting
the owner to user1. |
| | date | Display the current date and time.
Priviledged users may also set a date and time. | | finger | Point out information about users.
Syntax: finger [options] users
Displays data about one or more users. | | hostname | Print the name of the host machine. | | ps | Report on active processes
Syntax: ps [options]
| Options | -A | List all processes. |
| -u users | List processes only for usernames in users. |
For more options type man ps.
| | who | List the names of users currently
logged into the system. | | whoami | Print the effective username. | | Back to top |
|