1 / 27

Introduction to Linux ( II )

Introduction to Linux ( II ). Sidney Fong 11 th Feb 2006. Rough Outline. Prerequisites: Knowledge of basic Computer / Operating System concepts Preferably some previous experience of Linux Training is divided into Two Parts: Part I - Introduction of the background of Linux

rio
Download Presentation

Introduction to Linux ( II )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Linux (II) Sidney Fong 11th Feb 2006

  2. Rough Outline • Prerequisites: • Knowledge of basic Computer / Operating System concepts • Preferably some previous experience of Linux • Training is divided into Two Parts: • Part I - Introduction of the background of Linux • Part II – Quick review of basic Linux commands • Part III – Vim • Part IV – Some miscellaneous topics (if time allows)

  3. Introduction to Linux (II) Part I – Some Background of Linux

  4. What is “Linux”? • Operating system? • … What is an operating system? • Wikipedia: “the system software responsible for the direct control and management of hardware and basic system operations”. • The kernel? • The basic interface (eg. command line, graphical interface)? • The commands? The tools? • Text editors? Compilers? • Web Browser? • … Everything?

  5. Operating System (cont’d) • In general, there is one narrow usage and a broader usage • Narrow usage: Only the parts that deal directly with the hardware, and very low level features (i.e. the kernel) • Broader usage: Also includes system software. What is “system software” depends on the nature of the system.b

  6. Graphical Illustration Hardware Kernel User space programs Daemons X Server Shell X Client

  7. What is Linux? • There are also two usages of the term “Linux”, corresponding roughly to the narrow/broad usage of the term “Operating System”. • The narrow definition: simply the kernel • The broader definition: includes basically everything available in the system

  8. A Typical Linux System • Linux Kernel • User space programs (many are GNU software) • Shell (command line): bash • Utilities: ls, cp, mv, rm, cat, grep, ... • Compiler: gcc • … and more … • X Window System (for desktops/workstations) • Various daemons (a.k.a. services) • Eg.: syslogd, httpd, cron, inetd

  9. Richard Stallman founded the GNU project in the 1980’s Linus Torvalds began writing a kernel in the early 1990’s => GNU/Linux, commonly referred to as “Linux”. (For more details, see for yourself on the web) A bit of History

  10. Open Source / Free • Open Source – Source code is available to everybody • “Free” – Source code is available to everybody, and everybody can re-distribute the source code • “Copyleft” – Source code is available to everybody, and if you want to distribute the program, you must also distribute the source code.

  11. Linux Distributions • Once upon a time, there were softwares • The softwares were scattered in different sites, and they were distributed by source code • If people wanted to use them, they have to download them from different sites, compile them, and install them • See how many packages you have in your system! (dpkg -l) • Also, consider the difficulty of installing software onto a new computer (with no operating system pre-installed) • Conclusion: Installation of software is a very complicated process. • (Refer to the LFS “Distribution” if you want to get a feel of this)

  12. In the beginning, people did those complicated and tedious work themselves. Later, some of them released their work of collecting the software to the public. These are called “distributions”. Typically, a modern distribution handles the following: Installation of the OS Software Packaging (compiled software instead of source) Install / Upgrade / Removing packages Sensible default configurations You may have heard of these names: Redhat / Fedora Mandrake Debian Slackware Gentoo Linux Distributions (cont’d)

  13. Introduction to Linux (II) Part II – Basic Linux Commands (Quick Review)

  14. Login Screen “Message of the day” Usually contains important notices Username Hostname Current directory Hint: You may press <Ctrl+Alt+F1> to <Ctrl+Alt+F6> for multiple terminals if you are using Linux on the local machine (instead of over network) Why is the username and hostname displayed in the command prompt?

  15. Getting Help • man pages Purpose of command Different usages Hint: Press ‘q’ to quit Detailed description of command and its options

  16. More on Man Pages • There are different sections of man pages • Section 1: commands • Section 2: system calls • Section 3: C library calls • Section 4: special files (in /dev) • Section 5: (config) file formats • Section 6: “games” • Section 7: Misc • Section 8: System administration commands • If there are conflicts in names, the section of lower value is displayed. For a specific section: • man <section> <page> • Note that you may find section 3 very useful as a reference to standard C functions (eg. printf, fopen, string functions, etc)

  17. The Basics • File system: • cd, ls, rm, cp, mv, mkdir, rmdir • Piping • cat input.txt | ./program1 | diff - answer1.txt • IO Redirection • sort –n > sorted.txt < numbers.txt • ls >> logs.txt • Process management • ps, kill

  18. Useful Commands in Competitions • bc – Arbitrary precision calculator • sort – Sort lines of text files (note the “-n” option) • ps – list running processes on the machine • kill – Sends a signal to running programs (terminates it by default) • date – Print system date/time • time – reports execution time of a command • diff – compares files • head, tail – prints the first/last N lines of the input • wc – word count (also counts characters and lines) • more – pager (allows you to scroll the input for easy viewing) • less – better version of more • grep – print lines matching a pattern • find – search for files • factor – factorize numbers • tsort – perform topological sort • seq – print a sequence of numbers • file – determine file type (sometimes displays other useful information) • tar – Archive files (“glue” multiple files into one, and vice versa)

  19. Some shell scripting • For loop: • for ((i=0;i<10;i++)); do echo $i; done • If statement: • if [ $ME = “dizzy” ]; then echo “I am $RANDOM years old”fi • While loop: • A=1while [ $A -ne 0 ]; do read A echo $A | factor done • Note that spacing may be significant!!

  20. Introduction to Linux (II) Part III – Vim

  21. Starting Vim • Type “vim” in shell. (some systems equate vi with vim, but not always) • Screenshot of an empty vim session

  22. Quit • Even if you don’t want to learn vi(m), you have to know how to quit: • <ESC>:q!<ENTER> • By the way, the way to exit Emacs: • Ctrl+X Ctrl+C

  23. Using Vim as “notepad” • Once started, press “i” to enter insert mode. • Use like notepad. • To save/quit, <ESC> and :w / :q • Note: set nocp, set bs=2

  24. Different modes • Vi has two (three?) different modes: • Insert mode – in which you type the text • Command mode – in which you issue commands to the editor • (ex mode) – more complex commands • Vim starts in command mode by default • Various commands to enter insert mode • Esc to exit from insert mode back to command mode • During command mode, the “:” character indicates an ex command. For example, ‘:q!’ is an ex command.

  25. Basic movements • Vim is fast when it comes to movement (of cursor). One of the reasons is that you do not have to move your hand to the arrow keys to move. (Almost) Everything can be done by [a-zA-Z0-9] • h,j,k,l : left, down, up, right • If you want to learn vi, you must learn these.

  26. Vim commands • (Refer to command list)

  27. vimrc • vimrc – start up commands (in ex) for Vim • Utilize it to personalize your settings. But remember not to be over reliant on these because you may not have the time to set up a vimrc in competition environments (except simple ones) • Simple Example: • set nocp #do not use old vi behaviorset bs=2 # sane backspace setting (see :help bs)set ruler # “status bar”set ai # auto indent • Combine with :map command for easy compile/run keys

More Related