📄 linux-commands.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"><HTML><HEAD><TITLE>Josh's Linux Guide - Linux Commands</TITLE> <META NAME="Description" CONTENT="A brief summary of Linux/Unix commands."></HEAD><LINK REL="stylesheet" TYPE="text/css" HREF="default.css"><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#7F007F"><H2><A NAME="0">Linux Commands</A></H2><FONT SIZE="-1"><B>Created: October 28, 1998</B></FONT><BR><FONT SIZE="-1"><B>Last updated: June 9, 1999</B></FONT><BR><FONT SIZE="-1"><B>Development stage: Beta</B></FONT><BR><!-- Document upgraded to Beta stage ~ Wed Jun 9 20:17:58 PDT 1999 --><P>These commands will work with most (if not all) distributions of Linuxas well as most (?) implementations of Unix. They're the commands thateverybody knows. To be able to survive in Linux, you should know these.There aren't always handy-dandy tools for X that shield you, especially ifyou're managing your own system, stuff often goes wrong and you're forcedto work with the bare minimum.</P><P>I hope I didn't scare you.</P><H3><A NAME="1">Index</A></H3><OL><LI><A HREF="#Navigation">Navigation</A> - how to get around</LI> <UL> <LI><A HREF="#cd">cd</A> - changing directories</LI> <LI><A HREF="#ls">ls</A> - listing files</LI> <LI><A HREF="#pwd">pwd</A> - knowing where you are</LI> </UL><LI><A HREF="#FileManagement">File Management</A> - who needs a graphical file manager?</LI> <UL> <LI><A HREF="#cp">cp</A> - copying files</LI> <LI><A HREF="#ln">ln</A> - creating symbolic links</LI> <LI><A HREF="#mv">mv</A> - moving and renaming files</LI> <LI><A HREF="#rm">rm</A> - removing files</LI> </UL><LI><A HREF="#Editing">Editing</A> - using text editors for those nasty configuration files</LI> <UL> <LI><A HREF="#emacs">emacs</A> - another widely used text editor</LI> <LI><A HREF="#pico">pico</A> - for wussies like myself</LI> <LI><A HREF="#vim">vim</A> - an improved version of the standard Unix text editor</LI> </UL><LI><A HREF="#MonitoringYourSystem">Monitoring Your System</A> - to satisfy your insatiable curiosity</LI> <UL> <LI><A HREF="#tail">tail</A> - follow a file as it grows</LI> <LI><A HREF="#top">top</A> - a program to see how your memory and CPU are holding up</LI> <LI><A HREF="#w">w</A> - look at who's logged on</LI> </UL><LI><A HREF="#ShuttingDownAndRebooting">Shutting Down and Rebooting</A> - you better know this, though you may not use it a lot</LI><LI><A HREF="#books">Related Books</A> - books to consider for further information</LI></OL><A NAME="Navigation"></A><H3><A NAME="2">Navigation</A></H3><P>Navigating around the files and directories of your hard drive could bea dreaded task for you, but it is necessary knowledge. If you were a userof command prompt interfaces such as MS-DOS, you'll have little troubleadjusting. You'll only need to learn a few new commands. If you're used tonavigating using a graphical file manager, I don't know how it'll be like,but some concepts might require a little more clarification. Or maybeit'll be easier for you. Who knows? Everyone is different.</P><A NAME="cd"></A><H4><A NAME="3">cd</A></H4><P>As you might already have guessed, the <B>cd</B> command changesdirectories. It's a very common navigation command that you'll end upusing, just like you might have done in MS-DOS.</P><P>You must put a space between <B>cd</B> and the ".." or elseit won't work; Linux doesn't see the two dots as an extension to the cdcommand, but rather a different command altogether. It'll come to makesense if it doesn't already.</P><A NAME="ls"></A><H4><A NAME="4">ls</A></H4><P>The <B>ls</B> letters stand for <B>l</B>i<B>s</B>t. It basically worksthe same way as the <B>dir</B> command in DOS. Only being a Unixcommand, you can do more with it. :-)</P><P>Typing <B><TT>ls</TT></B> will give you a listing of all the files inthe current directory. If you're new to Linux, chances are that thedirectories you are commonly in will be empty, and after the <B>ls</B>command is run, you aren't given any information and will just be returnedto the command prompt (the shell).</P><P>There are "hidden" files in Linux, too. Their file namesstart with a dot, and doing a normal <B>ls</B> won't show them in adirectory. Many configuration files start with a dot on their file namesbecause they would only get in the way of users who would like to see morecommonly used items. To view hidden files, use the <B>-a</B> flag with the<B>ls</B> command, i.e. <B><TT>ls -a</TT></B>.</P><P>To view more information about the files in a directory, use the<B>-l</B> flag with <B>ls</B>. It will show the <AHREF="linux-chmod.html">file permissions</A> as well as the file size,which are probably what are the most useful things to know aboutfiles.</P><P>You might occasionally want to have a listing of all thesubdirectories, also. A simple <B>-R</B> flag will do, so you could lookupon <B><TT>ls -R</TT></B> as a <I>rough</I> equivalent of the <B><TT>dir/s</TT></B> command in MS-DOS.</P><P>You can put flags together, so to view all the files in a directory,show their permissions/size, and view all the files that way through thesubdirectories, you could type <B><TT>ls -laR</TT></B>.</P><A NAME="pwd"></A><H4><A NAME="5">pwd</A></H4><P>This command simply shows what directory you're in at the moment. Itstands for "Print Working Directory". It's useful for scriptingin case you might ever want to refer to your current directory.</P><A NAME="FileManagement"></A><H3><A NAME="6">File Management</A></H3><P>A lot of people, surprisingly for me, prefer to use graphical filemanagers. Fortunately for me, I wasn't spoiled like that and used commandsin DOS. That made it a bit easier for me to make the transition to Linux.Most of the file management Linux gurus do is through the commandline, so if you learn to use the commands, you can brag that you're aguru. Well, almost.</P><A NAME="cp"></A><H4><A NAME="7">cp</A></H4><P>Copying works very much the same. The <B>cp</B> command can be usedjust like the MS-DOS <B>copy</B> command, only remember that directoriesare separated with slashes (/) instead of backslashes (\). So a basiccommand line is just <B><TT>cp filename1 filename2</TT></B>.</P><P>There are other extensions to the <B>cp</B> command. You can use the<B>-f</B> command to force it. You can use the <B>-p</B> command topreserve the <A HREF="linux-chmod.html">permissions</A> (and also who ownsthe file, but I'm not sure).</P><P>You can move an entire directory to its new destination. Let's say youwant to copy a directory (and all of its contents) from where you are tobe <TT>/home/jack/newdirectory/</TT>. You would type <TT><B>cp -rpfolddirectory /home/jack/newdirectory</B></TT>. To issue this command youwould have to be in the directory where the subdirectory"olddirectory" is actually located.</P><A NAME="ln"></A><H4><A NAME="8">ln</A></H4><P>A feature of <B>l</B>i<B>n</B>king files is available in Linux. It works by "redirecting" a file to the actual file. It's referred to as a <B>symbolic link</B>. Don't confuse this term with the linking of programs, which is when binary programs are connected with libraries that they need to load in order to run.</P><P>The most simple way that I've ever used <B>ln</B> to create symboliclinks is <B><TT>ln -s existing_file link</TT></B>. Evidently there's ahard link and a symbolic link; I've been using a symbolic link all along.You can also use the <B>-f</B> flag to force the command line to overwriteanything that might have the symbolic link's file name already.</P><P>To remove a symbolic link, simply type <B><TT>rmsymbolic_link</TT></B>. It won't remove the file that it's linked to.</P><A NAME="mv"></A><H4><A NAME="9">mv</A></H4><P>The <B>mv</B> command can be used both to move files and to renamethem. The syntax is <B><TT>mv fileone filetwo</TT></B>, where"fileone" is the original file name and "filetwo" willbe the new file name.</P><P>You can't move a directory that is located in one partition to another,unfortunately. You can copy it, though, using <B><TT>cp -rpf</TT></B>, and then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -