Convert a text file to tar file if the size exceeds 5KB

Rajnilari2015
Posted by Rajnilari2015 under Others category on | Points: 40 | Views : 394
The tar command stores and extract files from an archive file known as a tarfile.

Syntax :
tar <operation> [options]


A full list of tar options and more about the same can be refer from here ( http://www.tutorialspoint.com/unix_commands/tar.htm ).

In our case, the scenario is to Convert a text file to tar file if the size exceeds 5KB

So let us issue the below command from the Ubuntu terminal

tar rvf destinaiton.tar $(find sourcefile.txt -size +5k)


The options

r => append,
v => verbose,
f => file

"destinaiton.tar" is the final tar file that will be generated

The find command plays an important role here.
It is used to search and locate list of files and directories based on conditions we specify for files that match the arguments. For more information please refer (http://www.tecmint.com/35-practical-examples-of-linux-find-command/ ).

Now find sourcefile.txt -size +5k indicates to find the "sourcefile.txt" in the current working directory, whose size is more than 5KB

Hope this helps

Comments or Responses

Login to post response