[ 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 ]
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
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).
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.
List the contents of the current directory. Note the size of mysamplefile.
Observe the results: mysamplefile is now called mysamplefile.gz. It's also a good bit smaller.
gunzip mysamplefile.gz; ls -l
Uncompress. Observe that mysamplefile has returned to its original state. Notice that to uncompress one uses gunzip, not gzip.
Remove the file, since it was just to practice with.
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.
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.
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.
cat myprefix* > mynewfile
Concatenate all the files and write them to mynewfile. (The * and > are tricks you'll learn in another chapter .)
rm myfile mynewfile myprefix*
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.
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
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
search for files whose name matches XF86Config, you'd have to use a regular
expression: find / -name '*XF86Config*'. Like most of the command
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.
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.
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.
Gives this response:
/etc/init.d/boot: Bourne shell script text
Meaning that this is a text file, containing a Bourne shell script.
Debian Tutorial (Obsolete Documentation)29 Dezember 2009