Docs/Desktop/FileTools
From Mandriva Community Wiki
Contents |
[edit] Finding Files
There is a very fast way of finding files in Linux from the command line. Install the slocate package from CD and then as root run updatedb to initialise the slocate database. Then as any user slocate string will instantly return the location of all files containing that string.
slocate can only find files indexed in it's database so it is important to update it regularly. A job to update the database runs at 4am each morning. If your computer is not switched on then it will not run. Install the anacron package to ensure that all missed jobs are run when the computer is powered on.
There is a way to use slocatefrom within a konqueror window. Install the kio_locate package from a Mandriva Linux 'contrib' mirror and then locate:/string/ in the URL line of konqueror will find all files with that string in their name for you.
[edit] Disk Usage
There are a couple of useful command line tools to work out how your partitions are being used.
*df : Will tell you how much space is on your partitions. *du : Will tell you the size of all your files and folders.
For anyone who wants a graphical tool to display partition usage there are two useful utilities.
*KDiskFree : Displays a bar showing free space on partitions. (Menu->System->Monitoring->KDiskFree) *fsv : FileSystemVisualiser is a package in the 'contrib' folder on mirrors which displays folder
and files as a 3 Dimensional map. Very useful for finding what is using up all that disc space.
[edit] Managing Large Compressed Archives
UPDATED: 21 Jan 2005
Assume that we have 3 directories, one of which has large amounts of data in it. We want to create a backup of this directory but we don't want any of the resulting archive files to exceed a certain size. The directories concerned are srcFilesDir, where the files are currently, arcFilesDir, which is where we want to put our archives, and extractedFilesDir which is where we will restore those files to.
- tar
- Tape ARchive, sticks files together end to end and will also compress them.
- split
- will divide an input or file into chunks of an exact size.
- cat
- does the opposite of split so it can be used to reassemble split files.
Example:
$ tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive.
The options used here are as follows:
For tar
- c - Create an archive.
- v - Produce lots of output so that we can see any errors.
- z - Compress using gzip.
- p - Preserve permissions and ownerships.
- S - Handle "sparse" files effectively.
- f - Specifies a file or output. In this case we use "-" so that we can also use a pipe (i.e. "|" ) to route the output through to the split command.
For split
- b - Specify the maximum allowable size of the file. In this case we are using one Gigabyte or 1073741824 bytes.
- prefix - Each of the resulting files will begin with a prefix but will be appended with an alphabetic identifier that will be used by cat later on to reassemble the files in the correct order. If I specify a prefix of arcFilesDir/largarchive. then the data will be stored in the arcFilesDir subdirectory and file names will begin with largarchive. but split will append an identifier after the ".".
$ cat arcFilesDir/* | tar xvzf - -C extractedFilesDir
This command follows many of the same rules. It is an example of how we can later reassemble the split files and restore the compressed data.
Options for tar in this case are:
- x - Extract files from an archive.
- v - Print lots of information about how things are going.
- z - Used with x above, this means uncompress using gzip.
- f - Used with x above, this specifies where we are getting our data from. In this case standard input.
Well, that's all I got on this right now. I will warn the reader that some compression programs, like zip/unzip, have very poor Large File support. Part of what spurred this HOWTO into being.
Here is how it all might go together:
[root@kaliklak root]# ls *FilesDir arcFilesDir: extractedFilesDir: srcFilesDir: First.iso Fourth.iso Second.iso Third.iso
So these are the files and directories we will be working with. This isn't the best way to handle CD images but as far as file size is concerned they'll work OK for this example.
[root@kaliklak root]# tar cvzpSf - srcFilesDir | split -b 1073741824 - arcFilesDir/largarchive. srcFilesDir/ srcFilesDir/Third.iso srcFilesDir/Second.iso srcFilesDir/Fourth.iso srcFilesDir/First.iso
So far, so good. Now lets see if the files are as they should be.
[root@kaliklak root]# ls -l arcFilesDir/ total 2687628 -rw-r--r-- 1 root root 1073741824 Jan 21 01:49 largarchive.aa -rw-r--r-- 1 root root 1073741824 Jan 21 01:53 largarchive.ab -rw-r--r-- 1 root root 601946112 Jan 21 01:55 largarchive.ac
Great! Now lets try our extraction.
[root@kaliklak root]# cat arcFilesDir/* | tar xzf - -C extractedFilesDir srcFilesDir/ srcFilesDir/Third.iso srcFilesDir/Second.iso srcFilesDir/Fourth.iso srcFilesDir/First.iso
Fantastic. So our files have extracted properly. Lets check them against the originals, just to be sure.
[root@kaliklak root]# ls -l srcFilesDir/* extractedFilesDir/* -rw-r--r-- 1 root root 728795136 Jan 20 18:53 srcFilesDir/First.iso -rw-r--r-- 1 root root 728795136 Jan 20 19:07 srcFilesDir/Fourth.iso -rw-r--r-- 1 root root 728563712 Jan 20 18:57 srcFilesDir/Second.iso -rw-r--r-- 1 root root 728563712 Jan 20 19:08 srcFilesDir/Third.iso extractedFilesDir/srcFilesDir: total 2849208 -rw-r--r-- 1 root root 728795136 Jan 20 18:53 First.iso -rw-r--r-- 1 root root 728795136 Jan 20 19:07 Fourth.iso -rw-r--r-- 1 root root 728563712 Jan 20 18:57 Second.iso -rw-r--r-- 1 root root 728563712 Jan 20 19:08 Third.iso [root@kaliklak root]#
Notice that the files were written into the subdirectory extractedFilesDir/srcFilesDir. This is because tar stores the directory name unless told to do otherwise.
Everythings cool so we are good to go. :-)
[edit] Comments on other compression protocols
- zip
- Will compress and concatenate files and store permissions and ownerships but does not support files larger than 2 Gigabytes. Also not self splitting.
- tar
- Does it all but can be complex to use. Not self splitting. Can use a variety of compression tools.
- dar
- A "fixed" version of tar. Self splitting is added. Not yet mainstream, though.
I'm really itching to try it. :-)
Currently however, the -P option seems broken. :-|