From DOS to Linux - Quick! By Guido Gonzato January 22, 1996 Version 1.0 Preface This mini-HOWTO is dedicated to all the (soon to be former?) DOS users who have just taken the plunge and decided to switch to Linux. When I first installed Linux on my PC (it was the MINILINUX distribution; rather incomplete, but enough to whet your appetite) I wanted to be up and running straight away - I suppose it's what just everyone wants. You may know that DOS can be viewed as a lame and kinky subset of Unix. Well: being a seasoned DOS user, I realised that I already knew a few things that were similar among the two os's: the concepts of filesystem, directories, environment variables, running programs and .BAT files, and a few other things. The purpose of this document is to help the reader translate his or her knowledge of DOS into the Linux environment, so as to be productive asap. Just a few pages to read in bed when your partner is not there, or, better, to keep on hand next to your PC. I'd like to stress that this is *not* an introductory course on Linux: I strongly recommend that the beginner get a copy of Matt Welsh's "Linux Installation and Getting Started", available on sunsite.unc.edu and its mirrors in directory /pub/Linux/docs/LDP; it's really well written and easy to understand. Scores of HOWTO and FAQ documents are also available. This work is there not as an alternative to those docs, but simply because there must be many freaks out there who, like me, long to use Linux after reading 15 pages instead of 150+. As for you, diehard Mac & Windows users... well, it must be really hard for you to get used to the joy of command-driven operating systems. I'm afraid this document is of very little use to you. Please get Matt's book. Introduction You installed Linux on the PC. You gave yourself an account following the installation instructions (if this is not the case, see 6.1) and Linux is running. Somebody told you that all the programs you needed were there, and all you have to do is login and go. You've just entered your name and password, and now you are looking at the screen thinking: "Well, now what?" Now, don't despair. You're almost ready to do the same things you used to do with DOS, and many more. If you were running DOS instead of Linux, you would be doing some of the following tasks: 1. executing programs and creating, copying, viewing, deleting, renaming files; 2. CDing, MDing, RDing, and DIRring your directories; 3. formatting floppies and copying files from/to them; 4. mending your AUTOEXEC.BAT and CONFIG.SYS; 5. writing your own .BAT files and/or QBASIC programs; 6. the remaining 1%. You'll be glad to know that these tasks can be accomplished under Linux in a fashion similar to DOS. Under DOS, the average user uses very few of the 100+ commands available: the same, up to a point, can be said for Linux. Incidentally, if you don't know the DOS commands for the tasks in the list, drop out now: I won't be explaining what such things as a directory or the PATH variable are. A few things to point out before going on: 1) Unlike DOS, Linux has built-in security mechanisms. The normal user doesn't really own the system; at login time, only the user whose login name is "root" (this guy's the system administrator) has the power. Files and directories have permissions associated to them, and therefore some cannot be accessed by the normal user. DOS, on the other hand, will let you wipe out the entire contents of your hard disk; 2) once you have finished working, you *must not* switch off your PC! Instead, you must follow the correct shutdown procedure (press CTRL-ALT-DEL, wait for the system to fix its innards and tell you everything is OK, then switch off the PC). Anyway, Linux is such a reliable os that it is *extremely* unlikely that an ill-behaved application will ever hang your machine - you'll never need to reset. 3) you are strongly encouraged to experiment, play, try by yourself: it surely won't hurt. You can get some help typing at the prompt ($ is the standard prompt, # is the prompt for root): $ help (pretty logical), or get info about a command typing $ man which will invoke the manual page associated to . 4) conventions: as usual, <...> means something that must be specified, while [...] something optional. Example: $ tar -tf [> redir_file] file.tar must be indicated, but redirection to redir_file is optional. You are now ready to refer to the following chapters. Chapter 1: Working with Files 1.1. Files: Preliminary Notions Linux has a file system - meaning by that "the structure of directories and files in them" - very similar to that of DOS. Files have filenames that obey special rules, are stored in directories, some are executable, and among these most have command switches. Moreover, you can use wildcard characters, redirection, and piping. There are only a few minor differences. - First difference: under DOS, file names are in the so-called 8.3 form; e.g. NOTENOUG.TXT. Under Linux we can do better. If you installed Linux using a filesystem (you needn't know what it means now) like ext2 or umsdos, you can use longer filenames, and with more than one dot in them: for example, This_is.a.VERY_long.filename . Please note that I used both upper case and lower case characters. In fact... - Second difference: upper case and lower case characters are different. Therefore, FILENAME.tar.gz and filename.tar.gz are two different files. The same holds true for commands: if you issue the command ls (the same as DIR under DOS) you'll get a list of files in your directory, but if you enter LS you'll get an error message. - Third difference: if you start a filename with a period, the file will be considered as hidden. Example: the file .I.am.a.hidden.file won't show up after an ls command. - Fourth difference: there are no compulsory exensions like .COM and .EXE for programs, or .BAT for batch files. Executable files are marked by a star * at the end of their name when you issue the ls -F command. For example: $ ls -F letter_to_Joe Cindy.jpg cjpg* I_am_a_dir/ my_1st_script* The files cjpg and my_1st_script are executable - "programs". Under DOS, files ending in .BAK represent backup files; under Linux, such files are those ending with ~. - Fifth difference: DOS program switches are obtained with /switch, while under Linux with -switch. Example: dir /s becomes ls -R. Note that many DOS programs, like PKZIP or ARJ, use UNIX-style switches. 1.2. Files: Translating Commands from DOS to Linux On the left, the DOS commands; on the right, their Linux counterpart. COPY: cp DEL: rm REN: mv TYPE: more, less, cat Redirection and plumbing operators: < > >> | Wildcards: * ? nul /dev/null prn, lst /dev/lp0 - EXAMPLES - DOS Linux C:\GUIDO>copy joe.txt joe.doc $ cp joe.txt joe.doc C:\GUIDO>copy *.* total $ cp * total C:\GUIDO>copy fractals.doc prn $ cp fractals.doc /dev/lp0 C:\GUIDO>del temp $ rm temp C:\GUIDO>del *.bak $ rm *~ C:\GUIDO>ren *.txt *.asc $ mv *.txt *.asc C:\GUIDO>ren edit??.bak edit??.c $ mv edit??.bak edit??.c C:\GUIDO>type letter.txt $ more letter.txt C:\GUIDO>type letter.txt $ less letter.txt C:\GUIDO>type letter.txt > nul $ cat letter.txt > /dev/null n/a $ more *.txt *.asc n/a $ cat chapter*.txt Notes: 1) * is smarter under Linux: - * matches all files (*.* matches only those ending with . plus other characters); - p*r matches both peter and piper; - *n* matches both friend and Linux; 2) when using more, press to read through the file, 'q' or CTRL-C to exit; 3) there is no UNDELETE, so think twice before deleting anything; 4) in addition to DOS's < > >>, Linux has 2> to redirect error messages (stderr); 6) Linux has another wildcard: the []. Use: - [abc]* matches files starting with a, b, c; - [I-N]* matches files starting with I, J, K, L, M, N. 1.3. Executing Programs: Multitasking and Sessions To run a program, type in its name as you would do under DOS. If the directory (chapter 2) where the program is stored is included in the PATH (chapter 4), the program will start. Exception: unlike DOS, under Linux a program located in the current directory won't run unless the directory is included in the PATH. This is what the typical command line looks like: $ command -s1 -s2 ... -sn par1 par2 ... parn output where -s1, ... , -sn are the program switches, par1, ... , parn are the program parameters. It is possible to issue several commands on the command line: $ command1 ; command2 ; ... ; commandn That's all about running programs, but it's easy to go a step beyond. One of the main reasons for using Linux is that it is a multitasking OS - it can run several programs (from now on, processes) at the same time. You can launch processes in background and continue working straight away. Moreover, Linux lets you have several sessions: it's like having many computers to work on at once! - To switch to session 1..8: $ ALT + F1 ... ALT + F8. - To start a new session without leaving the current one: $ su - Example: $ su - root This is useful, for one, when you need to mount a disk (chapter 3): only root can do that. - To end a session: $ exit - To launch a process in foreground: $ progname [-switches] [parameters] [output] - To launch a process in background you add the character & at the end of the line: $ progname [-switches] [parameters] [output] & - To see how many processes there are: $ ps This will output a list of processes currently running. Each one is identified by a PID, a number. - To kill a process: $ kill You may need to kill a process when you don't know how to exit from it the right way... In addition to this, the shell (the equivalent of COMMAND.COM) allows you to stop or temporarily suspend a process, send a process to background, and bring a process from background to foreground. In this context, processes are called jobs. - To see how many jobs there are: $ jobs here jobs are identified by the numbers the shell gives them, not by their PID. - To stop a process running in foreground: $ CTRL-C (it doesn't always work) - To suspend a process running in foreground: $ CTRL-Z - To send a suspended process into background: $ bg - To bring a process to foreground: $ fg - Again, to kill a process: $ kill % where may be 1, 2, 3, ... Using these commands you can format a disk, zip a bunch of files, compile a program, and unzip an archive all at the same time, and still have the prompt at your disposal. Try this with DOS! And try with Windows, just to see the difference in performance. Chapter 2: Using Directories 2.1. Directories: Preliminary Notions We have seen the differences between files under DOS and Linux. As for directories, under DOS the root directory is \, under Linux / is. Similarly, nested directories are separated by \ under DOS, by / under Linux. Example of file paths: DOS: \PROGRAMS\C++\SOURCES\HELLO.CPP Linux: /home/guido/papers/geology/mid_eocene.tex As usual, .. is the parent directory, . is the current directory. Remember that the system won't let you cd, rd, or md everywhere you want. Every user starts from his or her own directory called home, given by the system administrator; for instance, on my PC my home dir is /home/guido. The character ~ is a shortcut for the name of your home directory. 2.2. Translating Commands from DOS to Linux DIR: ls, find CD: cd, pwd MD: mkdir RD: rmdir - EXAMPLES - DOS Linux C:\GUIDO>dir $ ls C:\GUIDO>dir file.txt $ ls file.txt C:\GUIDO>dir *.cls *.c $ ls *.cls *.c C:\GUIDO>dir/p $ ls | more C:\GUIDO>dir \*.tmp /s $ find / -name "*.tmp" -print C:\GUIDO>cd $ pwd n/a - see note $ cd n/a - see note $ cd ~ n/a - see note $ cd ~/temp C:\GUIDO>cd \other $ cd /other C:\GUIDO>cd ..\temp\trash $ cd ../temp/trash C:\GUIDO>md newprogs $ mkdir newprogs C:\GUIDO>md \progs\turbo $ mkdir /progs/turbo C:\GUIDO>rd newprogs $ rmdir newprogs C:\GUIDO>rd \progs\turbo $ rmdir /progs/turbo Note: the commands cd and cd ~ will take you to your home directory from wherever you are; the command cd ~/tmp will take you to /home/your_home/tmp. Got the hang of it? Chapter 3: Floppies, Hard Disks, and the Like 3.1. Using a floppy disk You have never thought about it, but the DOS command FORMAT A: does a lot more work than it seems. In fact, when you issue the command FORMAT it will: 1) physically format the disk; 2) create the A:\ directory (= create a filesystem); 3) make the disk available to the user (= mount the disk). These three steps are addressed separately under Linux. It is possible to prepare and use floppies in MS-DOS format, though other formats are available; the most common is perhaps ext2. Here is how to prepare a disk (you'll need to start a session as root): - To format a standard 1,44 Meg floppy disk (A:): # fdformat /dev/fd0H1440 - To create a filesystem: # mkfs -t ext2 -c /dev/fd0H1440 or # mformat a: to create an MS-DOS filesystem. Beore using the disk, you must mount it. - To mount the disk: # mount -t ext2 /dev/fd0 /mnt or # mount -t msdos /dev/fd0 /mnt Now you can address the files in the floppy. When you've finished, before extracting the disk you must unmount it. - To unmount the disk: # umount /mnt Now you can extract the disk. Obviously, you have to fdformat and mkfs only unformatted disks, not previously used ones. If you want to use drive B:, refer to fd1H1440 and fd1 instead of fd0H1440 and fd0 in the examples above. All you used to do with A: or B: is now done using /mnt instead. Examples: DOS Linux C:\GUIDO>dir a: $ ls /mnt C:\GUIDO>copy a:*.* \docs\temp $ cp /mnt/* /docs/temp C:\GUIDO>copy *.zip a:\zip $ cp *.zip /mnt/zip C:\GUIDO>a: $ cd /mnt A:\> /mnt$ Needless to say, what holds for floppies holds for whatever device you can think of; for instance, you may want to mount another hard disk or a CD-ROM drive. Have a look at the list of devices in directory /dev. Chapter 4: Tayloring the System 4.1. Initialization Files Two important files under DOS are AUTOEXEC.BAT and CONFIG.SYS, which are used at boot time to initialise the system, set some environment variables like PATH and FILES, and possibly launch a program or batch file. Under Linux there are several initialisation files, some of which you had better not tamper with until you know exactly what you are doing. I'll tell you what the most important are, anyway: FILES NOTES /etc/inittab don't touch for now! /etc/rc.d/* ditto If all you need is setting the PATH and other environment variables used by some programs (TeX, for one), or you want to change the login messages or automatically launch a program after the login, have a look at the following files: FILES NOTES /etc/issue sets pre-login message /etc/motd sets post-login message /etc/profile sets PATH and other variables, etc. /home/your_home/.profile does what you want If the latter file exists (note that it is a hidden file), it will be read after the login and the commands in it will be executed. Example - look at this .profile: # I am a comment echo Environment: printenv | more # equivalent of command SET under DOS alias d='ls -l' # easy to understand what an alias is alias up='cd ..' echo I remind you that the path is $PATH echo Have a good day, $LOGNAME PATH and LOGNAME, you guessed right, are environment variables. Chapter 5: .BAT Files on Steroids 5.1. Writing Scripts If you used .BAT files to create shortcuts of long command lines (I did a lot), this goal can be attained by inserting appropriate alias lines (see example above) in profile or .profile. But if your .BATs were more complicated, then you'll love the scripting language made available by the shell: it's as powerful as Qbasic, if not more. It has variables, structures like while, for, case, if... then... else, and lots of other features. To write a script - the equivalent of a .BAT file under DOS - all you have to do is write a standard ASCII file containing the instructions, save it, then make it an executable file with the command $ chgmod u+x To execute it, type in its name. Beware: if the directory you're in is not included in the path, the script won't start. Escamotage: being your script file, type ./. A word of warning. The system editor is called vi, it's rather difficult to use, and I'm sure you'll find it horrible. I'm not going to explain how to use it, because I myself can't find my way around in it yet. You had better get hold of another editor like joe or emacs. Writing scripts under Linux is such a vast subject it would require a book by itself, and I will not delve into the subject any further. I'll just give you a few (hopefully) useful examples from which you can extract some basic rules. EXAMPLE 1: first_script #!/bin/sh # I am a comment # don't change the first line - it's got to be there echo "My name is "$0 echo "You gave me the following "$#" parameters: "$* echo "First parameter is "$1 echo "Have you grasped the trick?" EXAMPLE 2: 2exe #!/bin/sh echo "making "$1" executable... " chmod u+x $1 EXAMPLE 3: backup #!/bin/sh echo "Copying files in ~/bak ... " for name in $* do cp ${name} ~/bak done EXAMPLE 4: fmta #!/bin/sh echo "I remind you that only root can format disks" fdformat /dev/fd0H1440 & mkfs -t ext2 -c /dev/fd0H1440 & echo "disk formatted." EXAMPLE 5: a #!/bin/sh echo "I remind you that only root can mount disks" mount -t msdos /dev/fd0 /mnt echo "don't forget to umount when you've done." Chapter 6: The Remaining 1% 6.1. Unroot Yourself It is generally a bad idea to login as root to do everyday work; such account should be used for system administration only. To give yourself a new account, login as root and issue the command # adduser entering then the information the system will ask you. (Enter to the questions you don't understand; default values will be used.) 6.2. Making Virtual Memory Although Linux runs with only 2 megs of RAM, the more you have, the more you can do. X Window System won't run unless you have at least 8 megs. To create an additional 8 megs of virtual memory: # dd if=/dev/zero of=/swapfile bs=1024 count=8192 # mkswap /swapfile 8192 # sync # swapon /swapfile Adding the last line in the file /etc/rc.d/rc.local will make the swapfile available the next time you boot. 6.3. Backscrolling You can still read what scrolled past by pressing SHIFT + PAG UP (the grey key). This allows you to backscroll a few pages, depending on how much memory you have. Moreover, if you issue the command $ script [script_file] everything that appears on screen until you issue the command exit will be copied to the file script_file, which you can examine later on. 6.4. Using tar & gzip Under Unix there are some widely used applications to archive and compress files. The utility tar is used to make archives - it's like PKZIP but doesn't compress, it only archives. To make a new archive: $ tar -cvf file [file...] To extract files from an archive: $ tar -xpvf [file...] To list the contents of an archive: $ tar -tf | more You can compress files using compress or, better, gzip: $ compress or: $ gzip that creates a compressed file with extension .Z (compress) or .gz (gzip). Note that compress and gzip can compress only one file at a time. To decompress, use $ compress -d or $ gzip -d Consult the man pages for more options. Files with extension .tar.gz or .tgz (archived with tar, then compressed with gzip) are as common in the Unix world as .ZIP files are under DOS. The arj, zip and unzip (PK??ZIP compatible) utilities are also available. 6.5. Installing Applications Most Linux applications are distributed as .tar.gz archives, specifically prepared so that they can be decompressed from / typing the following command: $ gzip -dc | tar xvf - The files will be decompressed in the right directory, which will be created on the fly. Great, isn't it? Users of the Slackware distribution (and perhaps other distributions - I don't know) have a user-friendly SETUP program, though. Others packages have their own installation instructions; read the documentation. Besides, under Linux some packages are distributed as C or C++ source files, which you'll have to compile to create the binaries. In most cases, all you have to do is issue # make Obviously, you'll need the GCC compiler, included in most distributions. 6.6. The DOS Emulator If you occasionally need to run a DOS application and resetting annoys you, download the DOS emulator from TSX-11.mit.edu:/pub/linux/ALPHA/dosemu. It can run several (not all) DOS programs. It's a chance to try and install a package as seen in 6.5. 6.7. Resetting the Screen If you happen to more or cat a binary file, your screen may end up full of garbage. To fix things, blind type $ reset or this sequence of characters: echo CTRL-V ESC c RETURN. The End, for Now Congratulations! You have now grasped a little bit of Unix and are ready to start working. Remember that your knowledge of the system is still positively limited, and that you are expected to get more info about Linux to use it comfortably. But if all you had to do was get a bunch of applications and start working with them, I bet that what I included in this document is enough: by now I know little more, yet I manage to work with Linux every day! I'm sure you'll enjoy using Linux and will go on studying and learning more about it - everybody does. I bet, too, that you'll never go back to DOS! I hope I made myself understood and did a good service to my 3 or 4 readers. Disclaimer "From DOS to Linux - Quick!" was written by Guido Gonzato, , January 1996. Many thanks to Matt Welsh, the author of "Linux Installation and Getting Started", to Ian Jackson, the author of "Linux frequently asked questions with answers", to Giuseppe Zanetti, the author of "Linux - Il sistema operativo FREE SOFTWARE per personal computer 386/486", and especially to Linus Torvalds and GNU who gave us Linux. This document is provided "as is". I put great effort into writing it as accurately as I could, but you use the information contained in it at your own risk. In no event shall I be liable for any damages resulting from the use of this work. This document can be freely distributed as long as: - it is distributed in its entirety, including this disclaimer and permission notice; - no money is charged for it; - it is not modified in any way without my permission. Translations, prints, re-editings, or extractions from this document must be approved by me before being distributed. I assert the right to be identified as the author of this work, and claim the moral rights of paternity and integrity, in accordance with the Copyright, Designs and Patents Act, 1988. For any requests, suggestions, flames etc. feel free to contact me. If you don't have e-mail access, my snail-mail address is: Guido Gonzato - Via Monte Ortigara 19/a 37127 Verona - Italy Enjoy, Guido =8-)