📄 linux tutorial-2.htm
字号:
command line by separating them with semicolons. (Not of interest
for now)</FONT></FONT> </LI></UL>
<P>When changing access privileges the identifiers <B>u</B> - user,
<B>g</B> - group and <B>a</B> - everyone are used. For example, this is
what is required if everyone is to be allowed to read from and write to
<B>file.txt</B>:</P>
<UL type=circle>
<LI><B>chmod a+r+w file.txt</B> </LI></UL>
<P>Directories are a little different to files. They have access
privileges that relate to accessing the files within them. For example,
when setting the executable privilege to everyone on a directory we simply
allow everyone to "move into that directory".</P>
<P><FONT size=5>3. Wildcards and Variables</FONT></P>
<P><FONT size=4>3.1 Wildcards (or pattern matching)</FONT></P>
<P>When using the command line it may be quite time consuming to
accomplish certain tasks simply using what we have covered here. For
example, you may only wish to list files that match a certain criteria.
There is help at hand. One of the most useful "short cuts" is via the use
of the <B>*</B> (asterisk) character. Simply stated, the use of <B>*</B>
simply allows a user to state "anything goes" in a directory or file name.
As an example of its use consider the desire to list all files that begin
with the letter "f": </P>
<UL type=circle>
<LI><B>ls f*</B> </LI></UL>
<P>Alternatively, say we require to list all files that end in txt:</P>
<UL type=circle>
<LI><B>ls *txt</B> </LI></UL>
<P>The <B>*</B> is known as a wildcard. There are other wildcards and
their use may be summarized as:</P>
<UL type=circle>
<LI><B>* </B>(asterisk) - matches zero or more characters in a file
name. Therefore <B>a*</B> matches the names <B>a</B>, <B>ab</B>,
<B>abc</B>, etc. <B>*</B> by itself matches all file names with certain
exceptions to be noted.
<LI><B>? </B>(question mark) - matches exactly one character in a file
name. Therefore <B>a?</B> matches <B>ab</B>, <B>ac</B>, but not a nor
<B>abc</B>.
<LI><B>\ </B>(backslash) treat the character following the <B>\</B> as a
non special character. Therefore, you can refer to a file named:
<B>e?b</B> as <B>e\?b</B>. </LI></UL>
<P><FONT size=4>3.2 Environmental variables</FONT></P>
<P>Variables exist within the command line environment. Variables are
identified by the <B>$</B> (dollar sign) that proceeds them. You can
substitute any hard coded data with variables. For example, you can return
to your <B>$HOME</B> directory whenever you wish by simply typing:</P>
<UL type=circle>
<LI><B>cd $HOME</B> </LI></UL>
<P> Here are some useful variables that may be used:</P>
<UL type=circle>
<LI><TT class=VARNAME><B>$HOME - </B></TT>Home directory of the user,
usually <TT class=FILENAME>/home/username</TT>
<LI><B><TT class=VARNAME>$HOSTNAME - </TT></B>Name assigned to the
system, usually fetched at bootup from <TT
class=FILENAME>/etc/hosts</TT>
<LI><B><TT class=VARNAME>$UID - </TT></B>User id number
<LI>Current user's user identification number, as recorded in <TT
class=FILENAME>/etc/passwd</TT>
<LI><TT class=VARNAME><B>$EUID - </B></TT><SPAN
class=QUOTE>"Effective"</SPAN> user id number
<LI>may be different from $UID as the user may sometimes assume other
IDs (don't worry about this issue for now)
<LI><B><TT class=VARNAME>$GROUPS - </TT></B>Groups current user belongs
to
<LI>This is a listing (array) of the group id numbers for current user,
as recorded in <TT class=FILENAME>/etc/passwd</TT>.
<LI><B><TT class=VARNAME>$PATH - </TT></B>Path to binaries, usually <TT
class=FILENAME>/usr/bin/</TT>, <TT class=FILENAME>/usr/X11R6/bin/</TT>,
<TT class=FILENAME>/usr/local/bin</TT>, etc.
<LI>When given a command, the shell automatically searches the
directories listed in the <EM>path</EM> for the executable. The path is
stored in the environmental variable, <TT class=VARNAME>$PATH</TT>, a
list of directories, separated by colons. Normally, the system stores
the <TT class=VARNAME>$PATH</TT> definition in <TT
class=FILENAME>/etc/profile</TT>
<P><TT class=USERINPUT><B>PATH=${PATH}:/opt/bin</B></TT> appends the <TT
class=FILENAME>/opt/bin</TT> directory to the current path.</P>
<DIV class=NOTE>
<BLOCKQUOTE class=NOTE>
<P><B>Note: </B>The current <SPAN class=QUOTE>"working
directory"</SPAN>, <TT class=FILENAME>./</TT>, is usually omitted from
the <TT class=VARNAME>$PATH</TT> as a security
measure.</P></BLOCKQUOTE></DIV>
<LI>The following are provided for information only:
<LI><FONT color=#c0c0c0><TT class=VARNAME><B>$PS1 - </B></TT>This is the
main prompt, seen at the command line.</FONT>
<LI><FONT color=#c0c0c0><TT class=VARNAME><B>$PS2 - </B></TT>The
secondary prompt, seen when additional input is expected. It displays as
<SPAN class=QUOTE>">"</SPAN>.</FONT>
<LI><FONT color=#c0c0c0><TT class=VARNAME><B>$PS3 - </B></TT>The
tertiary prompt, displayed in a <B class=COMMAND>select</B>.</FONT>
<LI><FONT color=#c0c0c0><TT class=VARNAME><B>$PS4 - </B></TT>The
quartenary prompt, shown at the beginning of each line of output when
invoking a script with the <SPAN class=TOKEN>-x</SPAN> option. It
displays as <SPAN class=QUOTE>"+"</SPAN>.</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$PWD - </TT></B>Working
directory (directory you are in at the time)</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$OLDPWD - </TT></B>Old
working directory (previous directory you were in)</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$DIRSTACK -
</TT></B>Contents of the directory stack</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$PPID - </TT></B>The
process id (pid) of the currently running process.</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$MACHTYPE -
</TT></B>Machine type, Identifies the system hardware.</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$HOSTTYPE - </TT></B>Host
type</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$OSTYPE -
</TT></B>Operating system type.</FONT>
<LI><FONT color=#c0c0c0><B><TT class=VARNAME>$EDITOR - </TT></B>The
default editor invoked by a script, usually <B class=COMMAND>vi</B> or
<B class=COMMAND>emacs</B>.</FONT> </LI></UL>
<P>When you log in a special script (more about scripts later) is parsed
and the shell updates environmental variables automatically at logging in
time (without you having to set variables each time you log in). This is
commonly found in the <B>.profile</B> file. A sample <B>.profile</B> file
may look like this:</P>
<P><B>PATH=:$HOME:/bin:/usr/bin:/usr/local/bin:/usr/local/X11/bin:/usr/local/X11-local<BR>:/usr/openwin/bin:usr/ccs/bin:/usr/ucb:/usr/local/CC/current/bin:/usr/ccs/bin:/u<BR>sr/local/JavaIDL/current/bin:/usr/local/JavaIDL/current/bin<BR>export
PATH<BR>PRINTER=durian <BR>export
PRINTER<BR>OMNIORB_CONFIG=$HOME/omniORB.cfg<BR>export
OMNIORB_CONFIG<BR>EDITOR=/usr/local/bin/memacs<BR>export
DISPLAY<BR>VISUAL=/usr/local/bin/emacs<BR>MANPATH=/usr/share/man:/usr/local/man:/usr/local/X11R5/man:/usr/local/CC/current<BR>/man<BR>CVSROOT=/usr/share/src/arjuna.cvs<BR>X11HOME=/usr/local/X11<BR>LD_LIBRARY_PATH=/usr/local/X11/lib:/usr/ucblib:/lib:/usr/local/jdk/lib:/usr/loca<BR>l/JavaIDL/current/lib:/usr/local/omniORB/2.7.1/lib/i586_linux_2.0_glibc<BR>export
LD_LIBRARY_PATH<BR></B></P>
<P><FONT size=4>3.3 Online help</FONT></P>
<P>The number of ways a command can be used tends to be diverse.
Therefore, there is a help system that identifies how commands may be
used. This command system is commonly known as <B>man</B> (short for
manual). If ever you want to know more about a command, placing man before
the command name will bring up a useful help sheet, describing how the
command may be used. For example, if I want to know how <B>ls</B> may be
used you can simply type:</P>
<UL type=circle>
<LI><B>man ls</B>
<LI><B>NOTE - To get out of the man page listing press the "q" key and
to scroll the man page listing press space.</B> </LI></UL>
<P>Another helpful aspect of executable programs (not usually basic
commands like <B>ls</B>) is that they usually (but not always) come with
help sheets built in. This is commonly accessed via the name of the
command followed by a <B>-</B> (dash) and <B>h</B> (or <B>help</B>). For
example, there is a simple program available on most Linux systems that
manages your email called <B>pine</B>. If I wanted help on how <B>pine</B>
works I could simply type:</P>
<UL type=circle>
<LI><B>pine -help</B> </LI></UL>
<HR>
<P><FONT size=5>Exercises</FONT></P>
<P><FONT color=#c0c0c0><B>1)</B> Login and change your password</FONT>
(NOT POSSIBLE ON YOUR SYSTEM - MISS THIS QUESTION OUT).</P>
<P><B>2)</B> Make a directory called "myDirectory" in your home
directory.</P>
<P><B>3)</B> Using the program "nedit" create a text file that contains
your name and call this file "myDetails".</P>
<P><B>4)</B> From inside the directory "myDirectory" make the directory
tree "myFiles/text/tmp".</P>
<P><B>5)</B> Move the "myDetails" file to the newly created "tmp"
directory.</P>
<P><B>6)</B> Make a directory in the "myFiles" directory and call it
"bin".</P>
<P><B>7)</B> Create a copy of the directory tree which has the root
directory of "myDirectory" and call "myWork".</P>
<P><B>8)</B> Remove, via a single command, the whole directory tree that
has the root directory "myDirectory".</P>
<P> </P>
<P> </P>
<P> </P></TD></TR></TBODY></TABLE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -