Archive all txt files if the size is more than 5MB

Rajnilari2015
Posted by Rajnilari2015 under Others category on | Points: 40 | Views : 329
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 Archive all txt files if the size is more than 5MB So let us issue the below command from the Ubuntu terminal
tar rvf destinaiton.tar $(find -name "*.txt" -size +5M)

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 -name "*.txt" -size +5M indicates to find all the files whose extension is "txt" in the current working directory and whose size is more than 5MB

Hope this helps

Comments or Responses

Login to post response