The tar command - which stands for tape archive - is used to convert a bunch of files in an archive. An archive is a file that contains other files and information needed to recover their original shape. Originally tar was created to meet the need for a storage system on magnetic tape (hence the name tar) but can be used to store files on any filesystem type.
command
serve a specificare un'altra directory dove fare a scrivere i file temporanei di cui sort ha bisogno. In genere, infatti, viene usata /tmp, ma a volte può essere necessario spostarsi in caccia di posto libero. Tra l'altro, il GNU sort deve essere stato scritto da qualcuno abituato a lavorare sotto DOS: se infatti esso trova settata la variabile di ambiente TMPDIR, usa quel valore come directory di lavoro.
Questa volta tocca a tar . Il nome sta per "tape archiver", cioè archiviatore su nastro: ma oramai sei abbastanza smaliziato per sapere che le probabilità di use the command on a real tape is very little. Let's be clear: if your sysadm has set things right and you have a tape drive, you can store your files by simply writing tar c. (the point is part of the command does not finish the sentence!). But since that time the answer will be more or less
or something like that, you better let it go and get a true read use the command. One note: if the man page did not improve in later versions, the GNU tar is just incomprehensible. Too bad.
Basic functions.
The command shown above is, however, already see the first characteristic: not used - in front of the options. This is not totally true: in a fit of kindness, in the current versions of tar may be possible to precede the option with '-' before the system is concerned. In general, however, the command syntax is:
\u0026lt;font style="font-style: italic;"> tar a large group of letters} {{a bit 'of parameters relating to the letters themselves
} [ -I file_include] file (s) [-C directory file] \u0026lt;/ font> The file is not a simple name, or better tell a simple regular expression such as "*": If it matches a directory, it throws the recursion and then tar begins to slip through the maze of file system you unearth unexpected findings. Recursion is done for good, and includes all the files whose names begin with a period and therefore are hidden in short, if you want to save everything from just a subtree ".."
five main functions are: c, r, t, u, x
- c is to create : an archive is built with the files that you indicate in the rest of the command.
- r is going to replace : the files that you indicate will be added to the bottom of the file, which obviously must already exist. And if there were already with that name, you ask? Nic problem! To control how, when there are multiple files with the same name is written on each one before, and only then will the last.
- t is about to head : to see what files are in an archive.
- u going to update (refresh) : Similar to the function r, but if the files were already present and have not changed are not wasted space.
- x stands for extract: is the function that is used to pull files from these blessed! In reality often does not even say what the file (even for problems with relative and absolute path), in which case we'll assume you want to extract everything.
-
the GNU tar, not to disprove, added two more, which however are not so necessary at least in my opinion:
- A , hanging another tar file (and not a single file) the archive;
- d, which occurs if there are differences between the files of an archive and those who are in the directory, so you know what has changed.
Ah, I forgot: The GNU tar can always write out the function names, preceded by - (two hyphens). Need? not necessary? for me it's just a waste of time.
modifying functions.
In so-called large group, there are so many letters. I will speak here only of the main view of my usual laziness. So it does not happen hardly ever use them all! As I said above, if the function has a parameter, this is the nice orderly after the same large group.
- b nn is the number of groups 512 bytes need to write at once (one block). It is used only when writing to tape, and generally leave at 20 because it optimizes the write speed.
- B forces tar to wait for it to completely exit the block above, before writing. If you use tar as a filter, and he is sent across the network, it is likely that there are no timeouts and the system believe that the data is finished, and this is not bello.l
- f filename is to give the name of the file (or device which is true) to be used as an archive. If it is written, tar begins to check if the environment variable TAPE è settata a qualcosa. Sennò. si prende il valore di default, tipicamente /dev/rmt0 . Se lo si scrive, si usa quello: caso speciale è il nome - , che sta per standard input o standard output a seconda di cosa sia più logico. In questo modo, il comando si trasforma automagicamente in un filtro, e i veri amanti di Unix si sentono immediatamente a casa.
- h serve per dire a tar di leggere i file, o le directory, puntate dai link simbolici. In genere, infatti, viene semplicemente salvato il nome del link.
- p permette di salvare, oppure di estrarre, informazioni supplementari sui permessi del file, come ad esempio the setuid bit. All this of course if you are root: think otherwise would be fun to create programs like Trojans!
- v is the "verbose", which says everything you want to know when we create an archive or extract its files. After a bit ', it's so automatic that we need to force himself to not only add it when it is not necessary, but even bother. Think how nice to use two tar appended to another one, how am I in the examples, and see the video output of a mixed one and the beautiful ...
- w serves to give us the opportunity to be decision-makers. In practice, whenever he should do something, tar prompt us: if we respond with a word that begins with y (lower case), performs the action, otherwise forget it.
- X exclude-file is the name of a file where you can write, one per line, all the files you do not want to consider the functions c, you x. You can have multiple functions X, each corresponding to a file. Noticine Two: Remember that when you save the file in a file, their names begin with . / , and remember to include the name of the file exclusion inside!
Just to give you an idea, I left out the following functions for the Solaris tar: E, F, FF, i, l, m, o. The GNU tar instead The following functions named with a letter: F, G, g, i, k, K, L, M, O, O, R, S, S, T, V, W, as well as another dozen that do not were found letters of the alphabet available. It is said that the options match: F, i, and o are in fact different things. There are also functions defined by a number between 0 and 7, which device is used to specify a different file. Some functions are GNU
but funny, and worth a look.
- the need to say not to change the file system, even though the heat of recursion in the creation of an archive would require it. This is not farfetched as it sounds: you will see in the examples. It is worth to point out Solaris tar that has a completely different conception of the , it serves to get angry if there is no file that a symbolic link points.
- M allows you to create an archive into several parts, to use if you want to break a file into floppini.
- P leaves the slash / in the names of files that are saved. It is not a good thing (that typically takes the GNU tar), but can anyone find it convenient.
- z (and sister Z) is not the only function for which it is worthwhile to install the GNU tar if you do not have one. With this fact you can use gzip (o rispettivamente compress ) per comprimere e decomprimere gli archivi. Chi arriva dal mondo dos si è sempre chiesto perché sotto Unix ci sono due comandi distinti per archiviare e comprimere, e non un unico zip. Bene, a parte il fatto che così ce n'è uno solo, la vera ragione è che si comprime meglio un unico file che tanti pezzetti, anche se al prezzo di perdere tutto se il primo file risulta corrotto.
Funzioni separate.
Le due funzioni che se ne stanno da sole sono, come visto sopra, -I include_file e -C directory file . La prima funziona più o meno come X : si apre il file and reads the file list on which you should do. Careful not to use spaces, that would be considered part of the file, and remember that if a file is simultaneously included and excluded, the latter condition prevails.
function -C is a bit 'more delicate. It is used only with functions and c r , and requires exactly two parameters, the program uses the first argument as a chdir , and then place elsewhere, and the second indicates which files (recursively) saving. In practice, it has the ability to save files in the directory without having unrelated from the root and select only the parts that interest you. Also better than nothing in this case.
examples.
A couple of examples are certainly not bad. Let's start with the most common: Remove a package format. Tar.gz The command to be given under the GNU tar (perhaps after checking with
tvzf pippo.tar.gz tar
-
in this case means the standard input. If you want to create a tar file with the directory foo
and all the files below, the answer is given by% tar cvf pippo.tar foo (foo and better position themselves in writing
tar cvf .. / foo . tar.- at least in my opinion. If you want to copy a subtree from another party in one shot, you can not use cp
, as even children now know; tar is just what we wants, used twice in a pipe.
fromdate% cd; tar cf - in entrambi i casi; ci serve inoltre racchiudere il secondo comando in una sottoshell, perché dobbiamo essere certi che il file sia salvato nella directory corretta. Altrimenti, la pipe terminerebbe con ilcd , si perderebbe tutto l'input e il secondo tar non saprebbe da dove prendere i dati. Infine, un comando d'alta scuola: un tar in rete. Supponiamo di avere un nastro su un'unità remota e di volerlo utilizzare. Purtroppo non abbiamo la possibilità di copiare tutti i nostri file sul calcolatore remoto, e comunque siamo talmente innamorati delle pipe che vogliamo sfruttarle ad ogni pié sospinto. Bene: se sei stato attento, saprai che
b e B dovranno servirci perché abbiamo un nastro e lavoriamo in rete, e rsh
non è certo dimenticato. Tutto qui? No. Ovviamente non si può usaretarda ambo le parti. Ci si incasinerebbe con le dimensioni dei blocchi. Ma niente paura, c'è il nostro vecchio amicone dd ! Ecco in primo luogo come si salva il sottoalbero che parte da pippo su un nastro remoto sulla macchina
server1 : % tar cvfb - 20 pippo sempre aggiornato sui nuovi contenuti del blog :
0 comments:
Post a Comment