old-www/HOWTO/DOS-Win-to-Linux-HOWTO-4.html

446 lines
16 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE> From DOS/Windows to Linux HOWTO : Files and Programs</TITLE>
<LINK HREF="DOS-Win-to-Linux-HOWTO-5.html" REL=next>
<LINK HREF="DOS-Win-to-Linux-HOWTO-3.html" REL=previous>
<LINK HREF="DOS-Win-to-Linux-HOWTO.html#toc4" REL=contents>
</HEAD>
<BODY>
<A HREF="DOS-Win-to-Linux-HOWTO-5.html">Next</A>
<A HREF="DOS-Win-to-Linux-HOWTO-3.html">Previous</A>
<A HREF="DOS-Win-to-Linux-HOWTO.html#toc4">Contents</A>
<HR>
<H2><A NAME="s4">4. Files and Programs</A></H2>
<P>
<P>
<P>
<H2><A NAME="ss4.1">4.1 Files: Preliminary Notions</A>
</H2>
<P>
<P>Linux has a structure of directories and files very similar to that of
DOS/Win. 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:
<P>
<UL>
<LI> under DOS, file names are in the so-called 8.3 form; e.g.
<CODE>NOTENOUG.TXT</CODE>. Under Linux we can do better. If you installed Linux
using a file system like ext2 or umsdos, you can use longer filenames (up to
255 characters), and with more than one dot: for example,
<CODE>This_is.a.VERY_long.filename</CODE>. Please note that I used both upper
and lower case characters: in fact...
</LI>
<LI> upper and lower case characters in file names or commands are
different. Therefore, <CODE>FILENAME.tar.gz</CODE> and <CODE>filename.tar.gz</CODE>
are two different files. <CODE>ls</CODE> is a command, <CODE>LS</CODE> is a mistake;
</LI>
<LI> Windows users, beware when using long file names under Linux. If a
file name contains spaces (not recommended but possible), you must enclose
the file name in double quotes whenever you refer to it. For example:
<BLOCKQUOTE><CODE>
<PRE>
$ # the following command makes a directory called "My old files"
$ mkdir "My old files"
$ ls
My old files bin tmp
</PRE>
</CODE></BLOCKQUOTE>
Further, some characters shouldn't be used: some of those are
<CODE>!*$&amp;#</CODE>.
</LI>
<LI> there are no compulsory extensions like .COM and .EXE for programs,
or .BAT for batch files. Executable files are marked by an asterisk
`<CODE>*</CODE>' at the end of their name when you issue the <CODE>ls -F</CODE>
command. For example:
<BLOCKQUOTE><CODE>
<PRE>
$ ls -F
I_am_a_dir/ cindy.jpg cjpg* letter_to_Joe my_1st_script* old~
</PRE>
</CODE></BLOCKQUOTE>
The files <CODE>cjpg*</CODE> and <CODE>my_1st_script*</CODE> are executables, that
is ``programs''. Under DOS, backup files end in .BAK, while under Linux they
end with a tilde `<CODE>~</CODE>'. Further, a file whose name starts with
a dot is considered as hidden. Example: the file
<CODE>.I.am.a.hidden.file</CODE> won't show up after the <CODE>ls</CODE> command;
</LI>
<LI> DOS program switches are obtained with <CODE>/switch</CODE>, Linux
switches with <CODE>-switch</CODE> or <CODE>--switch</CODE>. Example: <CODE>dir
/s&lt;</CODE>tt> becomes <CODE>ls -R</CODE>. Note that many DOS programs, like
<CODE>PKZIP</CODE> or <CODE>ARJ</CODE>, use UNIX-style switches.
</LI>
</UL>
<P>You can now jump to Section
<A HREF="#Files">Translating Commands from DOS to Linux</A>, but if I were you I'd read on.
<P>
<P>
<H2><A NAME="ss4.2">4.2 Symbolic Links</A>
</H2>
<P>
<P>UNIX has a type of file that doesn't exist under DOS: the symbolic link.
This can be thought of as a pointer to a file or to a directory, and can be
used instead of the file or directory it points to; it's similar to Windows
shortcuts. Examples of symbolic links are <CODE>/usr/X11</CODE>, which points to
<CODE>/usr/X11R6</CODE>; <CODE>/dev/modem</CODE>, which points to either
<CODE>/dev/ttyS0</CODE> or <CODE>/dev/ttyS1</CODE>.
<P>To make a symbolic link:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ ln -s &lt;file_or_dir> &lt;linkname>
</PRE>
</CODE></BLOCKQUOTE>
<P>Example:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ ln -s /usr/doc/g77/DOC g77manual.txt
</PRE>
</CODE></BLOCKQUOTE>
<P>Now you can refer to <CODE>g77manual.txt</CODE> instead of
<CODE>/usr/doc/g77/DOC</CODE>. Links appear like this in directory listings:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ ls -F
g77manual.txt@
$ ls -l
(several things...) g77manual.txt -> /usr/doc/g77/DOC
</PRE>
</CODE></BLOCKQUOTE>
<P>
<P>
<H2><A NAME="Permissions"></A> <A NAME="ss4.3">4.3 Permissions and Ownership </A>
</H2>
<P>
<P>DOS files and directories have the following attributes: A (archive), H
(hidden), R (read-only), and S (system). Only H and R make sense under
Linux: hidden files start with a dot, and for the R attribute, read on.
<P>Under UNIX a file has ``permissions'' and an owner, who in turn belongs to a
``group''. Look at this example:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ ls -l /bin/ls
-rwxr-xr-x 1 root bin 27281 Aug 15 1995 /bin/ls*
</PRE>
</CODE></BLOCKQUOTE>
<P>The first field contains the permissions of the file <CODE>/bin/ls</CODE>, which
belongs to root, group bin. Leaving the remaining information aside,
remember that <CODE>-rwxr-xr-x</CODE> means, from left to right:
<P><CODE>-</CODE> is the file type (<CODE>-</CODE> = ordinary file, <CODE>d</CODE> =
directory, <CODE>l</CODE> = link, etc); <CODE>rwx</CODE> are the permissions for the
file owner (read, write, execute); <CODE>r-x</CODE> are the permissions for the
group of the file owner (read, execute); (I won't cover the concept of
group, you can survive without it as long as you're a beginner ;-)
<CODE>r-x</CODE> are the permissions for all other users (read, execute).
<P>The directory <CODE>/bin</CODE> has permissions, too: see Section
<A HREF="DOS-Win-to-Linux-HOWTO-5.html#Directories Permissions">Directories Permissions</A> for further
details. This is why you can't delete the file <CODE>/bin/ls</CODE> unless you
are root: you don't have the permission to do so. To change a file's
permissions, the command is:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ chmod &lt;whoXperm> &lt;file>
</PRE>
</CODE></BLOCKQUOTE>
<P>where who is <CODE>u</CODE> (user, that is owner), <CODE>g</CODE> (group),
<CODE>o</CODE> (other), X is either <CODE>+</CODE> or <CODE>-</CODE>, perm is <CODE>r</CODE>
(read), <CODE>w</CODE> (write), or <CODE>x</CODE> (execute). Common examples of
<CODE>chmod</CODE> use are the following:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ chmod +x file
</PRE>
</CODE></BLOCKQUOTE>
<P>this sets the execute permission for the file.
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ chmod go-rw file
</PRE>
</CODE></BLOCKQUOTE>
<P>this removes read and write permission for everyone but the owner.
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ chmod ugo+rwx file
</PRE>
</CODE></BLOCKQUOTE>
<P>this gives everyone read, write, and execute permission.
<P>
<BLOCKQUOTE><CODE>
<PRE>
# chmod +s file
</PRE>
</CODE></BLOCKQUOTE>
<P>this makes a so-called ``setuid'' or ``suid'' file---a file that everyone
can execute with its owner's privileges. Typically, you'll come across root
suid files; these are often important system files, like the X server.
<P>A shorter way to refer to permissions is with digits: <CODE>rwxr-xr-x</CODE> can
be expressed as 755 (every letter corresponds to a bit: <CODE>---</CODE> is 0,
<CODE>--x</CODE> is 1, <CODE>-w-</CODE> is 2, <CODE>-wx</CODE> is 3...). It looks
difficult, but with a bit of practice you'll understand the concept. root,
being the superuser, can change everyone's file permissions. RMP.
<P>
<P>
<H2><A NAME="Files"></A> <A NAME="ss4.4">4.4 Files: Translating Commands </A>
</H2>
<P>
<P>On the left, the DOS commands; on the right, their Linux counterpart.
<P>
<BLOCKQUOTE><CODE>
<PRE>
ATTRIB: chmod
COPY: cp
DEL: rm
MOVE: mv
REN: mv
TYPE: more, less, cat
</PRE>
</CODE></BLOCKQUOTE>
<P>Redirection and plumbing operators: <CODE> &lt; > >> |</CODE>
<P>Wildcards: <CODE>* ?</CODE>
<P><CODE>nul: /dev/null</CODE>
<P><CODE>prn, lpt1: /dev/lp0 or /dev/lp1; lpr</CODE>
<P>
<H3>Examples</H3>
<P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
DOS Linux
---------------------------------------------------------------------
C:\GUIDO>ATTRIB +R FILE.TXT $ chmod 400 file.txt
C:\GUIDO>COPY JOE.TXT JOE.DOC $ cp joe.txt joe.doc
C:\GUIDO>COPY *.* TOTAL $ cat * > total
C:\GUIDO>COPY FRACTALS.DOC PRN $ lpr fractals.doc
C:\GUIDO>DEL TEMP $ rm temp
C:\GUIDO>DEL *.BAK $ rm *~
C:\GUIDO>MOVE PAPER.TXT TMP\ $ mv paper.txt tmp/
C:\GUIDO>REN PAPER.TXT PAPER.ASC $ mv paper.txt paper.asc
C:\GUIDO>PRINT LETTER.TXT $ lpr letter.txt
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 section*.txt | less
</PRE>
</CODE></BLOCKQUOTE>
<P>Notes:
<P>
<UL>
<LI> <CODE>*</CODE> is smarter under Linux: <CODE>*</CODE> matches all files
except the hidden ones; <CODE>.*</CODE> matches all hidden files (but also the
current directory `<CODE>.</CODE>' and parent directory `<CODE>..</CODE>': beware!);
<CODE>*.*</CODE> matches only those that have a `<CODE>.</CODE>' in the middle or
that end with a dot; <CODE>p*r</CODE> matches both `peter' and `piper';
<CODE>*c*</CODE> matches both `picked' and `peck';
</LI>
<LI> when using <CODE>more</CODE>, press &lt;SPACE&gt; to read through the
file, `q' to exit. <CODE>less</CODE> is more intuitive and lets you use the
arrow keys;
</LI>
<LI> there is no <CODE>UNDELETE</CODE>, so <EM>think twice</EM> before
deleting anything;
</LI>
<LI> in addition to DOS' <CODE>&lt; &gt; &gt;&gt;</CODE>, Linux has
<CODE>2&gt;</CODE> to redirect error messages (stderr); moreover,
<CODE>2&gt;&amp;1</CODE> redirects stderr to stdout, while <CODE>1&gt;&amp;2</CODE>
redirects stdout to stderr;
</LI>
<LI> Linux has another wildcard: the <CODE>[]</CODE>. Usage: <CODE>[abc]*</CODE>
matches files starting with a, b, c; <CODE>*[I-N1-3]</CODE> matches files ending
with I, J, K, L, M, N, 1, 2, 3;
</LI>
<LI> <CODE>lpr</CODE> &lt;file&gt; prints a file in background. To check the
status of the print queue, use <CODE>lpq</CODE>; to remove a file from the print
queue, use <CODE>lprm</CODE>;
</LI>
<LI> there is no DOS-like <CODE>RENAME</CODE>; that is, <CODE>mv *.xxx
*.yyy</CODE> won't work. A REN-like command is available on
<A HREF="ftp://metalab.unc.edu/pub/Linux/utils/file">ftp://metalab.unc.edu/pub/Linux/utils/file</A>;
</LI>
<LI> use <CODE>cp -i</CODE> and <CODE>mv -i</CODE> to be warned when a file is
going to be overwritten.
</LI>
</UL>
<P>
<P>
<H2><A NAME="ss4.5">4.5 Running Programs: Multitasking and Sessions</A>
</H2>
<P>
<P>To run a program, type its name as you would do under DOS. If the directory
(Section
<A HREF="DOS-Win-to-Linux-HOWTO-5.html#Directories">Using Directories</A>) where the program
is stored is included in the PATH (Section
<A HREF="DOS-Win-to-Linux-HOWTO-8.html#System Initialisation">System Initialisation Files</A>), 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. Escamotage: being
<CODE>prog</CODE> your program, type <CODE>./prog</CODE>.
<P>This is what the typical command line looks like:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ command [-s1 [-s2] ... [-sn]] [par1 [par2] ... [parn]] [&lt; input] [> output]
</PRE>
</CODE></BLOCKQUOTE>
<P>where <CODE>-s1</CODE>, ..., <CODE>-sn</CODE> are the program switches,
<CODE>par1</CODE>, ..., <CODE>parn</CODE> are the program parameters. You can issue
several commands on the command line:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ command1 ; command2 ; ... ; commandn
</PRE>
</CODE></BLOCKQUOTE>
<P>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!
<P>
<UL>
<LI> To switch to session 1..6 on the virtual consoles, press
&lt;ALT-F1&gt; ... &lt;ALT-F6&gt;
</LI>
<LI> To start a new session in the same v.c. without leaving the current
one, type <CODE>su - &lt;loginname&gt;</CODE>. Example: <CODE>su - root</CODE>. This
is useful, for instance, when you need to perform a task that only root can
do.
</LI>
<LI> To end a session, type <CODE>exit</CODE>. If there are stopped jobs (see
later), you'll be warned.
</LI>
<LI> To launch a process in background, add an ampersand '<CODE>&amp;</CODE>'
at the end of the command line:
<BLOCKQUOTE><CODE>
<PRE>
$ progname [-switches] [parameters] [&lt; input] [> output] &amp;
[1] 123
</PRE>
</CODE></BLOCKQUOTE>
the shell identifies the process with a job number (e.g. <CODE>[1]</CODE>; see
below), and with a PID (Process Identification Number; 123 in our example).
</LI>
<LI> To see how many processes there are, type <CODE>ps ax</CODE>. This will
output a list of currently running processes.
</LI>
<LI> To kill (terminate) a process, type <CODE>kill &lt;PID&gt;</CODE>. You
may need to kill a process when you don't know how to quit it the right
way.... Unless you're root, you can't kill other people's processes.
Sometimes, a process will only be killed by <CODE>kill -SIGKILL
&lt;PID&gt;</CODE>.
In addition, the shell 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''.
</LI>
<LI> To see how many jobs there are, type <CODE>jobs</CODE>. Here the jobs are
identified by their job number, not by their PID.
</LI>
<LI> To stop a process running in foreground, press &lt;CTRL-C&gt; (it
won't always work).
</LI>
<LI> To suspend a process running in foreground, press &lt;CTRL-Z&gt;
(ditto).
</LI>
<LI> To send a suspended process into background, type <CODE>bg
&lt;%job&gt;</CODE> (it becomes a job).
</LI>
<LI> To bring a job to foreground, type <CODE>fg &lt;%job&gt;</CODE>. To bring
to foreground the last job sent to background, simply type <CODE>fg</CODE>.
</LI>
<LI> To kill a job, type <CODE>kill &lt;%job&gt;</CODE> where &lt;job&gt; may
be 1, 2, 3,...
</LI>
</UL>
<P>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 Windows, just to see the difference
in performance (if it doesn't crash, of course).
<P>
<P>
<H2><A NAME="ss4.6">4.6 Running Programs on Remote Computers</A>
</H2>
<P>
<P>To run a program on a remote machine whose name is
<CODE>remote.machine.edu</CODE>:
<P>
<BLOCKQUOTE><CODE>
<PRE>
$ telnet remote.machine.edu
</PRE>
</CODE></BLOCKQUOTE>
<P>After logging in, start your favourite program. Needless to say, you must
have a shell account on the remote machine.
<P>If you have X11, you can even run an X application on a remote computer,
displaying it on your X screen. Let <CODE>remote.machine.edu</CODE> be the
remote X computer and let <CODE>local.linux.box</CODE> be your Linux machine. To
run from <CODE>local.linux.box</CODE> an X program that resides on
<CODE>remote.machine.edu</CODE>, do the following:
<P>
<UL>
<LI> fire up X11, start an <CODE>xterm</CODE> or equivalent terminal emulator,
then type:
<BLOCKQUOTE><CODE>
<PRE>
$ xhost +remote.machine.edu
$ telnet remote.machine.edu
</PRE>
</CODE></BLOCKQUOTE>
</LI>
<LI> after logging in, type:
<BLOCKQUOTE><CODE>
<PRE>
remote:$ DISPLAY=local.linux.box:0.0
remote:$ progname &amp;
</PRE>
</CODE></BLOCKQUOTE>
(instead of <CODE>DISPLAY...</CODE>, you may have to write: <CODE>setenv DISPLAY
local.linux.box:0.0</CODE>. It depends on the remote shell.)
</LI>
</UL>
<P>Et voila! Now <CODE>progname</CODE> will start on <CODE>remote.machine.edu</CODE>
and will be displayed on your machine. Don't try this over the modem though,
for it's too slow to be usable. Moreover, this is a crude and insecure
method: please read the ``Remote X Apps mini-HOWTO'' at
<A HREF="http://www.linuxdoc.org/HOWTO/mini/Remote-X-Apps.html">http://www.linuxdoc.org/HOWTO/mini/Remote-X-Apps.html</A>.
<P>
<P>
<HR>
<A HREF="DOS-Win-to-Linux-HOWTO-5.html">Next</A>
<A HREF="DOS-Win-to-Linux-HOWTO-3.html">Previous</A>
<A HREF="DOS-Win-to-Linux-HOWTO.html#toc4">Contents</A>
</BODY>
</HTML>