In this scenario it doesnt make much difference considering that there are only two files inside our archive. There is also a way to extract a single file from your archive. We could have specified the dash sign before each flag instead and the output would have been the same. NOTE: As mentioned before we are only typing the dash character once before all the flags. rw-rw-r- 1 myuser mygroup 10240 Feb 10 21:17 archive.tar-rw-rw-r- 1 myuser mygroup 54 Feb 10 21:17 testfile1-rw-rw-r- 1 myuser mygroup 78 Feb 10 21:17 testfile2Īs you can see we have used the -x flag to extract the content of the archive, the -v flag to do it verbosely and the -f flag to refer to the archive file specified after the flags (archive.tar). drwxr-xr-x 3 myuser mygroup 55 Feb 10 21:21. To extract the content of the file we have created before we can use the following command: tar -xvf archive.tar(the two lines below are the output of the command in the shell)testfile1testfile2ls -altotal 20drwxrwxr-x 2 myuser mygroup 59 Feb 10 21:21. Lets introduce an additional flag that allows to extract the content of a tar archive. You can see how its a lot easier to use the short version of the flag. The last command is using the long-option style for flag provided to Linux commands. Just to give you an idea, you can run the tar command in the following way and obtain the same output: tar -t -v -f archive.tar tar -tvf archive.tartar -tvf archive.tartar -list -verbose -file archive.tar The output is the same, this mean the dash is not necessary. So, lets see if passing the dash or not makes any difference.įirst of all, lets try to run the same command without using the dash before the flags: tar tvf archive.tar -rw-rw-r- myuser/mygroup 0 09:38 testfile1-rw-rw-r- myuser/mygroup 0 09:38 testfile2 I noticed that is some cases the dash before the flags was present but it wasnt always the case. I will explain what I mean in the next section… Shall I Use the Dash or Not with Tar? One of the things I noticed when I started using the tar command is that different people were running it in a slightly different way. We can now put together three flags: -t, -v and -f to see the files in the archive we have previously created: tar -tvf archive.tar -rw-rw-r- myuser/mygroup 0 09:38 testfile1-rw-rw-r- myuser/mygroup 0 09:38 testfile2 To list all the files in a tar archive without extracting its content we will introduce a fourth flag: Makes sense? List all files in a tar archive verbosely Lets swap the -f and -v flags in the tar command and try again: tar -cvf archive.tar testfile1 testfile2testfile1testfile2Īll good this time, the verbose flag show the names of the two files being added to the archive we are creating. This show how important is the order of flags for tar. The No such file or directory directory is caused by the fact that tar tries to create an archive called v that contains three files: archive.tar, testfile1 and testfile2.īut archive.tar doesnt exist and hence the error. 1 myuser mygroup 10240 Jul 17 09:42 file vv: POSIX tar archive (GNU) 1 myuser mygroup 0 Jul 17 09:38 testfile2-rw-rw-r. 1 myuser mygroup 0 Jul 17 09:38 testfile1-rw-rw-r. The result is an archive called v as you can see from the ls output below: ls -altotal 20drwxrwxr-x. Thats because the tar command creates an archive with a name based on what follows the -f flag, and in this case after the -f flag there is v. Weird, for some reason we get an error back… Lets see how the output changes if we also pass the -v flag when creating the archive: tar -cfv archive.tar testfile1 testfile2tar: archive.tar: Cannot stat: No such file or directorytar: Exiting with failure status due to previous errors The file command confirms that archive.tar is an archive: file archive.tar archive.tar: POSIX tar archive (GNU)Īnother useful flag is the -v flag that provides a verbose output of the files processed during the execution of the tar command on Linux. f: it allows to specify an archive file (in this case called archive.tar) c (same as -create): create a new archive This command creates an archive file called archive.tar that contains two files: testfile1 and testfile2. Here is a basic example of tar command, in this case we are not using compression: tar -cf archive.tar testfile1 testfile2 Conclusion Create an archive that contains two files.List all files in a tar archive verbosely.Create an archive that contains two files.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |