📄 linux tutorial-2.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0066)http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/linux2.htm -->
<HTML><HEAD><TITLE>Linux Tutorial</TITLE>
<META http-equiv=Content-Language content=en-us>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<META content="MSHTML 6.00.2800.1226" name=GENERATOR>
<META content=FrontPage.Editor.Document name=ProgId></HEAD>
<BODY>
<TABLE width=1 border=0>
<TBODY>
<TR>
<TD width=163> </TD>
<TD width=578>
<P align=center><I><B><A
href="http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/index.htm">Home</A>
- <A
href="http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/linux1.htm">(1)
Shells</A> - <A
href="http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/linux2.htm">(2)
Files & Directories</A> - <A
href="http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/linux3.htm">(3)
Processes</A> - <A
href="http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/linux4.htm">(4)Shell
scripting</A> - <A
href="http://www.cs.ncl.ac.uk/modules/2003-04/csc842/LinuxTut/linux5.htm">(5)Makefiles</A></B></I></P></TD></TR>
<TR>
<TD width=163></TD>
<TD width=578><FONT face="Times New Roman" size=5>Linux Tutorial - User's
view (2)</FONT>
<P><FONT face="Times New Roman">Subject Summary</FONT></P>
<OL>
<LI><FONT face="Times New Roman">Logging in, logging out and changing
your password</FONT>
<LI><FONT face="Times New Roman">Navigating the system and manipulating
files and directories</FONT>
<LI><FONT face="Times New Roman">Using wildcards, environmental
variables and gaining online help</FONT> </LI></OL>
<P><I><B><FONT face="Times New Roman" size=5>1. Logging in and out and
changing your password.</FONT></B></I></P>
<P><FONT face="Times New Roman" size=4>1</FONT><FONT
face="Times New Roman" size=4>.1 Logging in</FONT></P>
<P><FONT face="Times New Roman">You can login to a <EM>UNIX</EM> operating
system after you had been assigned a <EM>username</EM> and <I>password</I>
by a system administrator. You will be greeted by a login screen or a
command line. Usually the system administrator has provided a login screen
that simply requires you to input your username and password.</FONT></P>
<P><I><FONT face="Times New Roman">Who else is logged on?</FONT></I></P>
<UL type=circle>
<LI><FONT face="Times New Roman"><B>who</B> - show who is logged
on</FONT> </LI></UL>
<P><FONT face="Times New Roman" size=4>1</FONT><FONT
face="Times New Roman" size=4>.2 Logging out</FONT></P><FONT
face="Times New Roman">It depends on the system. Usually by
<CODE><B>ctrl-d</B></CODE> (pressing the control button and <B>d</B> at
the same time) but in a lot of systems you must use a special
command:</FONT>
<UL type=circle>
<LI><CODE><B><FONT face="Times New Roman">logout</FONT></B></CODE>
</LI></UL>
<P><FONT face="Times New Roman">or</FONT>
<UL type=circle>
<LI><CODE><B><FONT face="Times New Roman">exit</FONT></B></CODE>
</LI></UL>
<P><FONT face="Times New Roman" size=4>1</FONT><FONT
face="Times New Roman" size=4>.3 Changing your password (NOT AVAILABLE ON
YOUR ACCOUNTS - PLEASE LOOK AT UCS LITERATURE FOR
INFORMATION)</FONT></P><FONT face="Times New Roman" color=#c0c0c0>If you
want to change your password, you will write the command
<CODE><B>passwd</B></CODE></FONT>
<P><FONT face="Times New Roman" color=#c0c0c0>System responds (if your
username is <CODE>n57</CODE>):</FONT>
<UL type=circle>
<LI><CODE><FONT face="Times New Roman" color=#c0c0c0>Changing password
for n57<BR><B>Old password:</B> </FONT></CODE><FONT
face="Times New Roman" color=#c0c0c0>(You will write your actual
password after colon)<BR><CODE><B>New password:</B> </CODE>(You will
write your new password after colon)<BR><B>Re-type new password:
</B>(You will repeat your new password after colon)<BR>Password
changed</FONT> </LI></UL>
<P><FONT face="Times New Roman" color=#c0c0c0>If you write your old
password and a new password correctly, the new one becomes valid. However,
if the new password is deemed not "difficult enough" the system will ask
you to enter a new password. Quite often the system administrator will do
this to prevent passwords from been hacked.</FONT>
<P><B><I><FONT face="Times New Roman" size=5>2. Using directories and
files</FONT></I></B></P>
<P><FONT size=4>2.1 Exploring</FONT></P>
<P>The file system is structured in a hierarchical fashion. With
directories containing other files and/or directories. There is a single
directory known as "root" that is the base of this hierarchical structure.
When you login you will be located within a special directory the system
administrator has set up just for you. You will have the power to create,
delete, copy and move files/directories within this directory. However,
you may still view other directories that don't belong to you, but it is
most likely you won't be able to create or delete files/directories in
these other areas. The following commands are most useful for navigating
and viewing the directories and files within the system:</P>
<UL type=circle>
<LI><PRE><FONT face="Times New Roman"><B>cd</B>: change directory. Just typing '<B>cd</B>' should change to your home directory. </FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>ls</B>: list contents of directory (like DOS DIR) </FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>ls -la</B>: list all files, long (detailed) format</FONT></PRE></LI></UL>
<P><FONT size=4>2.2 Manipulating</FONT></P>
<P>The following commands allow you to manipulate files and
directories:</P>
<UL type=circle>
<LI><PRE><FONT face="Times New Roman"><B>mv</B>: move or rename files (e.g., <B>mv helloFile /tmp</B>)</FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>rm</B>: remove files (and directories when used appropriately - will see later) (e.g., <B>rm helloFile</B>)</FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>mkdir</B>: make directory (e.g., <B>mkdir myDirectory</B>)</FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>mkdir -p</B>: make a directory tree (eg <B>mkdir -p /big/small/dance</B> - note this uses an absolute path name)</FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>rmdir</B>: remove directory (e.g., <B>rmdir myDirectory</B>)</FONT></PRE>
<LI><PRE><FONT face="Times New Roman"><B>pwd</B>: print working directory (shows you current directory)</FONT></PRE></LI></UL>
<P><FONT size=4>2.3 Accessing</FONT></P>
<P>In a Linux environment files and directories actually belong to a user.
Usually the creator (but not always - your home directory for example). A
quite primitive, but effective, security system is associated to each
file/directory, restricting access for certain users. This is what stops
you from creating files in directories you should not be in. There are
three types of user: <B>user</B> - a single user like your good self,
<B>group</B> - a collection of users (usually identified by the
administrator) and <B>world (everyone)</B> - which is everyone with access
to the system. Here is some output from the <B>ls -la</B> command:</P>
<P align=left>-rw-rw-r-- 1 n57 123 Feb 03
15:36 file.txt</P>
<TABLE borderColor=#f0f0f0 cellSpacing=0 borderColorDark=#ffffff
cellPadding=0 width="100%" borderColorLight=#f0f0f0 border=1>
<TBODY>
<TR>
<TD>-</TD>
<TD>rw</TD>
<TD>rw-</TD>
<TD>r--</TD>
<TD>1</TD>
<TD>hope</TD>
<TD>123</TD>
<TD>Feb 03 15:36</TD>
<TD>file.txt</TD></TR>
<TR>
<TD>File</TD>
<TD>owner</TD>
<TD>group</TD>
<TD>everyone</TD>
<TD>links</TD>
<TD>n57</TD>
<TD>size</TD>
<TD>mod date</TD>
<TD>file name</TD></TR></TBODY></TABLE>
<P>The letters to the left identify the access privileges of this file
(file.txt). There are three groupings of three letters, each relating to
the access privileges available for this file. There are three types of
privilege: <B>r</B> - read, <B>w</B> - write (also allows delete),
<B>x</B> - execute (may be a program that the system can run). We see that
the above file may be read and written by the owner and the group but only
read by everyone else.</P>
<P>The following commands relate to ownership of files and
directories.</P>
<UL type=circle>
<LI><FONT face="Times New Roman"><B>chmod</B>: change permission bits,
to change who may/may not read/write to a given file or
directory.</FONT>
<LI><FONT face="Times New Roman" color=#c0c0c0><B>chown</B>: change file
'owner'; on a Unix file system each file is "owned" by a specific
user. </FONT>
<LI><FONT face="Times New Roman"><FONT color=#c0c0c0><B>chgrp</B>:
change file 'group'; users belong to 'groups'. This changes the 'group'
associated with a file. (Not of interest for now)</FONT><BR><FONT
color=#c0c0c0>You can specify multiple commands to execute at the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -