[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ A ] [ B ] [ C ] [ D ] [ next ]


Debian Tutorial (Obsolete Documentation)
Chapter 12 - File tools


12.1 Backup tools

tar, cpio, dump; also large-scale copying, cp -a etc.

(Perhaps something on how to back up only /home and /etc if you only have a floppy drive, since many home users won't have a tape drive)

How to use tar to copy lots of files, or back up your files. Tarballs. I'm thinking this should be a brief section aimed at single-user systems, with a more thorough sysadmin discussion in a different manual.

Backup commands (contributed by Oliver Elphick, section to be cleaned up and elaborated):

dump - dumps one filesystem at a time; its command options assume that you are using half-inch tape (maximum 45Mb per reel) so it's a bit annoying when using DAT (2Gb or more). Probably the best for regular backups. Can't be used for NFS-mounted filesystems.

cpio - `find [directories] -print | cpio -ovH newc -B >/dev/st0'

tar - `tar cvf /dev/st0 [directories]'

afio - like cpio; supports pre-compression of files before archiving.

tob - front-end for afio


12.2 File compression with gzip

Often it would be nice to make a file smaller: say to download it faster, or so it takes up less space on your disk. The program to do this is called gzip (GNU Zip).

  1. cd; cp /etc/profile ./mysamplefile

    Switch to your home directory, then copy an arbitrarily chosen file (/etc/profile) to your current directory in the process renaming it mysamplefile. This gives us a file to play with using gzip.

  1. ls -l

    List the contents of the current directory. Note the size of mysamplefile.

  1. gzip mysamplefile

    Compress mysamplefile.

  1. ls -l

    Observe the results: mysamplefile is now called mysamplefile.gz. It's also a good bit smaller.

  1. gunzip mysamplefile.gz; ls -l

    Uncompress. Observe that mysamplefile has returned to its original state. Notice that to uncompress one uses gunzip, not gzip.

  1. rm mysamplefile

    Remove the file, since it was just to practice with.


12.3 Splitting files into smaller pieces

Sometimes a file is too big to fit on a disk, or you don't want to send a huge file over the net in a single chunk. You can split the file using the split utility, and reassemble it using the cat (concatenate) utility.

  1. cd; cp /bin/bash myfile; ls -l myfile

    Copy the bash executable to a file in your home directory called myfile. Observe that myfile occupies a little over 400,000 bytes, or around 400 kilobytes.

  1. split -b100k myfile myprefix

    Splits the file into sections of 100 kilobytes, naming the sections myprefixaa, myprefixab, etc. Type ls -l so see the results.

    You can specify any number after the -b: choose one that makes sense. If you leave off the k, it will be understood as bytes instead of kilobytes. If you use m instead of k, it will be understood as megabytes.

  1. cat myprefix* > mynewfile

    Concatenate all the files and write them to mynewfile. (The * and > are tricks you'll learn in another chapter .)

  1. rm myfile mynewfile myprefix*

    Remove everything.


12.4 Finding files

There are two different facilities for finding files: find and locate. find searches the actual files in their present state. locate searches an index generated by the system every morning at 6:42 a.m. (this is a cron job, explained elsewhere in this manual ). locate won't find any files which were created after the index was generated. However, since locate searches an index, it's much faster - like using the index of a book rather than looking through the whole thing.

To compare the two ways of finding files, pretend you can't remember where the X configuration file XF86Config resides.

  1. locate XF86Config

    This should be pretty fast. You'll get a list of filenames which contain XF86Config, something like this:

         /etc/X11/XF86Config 
         /usr/X11R6/lib/X11/XF86Config
         /usr/X11R6/lib/X11/XF86Config.eg
         /usr/X11R6/man/man5/XF86Config.5x.gz
    
  1. find / -name XF86Config

    You will hear a lot of disk activity, and this will take a lot longer. Results will look something like this:

         /etc/X11/XF86Config 
         /usr/X11R6/lib/X11/XF86Config 
         find: /var/spool/cron/atjobs: Permission denied 
         find: /var/spool/cron/atspool: Permission denied
         find: /var/lib/xdm/authdir: Permission denied
    

    Notice that find only found files which were named exactly XF86Config, rather than any files containing that string of letters. Also, find actually tried to look in every directory on the system - including some where you didn't have read permissions. Thus the "Permission denied" messages.

    The syntax is different as well. You had to specify what directory to search in --- / --- while locate automatically chose the root directory. And you had to specify a search by name, using the -name option. You could also have searched for files using many other criteria, such as modification date or owner. To have find search for files whose name matches XF86Config, you'd have to use a regular expression: find / -name '*XF86Config*'. Like most of the command line tools, find accepts regular expressions as arguments.

In general find is a more powerful utility, and locate is faster for everyday quick searches. The full range of possible searches would take a long time to explain; for more details type info find, which will bring up the very thorough info pages on find and locate.


12.5 Determining a file's contents

Debian comes with a utility which can guess at the contents of a file for you. It is not always correct. However, it is reasonably accurate, and you can use it to explore your system.

  1. file /bin/cp

    You should see something like this:

         /bin/cp: ELF 32-bit LSB executable, Intel 386, version 1, stripped
    

    Skipping the technical parts, this is an executable file for Intel machines.

  1. file /etc/init.d/boot

    Gives this response:

         /etc/init.d/boot: Bourne shell script text
    

    Meaning that this is a text file, containing a Bourne shell script.


[ previous ] [ Contents ] [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] [ 6 ] [ 7 ] [ 8 ] [ 9 ] [ 10 ] [ 11 ] [ 12 ] [ 13 ] [ 14 ] [ 15 ] [ 16 ] [ 17 ] [ 18 ] [ A ] [ B ] [ C ] [ D ] [ next ]


Debian Tutorial (Obsolete Documentation)

29 Dezember 2009

Havoc Pennington hp@debian.org


mirror server hosted at Truenetwork, Russian Federation.