Quick study computer LINUX 600dpi

6 635 1
Quick study computer LINUX 600dpi

Đang tải... (xem toàn văn)

Thông tin tài liệu

Li nux has its roots in UN IX A brie f history UNIX is, therefo re, cruc ia l in understanding it UNIX Came from Bell Labs in the late 1960s and I 970s It was des igned to a ll ow the staff to share infor ma­ tion, store and manipu late data , and research They all owed various universiti es to obtain the source code fo r free , for research into operating systems As the un ivcrsiti es worked on the operating system vari ous ve rs io ns dcvelo ped that \Veren't compatibl e with each other, but the comm crcial viability as an operati ng systcm was beginni ng to be realized Bell Labs stopped sharin g the source code and the versio ns of UN IX began to be more ti ghtly con­ trolled by the orga ni zati o ns that had control over the vanous versIons Enter Minix Minix was based on the Bell Labs vari ant and was the f irst real vers ion of U IX to be avail able on the IBM PC plat form It was created by Andrew Tanen baum, a professor in I iolland He managed to fit th e OS into an 8086 class Pc, and then made the so urcc code avai lable for his classes and others Li nus Torvalds bega n with M inix and started tin ker­ ing with it at the University of He lsin ki He decided to create his own vcrsio n o f UN IX that woul d be free ly avai lable, have more capabili ties than M inix and have no licens ing restrictions for those who wanted to con­ tribute to th e project , other than keepi ng the product in the public domain O ne of the first versions (0.02 ) of what was to become Linux was an no un ced on the comp os.minix ncwsgroup on October 5th, 199 By April 1992 , the new OS had enough of a foll owing to get its own newsgrollp, comp os.linux TCP/ Ip support was added in August 1992 and things continued to be rapidly updated and upgraded towards the goal of a 1.0 re lease (before th is , Lin ux was at O.xx releases ), whi ch occurred on March 14th 1994 Starting in March of 1995 , two ver­ sions of Linux were available, 1.2.x and 1.3.x The num­ bering standard is as follows: major or Kerne l vers ion (cu rrently 2), m inor version or kerne l patc h level (for example, ), and a sublevel (for example, 14) Th e kernel patch level is the most interesti ng feature of the number­ ing scheme : Even numbers are stable vers ions of the ker­ nel Odd numbers are versions that are sti ll in deve lop­ ment and are cons idered experi menta l Hoth arc freely avail able with prod u," once aga in without the $ prepended to (he \'ariable name FINDING FILES & DIRECTORIES Files and d irectori es may be found by two di ffer­ ent methods: the fi nd and the locate commands locate T he locate command is faster a nd causes less of a stra in on th e syste m beca use it searc hes th ro ugh an index of all files stor d on th e hard drive in a f ile ca ll ed localedh Th is fil e is usually updated da ily by a cron j ob that runs th e u pdatedb co mmand Th e database may be re freshed at a ny time by ru nnin g updatcdb as well The downs ide to thi s co mma nd is that new f i les may not be in the database yet, o r the updating of the database may sumc vita l system resou rces to bring it up to date For exa mp le, scarch­ ing fo r the location o f localedh is ne us ing thc fo l­ lowing synta/< : $ locate locatedb / etc / eron d / Daily/ 50update-locatedb / e te / eron.d/lib/update-locatedb / usr/ man/ man5/1ocatedb,5.gz / var/ state/ locatedb $ Note that mo re f iles may be returned tha n ex pect­ ell depe nding o n what is be ing searc hed fo r f ind The lind command is more comprehensive allowing you to search for files with a given namc (by using the - name option ), with given permission s (by utilizing the - perm opti on), of a given si7e (with the -size option), or a certain type (via (he - type option), to name just a few options T he power o f ihi s command lies not only in its ability to locate fil es but in its ability to then act on each fil e found in so me manner (via thc -exec option) The basic forma t of the command is '"lind .ample $ gzip message $ eat message.gz -: , U 98 mes,;;qge EE,V ¢D 6:UAc.e .U66:aA6T 56:&­ $ zeat message.gz T his is a small message, $ gunzip message.gz $ eat message Thi s is a small message $ ve fo fo Ip Each of the shell s in Linux o ffe rs scripts that set up the envi ron me nt for users of that she ll They are sim ilar to autocxec bat in the DOSfWindows envi ­ ro nment Each of the files listed are for the BASil shell and arc located in each user's home d irectory (except for fetcfp rofiIe) Othe r conf igurat ion fi les may also exist Script Name Function profi le Run s a t login to set the user's environm ent, includi ng environ­ ment al variables, such as the path and comma nd prompt bashrc Run s eac h time a new bash she ll is started (which can happen multi ple times fo r a s ingle log in) fetcfprofi le Log in script fo r all users on the system to set g lobal settings $ps PID TTY $ jobs [l]+ Running Is -l-R/home > HomeDirListtxt & $ Is HomeDir LisUxt [l]+ Done Is -l/ home >HomeDirLisUxt $ This example will a long listing of the fhome directory, recursively through the subdirectories, piping the output to l-IomeDirLisUxt and the job in the background Note that as soon as the com­ mand is entered and the < Enter> key is pressed, the system returns the job number "II and the process ID of that job (in this case, 887) While the job is running, its status (along with all other running jobs) can be viewed with the jobs command If you forget the ampersand at the end of a com­ mand and find it is taking a long time to complete, you can take that process and change it from a fore­ ground to a background process by pressing That keystroke combination will sus­ pend the process To take that suspended process and make it a background process, type bg Once a task is executing in the background, it can be made a foreground task with the fg command Both fg and bg allow an opt ional job number to be speci fied as a parameter There are several important notes regarding fore­ ground and background processes, and jobs in gen­ eral, that you should be aware of, namely: A process that is in the background and needs user input will be suspended until it is brought to the foreground and supplied the necessary input Output from a background process will display on the screen as it is gcnerate(l unless output is redirected to a file When you logout, all unfinished background jobs are terminated by default TIME CMD 854 pts/l 894 pts/l $ 00:00:00 bash 00 :00:00 ps TIME CMD ? ? 0000:04 init 00:00:00 kflushd ? ? ? ? pts/O pts/ l pts/ l 00 :0000 000000 00:00:00 0000:00 000003 00:00:00 000000 00:00:00 kpiod syslogd inetd rpc.portmap X bash bash ps or $ ps-e PID TTY ? If you want to terminate a process that is not responding or that you otherwise not want to keep running, usc the kill command The synta x the kill command is kill To view the top consumers of memory and C PU time, use the top command The inf(Jrlllati oll is updated frequently, and is similar to Task Manager in Windows NT or Windows 2000 T he output will be similar to the following (many lincs have been removed to save space): To view all of the processes on a systcm, use the -e switch The output of this command is as follows (note that many of the processes have been eliminat­ ed from the output to save space): $ top 12:56pm up 1:03, users, load average : 0.53, 0.15 0.05 48 pr=esses: 46 sleeping, running, I zombie, stopped CPU states: 6% user, 0.2% system, 0.0% nice 99 0% idle Mem: 127988K av, 94092K used, 33896K free, 46576K shrd, Swap OK av, OK used, OK free JOB CONTROL In Linux , as with UNIX,jobs are normally run in the foreground The problem is, if you have a long task, it can prevent you from doing anything else for a long time You have three solutions - switch to a new virtual console, open a new terminal window in the GUI , or run tasks in the background To switch to a new virtual console, press , where Fn is a function key from F I - F8 (F7 and F8 are usually for the graphical screens) and login again Opening a new terminal window in your GUI will depend on the GUI , so it will not be discussed here The third approach is running a task in the background and is the focus of this section To run it task in the background, simply append an ampersand, " &:' to the end of the command line, as illustrated here: $ Is -1 -Rjhome > HomeDirList.txt Be [1] 887 537 596 598 778 853 854 896 $ A process is simply a program that is running It may be a program that you start as a user or a sys­ tem process, such as a daemon Each process has a numbcr, called a Process ID (PID) To view active user processes, issue the following command: 40484K buff 29228K cached PID USER PRI NI SIZE RSS SHARE STAT LIB %CPU %MEI\I TIME COM;\1AND 907 119 537 540 590 596 598 621 1052 436 324 568 800 572 540 396 892 1052 436 324 568 800 572 540 396 892 852 372 268 460 384 436 440 320 728 R 0 0 0 0 0 root root root root root root root root bin root 18 0 0 0 0 0 0 0 0 0 S SW S S S S S S S 2.9 0 0 0 0.0 0 0 0 0 0.0 0.3 0.0 0.2 0.6 0.4 :00 :04 :00 :00 0:00 0:00 0:00 000 0:00 :00 top init kflushd update syslogd klogd cardmg r ine td rp::.p::lrtmap amd The two most important columns (generally) are the % C PU and 'X,M EM , which del"ine th e pe rcentage 1" C PU time and the percentage of total memory used by that process (note that total memory is displ aycd in the header information) See the man pages for detailed information on this command COMMAND SUMMARY thi s co mmand to change th e date (a ltho ugh it w ill not update the BIOS; thi s Illu st be done with th e BIO S's se tup utility ) While there are literally hundreds of" commands available in Linux , the following arc some of the more common and important : o cal - displays a cal e ndar on the screen With no arguments, displays a calendar for the current month Optionally, a year may be specified which will display a calendar for the entire year or a month and year may be given as arguments , displaying the specified month 's calendar If specified, the month must be a number between one and 12 and must precede the year, which can be from I - 9999 o r o o cat - di splays the contents of the file to the screen Designed to display textual data only If there is more information than will fit on a screen, it simply scrolls ofT the screen To display only a screenful of information at a time, use the commands less and more, as described below o di sk space o n a ll partiti ons o r o n a spcc ified par­ tition (in I K blocks by de fault ) l3y using th e-i option , the number of free in odes (direct ory entri es) may be di splayed inst ead o du - this cOlllmand will repo rt the used di sk space for the speci ri ed directo ry (thc default is the current directory) und each of it s subdirect o­ ries The numbers give n are in I KH bl oc ks by default Using the -a option will report disk uti­ li zation informati o n o n all fil es in eac h directory as well The -c opti o n will di spl ay a g rand to tal at the end of the output o echo - this command will a llow you to print text to the screen It is otten used in shell scripts to infi.mn the user on the progress 01" the script It can also be used to put information in a fil e by piping the output to a file clear - clears the screen cp - copies files The syntax is either cp , which allows you to o copy a file to another name (for example, to back it up), or cp r adm inistrators will allow you to remove a column (field) from a fil e You specify the columns (in absolute posi­ tions or by field number) to keep; the rest are dis­ carded See also paste o df - thi s command will report the am ount o fF ee head - di splays th e first few (10 by dcl~lUlt unless changed with the - switch) lin es o f the specified filc( s ) Olien used to review e rror logs and with other file s where the most important information is at the top of the file Sec al so tail o hostname - displays the current host name (with -s), domain name (with -d) , or both (with Command Summar (continued) -I" to di splay the FQDN : Fully Qualified Domain Name) The IP addressees) may be displayed instead by using the - i option • nslookup - this tool allows you to query DN S for FQDN s For example, querying DNS with the com­ mand "nslookup www.redhat.com will return the IP addressees) for www.redhat.com • tee ­ takes output destined fo r the screen and sends it to both the screen and a specified fil e; useful to 'cc thc output of a command and to save that output for later usc as well • id - displays your user ID and group lO(s) It can show your cOcctive uscr and group ID(s) if you su to anothcr user (scc su) • paste - merges files into multiple columns in a single file See also cut • ifconfig - the interface fig command allows you to view, and optionally change, TCP/ IP-related information The information is generally set at boot and viewed afierwards Without any arguments, it will display the IP-related information for a machine, including IP address, subnetmask, and so on Used primarily by administrators • ping - allows you to send packets to a destination and, if the destination host is online and available, receive replies In this respect, it is similar to sonar By default, a packet will be sent every second until the command is stopped by pressing , unless the -c switch is specified along with the number of packets to send This is one of the most basic, and most used, diagnostic com­ mands available for testing network connectivity • telnet - allows you to access a remote system and perform commands as ir you lVere on th e rcmote system As all information (inc luding pa sswords) is sent as clear text, encryption should be consid­ ered or another application , such as SS II (secure shell), should be used to protect important data and password s • init - used when the system starts to initialize May also be used after boot to start and stop various groups of services While the levels vary from dis­ tribution to distribution , several are widely used, including: • - halt (shutdown) the system • - place the system in single-user mode (typi ­ cally done by administrators while performing maintenance) • - multi-user mode, without the GUI started (normal level for servers) • - multi-user mode, GU I started (normal level for user workstations) • - rcboO! the machine (same as level 0, with a reboot at the end) • less - the less command allows you to scroll through data, searching for values, moving up and down through the data T he less command is far more powerful than the more comm and (described below); hencc, you will often hear "leIs is more." It offers many command line options, as well as many command s once the file is displayed View the man pages for information on all of them A few of the most important commands that can be used while the file is displayed are: • or f - scroll forward one screenful • or e or j - scroll forward one linc b - scroll back one screcnful • y or,k - scroll back one line ' - search forward for pal/em • 7 - search back ward for pat/em • n - search in the same direction for pattem as the last search • N - search in the opposite direction for pattern as the last search • q or :q or ZZ - exit less and return to a com­ mand prompt • In - creatcs a link (or alias) to a file, creating two dircctory entries that point to the same file on disk Similar in purpose to a shortcut in Windows • more - the more command allows you to scroll through a file by line or screenful There are far fewer options than with less, but all of the options listed above for less work except for the following: e, j, y, k, '!, N, :q, and ZZ • mount -this command will show all of the mount­ ed devices and/or allow you to mount new devices If you want to mount a new device, you need to specify the device and the directory to which the device is to be mounted You can mount Linux/ Minix/UNIX, OS/2, DOS, and C D-ROM (ISO 9660) file systems, among others This com­ mand is only available to the root user ~ z ~ • rm - allows you to remove (delete) a file or directory You must have at least write permissions to the directo­ Iy to be able to remove any files but write permission s to the files are 110t required If you don't have write per­ mission to a file, you will be prompted whether to remove it anyway If used with the -r option and a directory name is specified, all files in that directory and all subdirectories will be deleted, as will the subdi ­ rectories and the directory itsel f This is a very power­ ful command when used with the - r option, so be very careful when usin g it • rmdir - removes the specified directory or directori es, but not the contents of the directory See also rm • shutdown - shuts down the system , by taking it to run level I (sec init for more information on the diflc r­ ent levels) T he shutdown can be immediate by specify ­ ing " now," a number of minutes in thc future (by spec­ ifying +11 , where 11 is the number of minutes to wait ), or at a given time, by specifying the time in /lh : ///I11 for­ mat A message (optionally user-specified) will be sent to a ll users currently logged on to the system , telling them to logoff before the system goes down, and the Illessagc is repeated at a fa ster and faster rate as the specified time nears The system can be compl etely shutdown (vs run level I) by using the - h switch, rebooted with the - r switch, or an impending shutdown can be canceled with th e -c switch Only root can use this command • sort - allows you to sort a file, line by line Useful in sorting output, from other commands, that is displayed in an un sorted order or an order that is not des ired Often used with uniq (described in this sUlllmary) to view unique lines or words only • su - allows you to assume another user's user and group identities Most, but not all, programs act based on a user's effective user and group IDs, which mayor Illay not be the actual user ID that was originally logged in For all users other than root, a password must be specified for the given user If 110 user is spc ifiecl root is assumcd This is a great utility for administrators and programmers to see how the system or an appl ication bchaves when logged in as a normal user instead of the more powerful user that they may normally usc Thi s is also useful for allowing administrators to login as nor­ mal users, only gaining root access as needed, mini­ mizing the chances of accidentally causing maj or Sys­ iem disruptions • mv - allows you to move and rename files and directories • tac - this cOlllmand is the cOlllmand cat spelled bac k­ wards and, as the spelling would suggeSt, displays the spccified file backwards (line by lin~), starting at the end and finishing with the beginning • netstat - displays TCP/IP information for all active sockets (TCP and UDP), including the port numbers and the number of bytes waiting to be both sent and received • tail - displays the last few ( 10 by default; change the number with the -II option) lincs of a file Often used to display error and activity logs that place the most recent information at the end of the file See al so head CREDITS Author: John Hales Layout: Michael D Adam D.- - - - - - ­ = ~ • reboot - this command will close a ll files, terminate all processes, shutdown the system, then reboot it free wn~adS & at nLJ nd~re 01 titles ISBN-13: ISBN-10: qUlc uuy.com • touch - used to update the la st access and last mod­ ification date and timcs lor the files specified to the current date and time Useful with comm ands th at act based on th e informati on in the last-accessed or last­ modified field s, such as backup applicati ons • traceroute - shows t he route a packet takcs from it s place of origin to its destination host via each router Useful in determining the best rout e to a given destinati on, as wcll as giv ing informati on on cl ogged routes (as it reports th e tim e spent at eac h router) • unmount - thi s is the oppos ite o f the mOll nt com­ mand and will , there fore, unmoun t a previously mounted fil esystem • uniq - removes dupli cate adjacl'l/ t lines fro m a file, sending the output to the screc n or a fiic Us ually used with sort to en sure the data is presorted The -c switch will print eac h lin c and di splay the number of times it occ urs • uptime - d isplays th e current time, the Ic ngth of time the uscr has bcen logged in , how many users are currently logged in, and information on system utiliza­ tion over the last 1-,5-, and 15- minute intcnals • wc - di splays a cha racter, word, and Iinc count fo r the speei ficd fil e(s) or standard inp ut O ft en, the output o f other co mm ands is piped in to we to get this infor­ mation in combi na tion with those commands • who - by defa ul t, thi s com ma nd with no options will di splay a li st of a ll o f the users cu rrently logged in , where they logged in fro m, and the ti me th ey logged in When used w ith the - i option, it will also di splay th e amo unt of id le time, " hich can be use ful in dete rmining who is us ing the systcm without logging 00' when fini shed One of the most uscful swit ches is - h, whi ch will acid co lum n head­ ings to the output • whoami - di splays the current use r's user name T his information can also he obtained by usc of option s assoc iated with the id and who cOlllmand s man 8r info Help is available for almost all commands, displaying all com­ mand options listing related commands, and so on The main source of help is the man pages The syntax is simply "man ." For example, to view the man pages on grep type "man grep:' To, iew a list of available commands with a brief description of each, type "man -k keyword:' Many commands now have more extensive documentation available on the info pages To view the info pages simply type "info

Ngày đăng: 30/01/2017, 09:52

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan