UNIX / Linux Tutorial

1.3.4  Copying Files  |  1.3.5 Moving Files  |  1.3.6  Deleting Files And Directories

1.3.7  Looking At Files  |  1.3.8  Getting Online Help  |  1.4  Accessing MS-DOS files

1.5  Summary Of Basic UNIX commands

1.3.4  Copying Files

To copy files, use the command cp, as shown here:

               /home/patrick/foo# cp /etc/termcap 

               /home/patrick/foo# cp /etc/shells 

               /home/patrick/foo# ls --F

               shells termcap


              /home/patrick/foo# cp shells bells

              /home/patrick/foo# ls --F

              bells shells termcap

              /home/patrick/foo#

The cp command copies the files listed on the command line to the file or directory
given as the last argument. Notice that we use "." to refer to the current directory.


1.3.5 Moving Files

The mv command moves files, rather than copying them. The syntax is very straight-forward:

                     /home/patrick/foo# mv termcap sells

                     /home/patrick/foo# ls -F

                     bells sells shells

                    /home/patrick/foo#

Notice that the termcap file has been renamed sells. You can also use the mv
command to move a file to a completely new directory.

Note: mv and cp will overwrite a destination file having the same name without asking 
you. Be careful when you move a file into another directory. There may already be a file
having the same name in that directory, which you'll overwrite!


1.3.6  Deleting Files And Directories

You now have an ugly rhyme developing with the use of the ls command. To delete a
file, use the rm command, which stands for "remove", as shown here:

                     /home/patrick/foo# rm bells sells

                     /home/patrick/foo# ls -F

                     shells

                     /home/patrick/foo#



We're left with nothing but shells, but we won't complain. Note that rm by default
won't prompt you before deleting a file—so be careful.

A related command to rm is rmdir. This command deletes a directory, but only if
the directory is empty. If the directory contains any files or subdirectories, rmdir will
complain.

1.3.7  Looking At Files

The commands more and cat are used for viewing the contents of files. more displays
a file, one screen at a time, while cat displays the whole file at once.

To look at the file shells, use the command:

               /home/patrick/foo# more shells.

In case you're interested what shells contains, it's a list of valid shell programs on
your system. On most systems, this includes /bin/sh,/bin/bash,/bin/csh.
We'll talk about these different types of shells later.

While using more, press Space to display the next page of text, and b to display
the previous page. There are other commands available in more as well, these are just the
basics. Pressing q will quit more.

Quit more and try cat /etc/termcap. The text will probably fly by too quickly
for you to read it all. The name "cat" actually stands for "concatenate", 
which is the real use of the program. The cat command can be used to concatenate the contents 
of several files and save the result to another file. You will see this again in section 
3.14.1.


1.3.8  Getting Online Help

Almost every UNIX system, including Linux, provides a facility known as manual
pages. These manual pages contain online documentation for system commands, resources,
configuration files and so on.

The command used to access manual pages is man. If you're interested in learning
about other options of the ls command, you can type:

                       /home/patrick# man ls

and the manual page for ls will be displayed.

Unfortunately, most manual pages are written for those who already have some idea of
what the command or resource does. For this reason, manual pages usually contain only the
technical details of the command, without much explanation. However, manual pages can
be an invaluable resource for jogging your memory if you forget the syntax of a command.
Manual pages will also tell you about commands that we don't cover in this book.

I suggest that you try man for the commands that we've already gone over and whenever
I introduce a new command. Some of these commands won't have manual pages,
for several reasons. For example, the command could be an internal shell command,
or an alias  which would not have a manual page of its own. Another example is cd, which 
is an internal shell command. The shell itself actually processes the cd—there is not a 
separate program that implements this command.


1.4  Accessing MS-DOS files

If, for some twisted and bizarre reason, you want to access files from MS-DOS, it's
easily done under Linux.

The usual way to access MS-DOS files is to mount an MS-DOS partition or floppy
under Linux, allowing you to access the files directly through the file system. For example,
if you have an MS-DOS floppy in /dev/fd0, the command:

                       # mount -t msdos /dev/fd0 /mnt

will mount it under /mnt. 

You can also mount an MS-DOS partition of your hard drive for access. If
you have an MS-DOS partition on /dev/hda1, the command:

                      # mount -t msdos /dev/hda1 /mnt

mounts it. Be sure to umount the partition when you're done using it. You can have
a MS-DOS partition automatically mounted at boot time if you include the entry in
/etc/fstab. The following line in /etc/fstab will mount an MS-DOS partition on 
/dev/hda1 on the directory /dos:

   /dev/hda1              /dos                msdos               defaults

You can also mount the VFAT file systems that are used by Windows 95/98:

                     # mount -t vfat /dev/hda1 /mnt

This allows access to the long filenames of Windows 95. This only applies to partitions
that actually have the long filenames stored. You can't mount a normal FAT16 file system
and use this to get long filenames.

The Mtools software may also be used to access MS-DOS files. The commands mcd,
mdir, mcopy all behave like their MS-DOS counterparts. If you install Mtools, there
should be manual pages available for these commands.

Accessing MS-DOS files is one thing; running MS-DOS programs is another. There is
an MS-DOS Emulator under development for Linux; it is widely available, and included in
most distributions. It can also be retrieved from a number of locations, including the various
Linux FTP sites listed in Appendix B. The MS-DOS Emulator is reportedly powerful
enough to run a number of applications, including WordPerfect, from Linux. However,
Linux and MS-DOS are vastly different operating systems. The power of any MS-DOS
emulator under UNIX is limited. In addition, a Microsoft Windows emulator that runs
under X Windows is under development.And there's always KDE and GNOME.

1.5  Summary Of Basic UNIX commands

This section introduces some of the most useful basic commands of a UNIX system,
including those that are covered in the previous section.

Note that options usually begin with "-", and in most cases you can specify more than
one option with a single "-". For example, rather than use the command ls -l -F, you
can use ls -lF.

Rather than listing every option for each command, we only present useful or important
commands at this time. In fact, most of these commands have many options that you'll
never use. You can use man to see the manual pages for each command, which list all of
the available options.

Also note that many of these commands take as arguments a list of files or directories,
denoted in this table by " file1 ... fileN". For example, the cp command takes as 
arguments a list of files to copy, followed by the destination file or directory. When copying 
more than one file, the destination must be a directory.

cd      Change the current working directory.
        Syntax: cd directory
        Where directory is the directory which you want to change to. ("."
        refers to the current directory, ".." the parent directory. If no directory
        is specified it defaults you your home directory.)

        Example: cd ../foo sets the current directory up one level, then back
        down to foo.

ls      Displays information about the named files and directories.
        Syntax: ls files
        Where files consists of the filenames or directories to list. The most
        commonly used options are -F (to display the file type), and -l (to give
        a "long" listing including file size, owner, permissions, and so on).

        Example: ls -lF /home/patrick displays the contents of the directory
        /home/patrick.

cp      Copies one or more file to another file or directory.
        Syntax: cp files destination
        Where files lists the files to copy, and destination is the destination file
        or directory.

        Example: cp ../pup joe copies the file ../pup to the file or
        directory joe

mv      Moves one or more file to another file or directory. This command does
        the equivalent of a copy followed by the deletion of the original file. You
        can use this to rename files, like in the MS-DOS command RENAME.
        Syntax: mv files destination
        Where files lists the files to move, and destination is the destination file
        or directory.

        Example: mv ../pup joe moves the file ../pup to the file or
        directory joe.

rm      Deletes files. Note that when you delete a file under UNIX, they are unrecoverable
        (unlike MS-DOS, where you can usually "undelete" the file).
        Syntax: rm files
        Where files describes the filenames to delete.
        The -i option prompts for confirmation before deleting the file.

        Example: rm -i /home/patrick/joe /home/patrick/pup
        deletes the files joe and pup in /home/patrick.

mkdir     Creates new directories.
          Syntax: mkdir dirs
          Where dirs are the directories to create.

          Example: mkdir /home/patrick/test creates the directory test
          in /home/patrick.

rmdir     Deletes empty directories. When using rmdir, the current working directory
          must not be within the directory to be deleted.
          Syntax: rmdir dirs
          Where dirs defines the directories to delete.

          Example: rmdir /home/patrick/papers deletes the directory
          /home/patrick/papers, if empty.

man       Displays the manual page for the given command or resource (that is,
          any system utility that isn't a command, such as a library function.)
          Syntax: man command
          Where command is the name of the command or resource to get help on.

          Example: man ls gives help on the ls command.

more      Displays the contents of the named files, one screen at a time.
          Syntax: more files
          Where files lists the files to display.

          Example: more papers/history-final displays the file
          papers/history-final.

cat       Officially used to concatenate files, cat is also used to display the con-tents
          of a file on screen.
          Syntax: cat files
          Where files lists the files to display.

          Example: cat letters/from-mdw displays the file
          letters/from-mdw.
          
echo      Displays the given arguments on the screen.
          Syntax: echo args
          Where args lists arguments to echo.

          Example: echo "Hello world" displays the string "Hello
          world".

grep      Display every line in one or more files that match the given pattern.
          Syntax: grep pattern files
          Where pattern is a regular expression pattern, and files lists the files to
          search.

          Example: grep loomer /etc/hosts displays every line in the file
          /etc/hosts that contains the pattern "loomer".


HOME

1.1 Introduction   1.2.10 Referring To Home Directories   1.3.4  Copying Files

1.6 Exploring The File System   1.8   Wildcards   1.9.3 Pipes   1.10.3 Permissions Dependencies

1.12.4  Stopping And Restarting Jobs   1.13.3 Inserting Text   1.13.9 Including Other Files

1.14.3 Shell Initialization Scripts   System Administration   2.3.1 The /etc/imitate file

2.4 Managing File Systems   2.6 Managing Users  2.6.5 Groups   2.7.2 gzip and compress

2.8.3 Making Backups To Tape Devices   2.9.1 Upgrading The Kernel   

2.9.3 Installing A Device Driver Module

BOOK: LINUX QUICK COMMAND REFERENCE

 

http://personal.atl.bellsouth.net/~psadler

© copyright KnowledgeWorks, Inc. (2001)