Question

I am looking for a Unix command which will create a tar of 10 files from a directory.

Was it helpful?

Solution

tar cf path_of_tar.tar $(ls | head -10)

Add options to ls to select the 10 you want.

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top