I am using below command to untar
tar -xvf <filename.tar>
I want to make sure extracted files' modified time is updated to current time.
GNU tar has an option for this:
-m, --touch
don't extract file modified time
With this option, extracted files have the time of extraction as their last-modified.
Anyways, I found an answer. I looped through all the files in the tar and used touch command to change the modified time.
tar -xvf <filename.tar>
for f in $(tar -tf <filename>.tar); do touch $f;done
Related
I have a file (reviews_dataset.tar.gz) that contains many files which contains data. I am required to extract the files in this archive and then perform some basic commands on the file. So far I have created a directory named (CW) and found a command tar zxvf fileNameHere.tgz but when I run this it of course cannot find my file as I have not "downloaded it" into my directory yet? How do I get this file into my directory so that I can then extract it? Sorry if this is poorly worded I am extremely new to this.
You must either run the command from the directory your file exists in, or provide a relative or absolute path to the file. Let's do the latter:
cd /home/jsmith
mkdir cw
cd cw
tar zxvf /home/jsmith/Downloads/fileNameHere.tgz
You should use the command with the options preceded by dash like this:
tar -zxvf filename.tar.gz
If you want to specify the directory to save all the files use -C:
tar -zxf filename.tar.gz -C /root/Desktop/folder
I am using the command
tar -cvfE $TAPE_DRIVE $BACKUP_FILE
to write to tape for the first time. It works like a charm.
BUT, when there is already a file in the tape (older backup) I use the command
tar -rvfE $TAPE_DRIVE $BACKUP_FILE
which disappoints every time.
There is enough space on the tape (1.3TB).
I am only writing 80-90GB files at a time.
The tape is mounted locally.
After failing to write to tape if I try to list files on tape, i get the old (first) file that I wrote to it.
Is there any other command I should be using?
Apparently the native tar commands is not perfect and has bugs. It is recommended that using -i (ignore directory checksum errors) flag will resolve this but it did not in my case.
Using GNU tar solved my problem. Simply use gtar instead of tar and it works like a charm.
So the commands are like
gtar -cvf $TAPE_DRIVE $BACKUP_FILE
and
gtar -rvf $TAPE_DRIVE $BACKUP_FILE
I used tar -cvf sample_directory/* and didn't specify file.tar.gz. So the Makefile within the folder is in some unreadable format. is there a way to recover my Makefile?
The Makefile within the folder contains the output from the tar command, so it's not "some unreadable format", it's gzipped tar format. that tar archive won't contain your missing Makefile though.
The comments about recovering the Makefile from your backups or from your version control system are apt. This is in fact what you need to do.
If you don't have a backup or the Makefile wasn't checked in to a version control system, then there isn't a feasible way to recover its contents.
Aside from the issue of your poor lost Makefile, a piece of advice about using tar: never tar up a bunch of individual files inside a directory. Always tar up the directory itself instead. There is not much more annoying than untarring an archive that contains a big bunch or files instead of a single directory (which then contains files). Doing that makes a mess by littering files all over the directory that happens to be the current directory. Please be nice to whoever is going to extract your tar files (which might be yourself, later on!), follow convention, and tar up complete directories.
tar -czf file.tar.gz sample_directory
As a bonus, if you do it that way, and you forget the output filename like this:
tar -czf sample_directory
You won't squash anything, you'll just get an error.
I am trying to untar UNIX-based operating system from a .tar.gz file. In order to do so I use the following command:
tar -xvf rootfs.tar.gz -o
The -o flag is to not to preserve the ownership of the files (it gave some problems). The problem is that when a symbolic link is untared the following message shows up
Cannot create symlink to `toto': Operation not permitted
Moreover, mknod also gives problems
dev/tty0: Cannot mknod: Operation not permitted
I am in a FAT system. Does anyone know how to untar that file?
Thanks in advance
If the file is a tar.gz you must use:
tar -xvzf rootfs.tar.gz
And notice that a FAT filesystem doesn't support symbolic links, so it doesn't know how to make it on that FS, and it explains the Operation Not Permitted Error.
+1 fpr Ivan's answer
please note that:
flags always go right after the name of the command!
you will need to study "man tar" to see what other options you want, e.g. preserve owner, permissions, time-creation date, etc..
The correct answer is that if you're trying to untar a UNIX root file system, that's going to include special files such as device nodes (which is why tar is invoking mknod).
To create those successfully, tar must be allowed to run as root. Therefore, the correct answer is to use sudo, like so:
sudo tar -xvzf rootfs.tar.gz
Try this to untar a tar file. Hopefully it will work fine without any problem, as this one solved my issue
tar -xvvf foo.tar
I am looking for a Unix command which will create a tar of 10 files from a directory.
tar cf path_of_tar.tar $(ls | head -10)
Add options to ls to select the 10 you want.
The command you're looking for is: tar
How it's usually used:
$ tar cf file.tar file1 file2...
Well, depending on your needs...
$ tar cf tenfiles.tar file1 file2 file3 ... file10
That'll do it. You can check out the tar manpage ($ man tar) for further details on other options you might need. (Your question was a bit vague, so I can't be that much more specific.)
I would suggest trying:
man tar
This will show all the options available and usage information. A typical usage for creating a tar of files in a directory would look like this:
tar -cvf myfiles.tar ./mydirectory
where myfiles.tar is the name of the tar file you want to create, and mydirectory is the directory the files reside in.
tar -cvf name.tar /path/to/file1 /path/to/file2 /path/to/file3 ...
Can you define what files are they? Are they of a specific filename pattern? My reasoning is asking that you specified 10 files.
In general:
tar cvf tar_with_10_files.tar somefile_with_wildcards_or_pattern_matching