<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>LinuxSense &#187; English</title>
	<atom:link href="http://www.linuxsense.org/archives/category/english/feed" rel="self" type="application/rss+xml" />
	<link>http://www.linuxsense.org</link>
	<description>分享Linux技术的点点滴滴</description>
	<lastBuildDate>Sat, 01 Aug 2009 05:23:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Learn UNIX in 10 minutes</title>
		<link>http://www.linuxsense.org/archives/272.html</link>
		<comments>http://www.linuxsense.org/archives/272.html#comments</comments>
		<pubDate>Mon, 11 Aug 2008 05:53:48 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[UNIX]]></category>

		<guid isPermaLink="false">http://www.linuxsense.org/?p=272</guid>
		<description><![CDATA[Thanks for Cliff, i don&#8217;t know whether it was appropriate to call him Cliff
his homepage is http://freeengineer.org/
Learn UNIX in 10 minutes. Version 1.3  
Preface

This is something that I had given out to students (CAD user training) in years past.
The purpose was to have on one page the basics commands for getting started using
the UNIX shell (so that [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks for Cliff, i don&#8217;t know whether it was appropriate to call him Cliff<br />
his homepage is <a href="http://freeengineer.org/">http://freeengineer.org/</a></p>
<p>Learn UNIX in 10 minutes. Version 1.3  </p>
<p><strong><span style="text-decoration: underline;">Preface</span><br />
</strong><br />
This is something that I had given out to students (CAD user training) in years past.<br />
The purpose was to have on one page the basics commands for getting started using<br />
the UNIX shell (so that they didn&#8217;t call me asking what to do the first time someone<br />
gave them a tape).</p>
<p>This document is copyrighted but freely redistributable under the terms of the <a href="http://www.gnu.org/copyleft/fdl.html">GFDL</a> .</p>
<p>Have an idea for this page?  <img src="http://freeengineer.org/xxx.png" alt="" /><br />
Send me patches, comments, corrections, about whatever you think is wrong or should be<br />
included. I am always happy to hear from you. Please include the word &#8220;UNIX&#8221; in your subject.<br />
<span id="more-272"></span><br />
<strong>Sections:</strong><br />
<span style="color: #0080ff;">Directories:<br />
Moving around the file system:<br />
Listing directory contents:<br />
Changing file permissions and attributes<br />
Moving, renaming, and copying files:<br />
Viewing and editing files:<br />
Shells<br />
Environment variables<br />
Interactive History<br />
Filename Completion<br />
Bash is the way cool shell.<br />
Redirection:<br />
Pipes:<br />
Command Substitution<br />
Searching for strings in files: The grep  command<br />
Searching for files : The find command<br />
Reading and writing tapes, backups, and archives: The tar command <br />
File compression: compress, gzip, and bzip2<br />
Looking for help: The man and apropos commands<br />
Basics of the  vi editor<br />
FAQs<br />
</span>******************************************************************************************<br />
   Basic UNIX Command Line (shell) navigation  : Last revised May 17 2001<br />
******************************************************************************************</p>
<p><a name="Directories"><br />
<span style="text-decoration: underline;"><strong>Directories:</strong></span><br />
</a></p>
<p>File and directory paths in UNIX use the forward slash &#8220;/&#8221;<br />
to separate directory names in a path.</p>
<p>examples:</p>
<p>/              &#8220;root&#8221; directory<br />
/usr           directory usr (sub-directory of / &#8220;root&#8221; directory)<br />
/usr/STRIM100  STRIM100 is a subdirectory of /usr<br />
<a name="Navigating"><br />
<span style="text-decoration: underline;"><strong>Moving around the file system:</strong></span><br />
</a></p>
<p>pwd               Show the &#8220;present working directory&#8221;, or current directory.<br />
cd                Change current directory to your HOME directory.<br />
cd /usr/STRIM100  Change current directory to /usr/STRIM100.<br />
cd INIT           Change current directory to INIT which is a sub-directory of the current<br />
                        directory.<br />
cd ..             Change current directory to the parent directory of the current directory.<br />
cd $STRMWORK      Change current directory to the directory defined by the environment<br />
                        variable &#8216;STRMWORK&#8217;.<br />
cd ~bob           Change the current directory to the user bob&#8217;s home directory (if you have permission).</p>
<p><a name="Listing"><br />
<span style="text-decoration: underline;"><strong>Listing directory contents:</strong></span><br />
</a></p>
<p>ls    list a directory<br />
ls -l    list a directory in long ( detailed ) format</p>
<p>   for example:<br />
$ ls -l<br />
drwxr-xr-x    4 cliff    user        1024 Jun 18 09:40 WAITRON_EARNINGS<br />
-rw-r&#8211;r&#8211;    1 cliff    user      767392 Jun  6 14:28 scanlib.tar.gz<br />
^ ^  ^  ^     ^   ^       ^           ^      ^    ^      ^<br />
| |  |  |     |   |       |           |      |    |      | <br />
| |  |  |     | owner   group       size   date  time    name<br />
| |  |  |     number of links to file or directory contents<br />
| |  |  permissions for world<br />
| |  permissions for members of group<br />
| permissions for owner of file: r = read, w = write, x = execute -=no permission<br />
type of file: &#8211; = normal file, d=directory, l = symbolic link, and others&#8230;</p>
<p>ls -a        List the current directory including hidden files. Hidden files start<br />
             with &#8220;.&#8221;<br />
ls -ld *     List all the file and directory names in the current directory using<br />
             long format. Without the &#8220;d&#8221; option, ls would list the contents<br />
             of any sub-directory of the current. With the &#8220;d&#8221; option, ls<br />
             just lists them like regular files.</p>
<p><a name="Permissions"><br />
<span style="text-decoration: underline;"><strong>Changing file permissions and attributes</strong></span><br />
</a></p>
<p>chmod 755 file       Changes the permissions of file to be rwx for the owner, and rx for<br />
                     the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary)<br />
chgrp user file      Makes file belong to the group user.<br />
chown cliff file     Makes cliff the owner of file.<br />
chown -R cliff dir   Makes cliff the owner of dir and everything in its directory tree.</p>
<p>You must be the owner of the file/directory or be root before you can do any of these things.<br />
<a name="Moving"><br />
<span style="text-decoration: underline;"><strong>Moving, renaming, and copying files:</strong></span><br />
</a></p>
<p>cp file1 file2          copy a file<br />
mv file1 newname        move or rename a file<br />
mv file1 ~/AAA/         move file1 into sub-directory AAA in your home directory.<br />
rm file1 [file2 ...]    remove or delete a file<br />
rm -r dir1 [dir2...]    recursivly remove a directory and its contents BE CAREFUL!<br />
mkdir dir1 [dir2...]    create directories<br />
mkdir -p dirpath        create the directory dirpath, including all implied directories in the path.<br />
rmdir dir1 [dir2...]    remove an empty directory</p>
<p><a name="Viewing"><br />
<span style="text-decoration: underline;"><strong>Viewing and editing files:</strong></span><br />
</a></p>
<p>cat filename      Dump a file to the screen in ascii.<br />
more filename     Progressively dump a file to the screen: ENTER = one line down<br />
                  SPACEBAR = page down  q=quit<br />
less filename     Like more, but you can use Page-Up too. Not on all systems.<br />
vi filename       Edit a file using the vi editor. All UNIX systems will have vi in some form.<br />
emacs filename    Edit a file using the emacs editor. Not all systems will have emacs.<br />
head filename     Show the first few lines of a file.<br />
head -n  filename Show the first n lines of a file.<br />
tail filename     Show the last few lines of a file.<br />
tail -n filename  Show the last n lines of a file.</p>
<p><a name="Shells"><br />
<span style="text-decoration: underline;"><strong>Shells </strong></span><br />
</a></p>
<p>The behavior of the command line interface will differ slightly depending<br />
on the <em>shell</em> program that is being used.</p>
<p>Depending on the shell used, some extra behaviors can be quite nifty.</p>
<p>You can find out what shell you are using by the command:</p>
<p>    echo $SHELL</p>
<p>Of course you can create a file with a list of shell commands and execute it like<br />
a program to perform a task. This is called a shell script. This is in fact the<br />
primary purpose of most shells, not the interactive command line behavior.</p>
<p><a name="EnvVar"><br />
<span style="text-decoration: underline;"><strong>Environment variables</strong></span><br />
</a></p>
<p>You can teach your shell to remember things for later using environment variables.<br />
For example under the bash shell:</p>
<p>export CASROOT=/usr/local/CAS3.0               Defines the variable CASROOT with the value<br />
                                               /usr/local/CAS3.0.<br />
export LD_LIBRARY_PATH=$CASROOT/Linux/lib      Defines the variable LD_LIBRARY_PATH with<br />
                                               the value of CASROOT with /Linux/lib appended,<br />
                                               or /usr/local/CAS3.0/Linux/lib</p>
<p>By prefixing $ to the variable name, you can evaluate it in any command:</p>
<p>cd $CASROOT         Changes your present working directory to the value of CASROOT</p>
<p>echo $CASROOT       Prints out the value of CASROOT, or /usr/local/CAS3.0<br />
printenv CASROOT    Does the same thing in bash and some other shells.</p>
<p><a name="History"><br />
<span style="text-decoration: underline;"><strong>Interactive History</strong></span><br />
</a></p>
<p>A feature of bash and tcsh (and sometimes others) you can use<br />
the up-arrow keys to access your previous commands, edit<br />
them, and re-execute them.</p>
<p><a name="FilenameComp"><br />
<span style="text-decoration: underline;"><strong>Filename Completion</strong></span><br />
</a></p>
<p>A feature of bash and tcsh (and possibly others) you can use the<br />
TAB key to complete a partially typed filename. For example if you<br />
have a file called constantine-monks-and-willy-wonka.txt in your<br />
directory and want to edit it you can type &#8216;vi const&#8217;, hit the TAB key,<br />
and the shell will fill in the rest of the name for you (provided the<br />
completion is unique).</p>
<p><a name="Bash"><br />
<strong><span style="text-decoration: underline;">Bash is the way cool shell. </span><br />
</strong></a><br />
Bash will even complete the name of commands and environment variables.<br />
And if there are multiple completions, if you hit TAB twice bash will show<br />
you all the completions. Bash is the default user shell for most Linux systems.</p>
<p><a name="Redirection"><br />
<span style="text-decoration: underline;"><strong>Redirection:</strong></span><br />
</a></p>
<p>grep string filename &gt; newfile           Redirects the output of the above grep<br />
                                         command to a file &#8216;newfile&#8217;.<br />
grep string filename &gt;&gt; existfile        Appends the output of the grep command<br />
                                         to the end of &#8216;existfile&#8217;.</p>
<p>The redirection directives, &gt; and &gt;&gt; can be used on the output of most commands<br />
to direct their output to a file.<br />
<a name="Pipes"><br />
<span style="text-decoration: underline;"><strong>Pipes:</strong></span><br />
</a></p>
<p>The pipe symbol &#8220;|&#8221; is used to direct the output of one command to the input<br />
of another.</p>
<p>For example:</p>
<p>ls -l | more   This commands takes the output of the long format directory list command<br />
               &#8220;ls -l&#8221; and pipes it through the more command (also known as a filter).<br />
               In this case a very long list of files can be viewed a page at a time.</p>
<p>du -sc * | sort -n | tail <br />
               The command &#8220;du -sc&#8221; lists the sizes of all files and directories in the<br />
               current working directory. That is piped through &#8220;sort -n&#8221; which orders the<br />
               output from smallest to largest size. Finally, that output is piped through &#8220;tail&#8221;<br />
               which displays only the last few (which just happen to be the largest) results.<br />
<a name="CommandSubst"><br />
<span style="text-decoration: underline;"><strong>Command Substitution</strong></span><br />
</a></p>
<p>You can use the output of one command as an input to another command in another way<br />
called command substitution. Command substitution is invoked when by enclosing the<br />
substituted command in backwards single quotes. For example:</p>
<p>cat `find . -name aaa.txt`</p>
<p>which will cat ( dump to the screen ) all the files named aaa.txt that exist in the current<br />
directory or in any subdirectory tree.</p>
<p><a name="Grep"><br />
<span style="text-decoration: underline;"><strong>Searching for strings in files: The <em>grep</em>  command</strong></span><br />
</a></p>
<p>grep string filename    prints all the lines in a file that contain the string</p>
<p><a name="Find"><br />
<span style="text-decoration: underline;"><strong>Searching for files : The <em>find</em> command</strong></span><br />
</a></p>
<p>find search_path -name filename</p>
<p>find . -name aaa.txt    Finds all the files named aaa.txt in the current directory or<br />
                        any subdirectory tree.<br />
find / -name vimrc      Find all the files named &#8216;vimrc&#8217; anywhere on the system.<br />
find /usr/local/games -name &#8220;*xpilot*&#8221;      <br />
                        Find all files whose names contain the string &#8216;xpilot&#8217; which<br />
                        exist within the &#8216;/usr/local/games&#8217; directory tree.</p>
<p><a name="Tar"><br />
<span style="text-decoration: underline;"><strong>Reading and writing tapes, backups, and archives: The <em>tar</em> command</strong>  </span><br />
</a></p>
<p>The tar command stands for &#8220;tape archive&#8221;. It is the &#8220;standard&#8221; way to read<br />
and write archives (collections of files and whole directory trees).</p>
<p>Often you will find archives of stuff with names like stuff.tar, or stuff.tar.gz.  This<br />
is stuff in a tar archive, and stuff in a tar archive which has been compressed using the<br />
gzip compression program respectivly.</p>
<p>Chances are that if someone gives you a tape written on a UNIX system, it will be in tar format,<br />
and you will use tar (and your tape drive) to read it.</p>
<p>Likewise, if you want to write a tape to give to someone else, you should probably use<br />
tar as well.</p>
<p>Tar examples:</p>
<p>tar xv      Extracts (x) files from the default tape drive while listing (v = verbose)<br />
            the file names to the screen.<br />
tar tv      Lists the files from the default tape device without extracting them.<br />
tar cv file1 file2     <br />
            Write files &#8216;file1&#8242; and &#8216;file2&#8242; to the default tape device.<br />
tar cvf archive.tar file1 [file2...]  <br />
            Create a tar archive as a file &#8220;archive.tar&#8221; containing file1,<br />
            file2&#8230;etc.<br />
tar xvf archive.tar  extract from the archive file<br />
tar cvfz archive.tar.gz dname   <br />
            Create a gzip compressed tar archive containing everything in the directory<br />
            &#8216;dname&#8217;. This does not work with all versions of tar.<br />
tar xvfz archive.tar.gz         <br />
            Extract a gzip compressed tar archive.  Does not work with all versions of tar.<br />
tar cvfI archive.tar.bz2 dname  <br />
            Create a bz2 compressed tar archive. Does not work with all versions of tar</p>
<p><a name="Compression"><br />
<span style="text-decoration: underline;"><strong>File compression: <em>compress</em>, <em>gzip</em>, and <em>bzip2</em></strong></span><br />
</a></p>
<p>The standard UNIX compression commands are compress and uncompress. Compressed files have<br />
a suffix .Z added to their name. For example:</p>
<p>compress part.igs    Creates a compressed file part.igs.Z</p>
<p>uncompress part.igs  Uncompresseis part.igs from the compressed file part.igs.Z.<br />
                     Note the .Z is not required.</p>
<p>Another common compression utility is gzip (and gunzip). These are the GNU compress and<br />
uncompress utilities.  gzip usually gives better compression than standard compress,<br />
but may not be installed on all systems.  The suffix for gzipped files is .gz</p>
<p>gzip part.igs     Creates a compressed file part.igs.gz<br />
gunzip part.igs   Extracts the original file from part.igs.gz</p>
<p>The bzip2 utility has (in general) even better compression than gzip, but at the cost of longer<br />
times to compress and uncompress the files. It is not as common a utility as gzip, but is<br />
becoming more generally available.</p>
<p>bzip2 part.igs       Create a compressed Iges file part.igs.bz2<br />
bunzip2 part.igs.bz2 Uncompress the compressed iges file.</p>
<p><a name="Man"><br />
<span style="text-decoration: underline;"><strong>Looking for help: The <em>man</em> and <em>apropos</em></strong></span></a><a name="Vi"><br />
<span style="text-decoration: underline;"><strong>Basics of the <em>vi</em> editor</strong></span><br />
</a><br />
                Opening a file<br />
vi filename</p>
<p>Most of the commands have a manual page which give sometimes useful, often more or less<br />
detailed, sometimes cryptic and unfathomable discriptions of their usage. Some say they<br />
are called man pages because they are only for real men.</p>
<p>Example:</p>
<p>man ls      Shows the manual page for the ls command</p>
<p>You can search through the man pages using <em>apropos</em></p>
<p>Example:</p>
<p>apropos build     Shows a list of all the man pages whose discriptions contain the word &#8220;build&#8221;</p>
<p>Do a <em>man apropos</em> for detailed help on apropos.</p>
<p> </p>
<p>                Creating text<br />
Edit modes: These keys enter editing modes and type in the text<br />
of your document.</p>
<p>i     Insert before current cursor position<br />
I     Insert at beginning of current line<br />
a     Insert (append) after current cursor position<br />
A     Append to end of line<br />
r     Replace 1 character<br />
R     Replace mode<br />
&lt;ESC&gt; Terminate insertion or overwrite mode</p>
<p>                 Deletion of text</p>
<p>x     Delete single character<br />
dd    Delete current line and put in buffer<br />
ndd   Delete n lines (n is a number) and put them in buffer<br />
J     Attaches the next line to the end of the current line (deletes carriage return).</p>
<p>                 Oops</p>
<p>u     Undo last command</p>
<p>                 cut and paste<br />
yy    Yank current line into buffer<br />
nyy   Yank n lines into buffer<br />
p     Put the contents of the buffer after the current line<br />
P     Put the contents of the buffer before the current line</p>
<p>                cursor positioning<br />
^d    Page down<br />
^u    Page up<br />
:n    Position cursor at line n<br />
:$    Position cursor at end of file<br />
^g    Display current line number<br />
h,j,k,l Left,Down,Up, and Right respectivly. Your arrow keys should also work if<br />
      if your keyboard mappings are anywhere near sane.</p>
<p>               string substitution</p>
<p>:n1,n2:s/string1/string2/[g]       Substitute string2 for string1 on lines<br />
                                   n1 to n2. If g is included (meaning global), <br />
                                   all instances of string1 on each line<br />
                                   are substituted. If g is not included,<br />
                                   only the first instance per matching line is<br />
                                   substituted.</p>
<p>    ^ matches start of line<br />
    . matches any single character<br />
    $ matches end of line</p>
<p>These and other &#8220;special characters&#8221; (like the forward slash) can be &#8220;escaped&#8221; with \<br />
i.e to match the string &#8220;/usr/STRIM100/SOFT&#8221; say &#8220;\/usr\/STRIM100\/SOFT&#8221;</p>
<p>Examples:</p>
<p>:1,$:s/dog/cat/g                   Substitute &#8216;cat&#8217; for &#8216;dog&#8217;, every instance<br />
                                   for the entire file &#8211; lines 1 to $ (end of file)</p>
<p>:23,25:/frog/bird/                 Substitute &#8216;bird&#8217; for &#8216;frog&#8217; on lines<br />
                                   23 through 25. Only the first instance<br />
                                   on each line is substituted.</p>
<p>              Saving and quitting and other &#8220;ex&#8221; commands</p>
<p>These commands are all prefixed by pressing colon (:) and then entered in the lower<br />
left corner of the window. They are called &#8220;ex&#8221; commands because they are commands<br />
of the <em>ex</em> text editor &#8211; the precursor line editor to the screen editor<br />
vi.   You cannot enter an &#8220;ex&#8221; command when you are in an edit mode (typing text onto the screen)<br />
Press &lt;ESC&gt; to exit from an editing mode.</p>
<p>:w                Write the current file.<br />
:w new.file       Write the file to the name &#8216;new.file&#8217;.<br />
:w! existing.file Overwrite an existing file with the file currently being edited.<br />
:wq               Write the file and quit.<br />
:q                Quit.<br />
:q!               Quit with no changes.</p>
<p>:e filename       Open the file &#8216;filename&#8217; for editing.</p>
<p>:set number       Turns on line numbering<br />
:set nonumber     Turns off line numbering</p>
<p><a name="FAQS"><br />
<span style="text-decoration: underline;"><strong>FAQs</strong></span><br />
</a><br />
The USENET FAQs should be the first place you look for an answer to specific questions.<br />
You can find most of them at <a href="ftp://rtfm.mit.edu/pub/">RTFM</a><br />
The contents of <a href="ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/unix/questions/">this directory</a> includes vi, bash, and comp.unix.questions FAQs.<br />
Searching USENET archives are very useful too.<br />
google.com has a USENET archive (formerly Deja.com&#8217;s) .<br />
<a href="http://groups.google.com/advanced_group_search">Advanced Group Search</a> rules.</p>
<p>This document was converted from plain text using <a href="http://www.vim.org/">Vim</a> and<br />
then hacked.  Vim is the best version of the one true text editor: vi.</p>
<p>Copyright (c)  2000-2006 <img src="http://freeengineer.org/xxx.png" alt="" /><br />
Permission is granted to copy, distribute and/or modify this document<br />
under the terms of the GNU Free Documentation License, Version 1.1<br />
or any later version published by the Free Software Foundation;<br />
with Invariant Section: Preface, with Front-Cover Texts, and with no<br />
Back-Cover Texts. A copy of the license can be found on the GNU web site<br />
<a href="http://www.gnu.org/copyleft/fdl.html">here</a>.<br />
<strong>commands</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.linuxsense.org/archives/272.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
