Convert a pdf file to tar file if the size equals 1MB

Rajnilari2015
Posted by Rajnilari2015 under Others category on | Points: 40 | Views : 324
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 pdf file to tar file if the size equals 1MB

So let us issue the below command from the Ubuntu terminal

tar rvf destinaiton.tar $(find /Desktop/MyFolders -name sourcefile.pdf -size 1M)


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 /Desktop/MyFolders -name sourcefile.pdf -size 1M indicates to find the file whose name is "sourcefile.pdf" under /Desktop/MyFolders location, whose size equals 1MB

Hope this helps

Comments or Responses

Login to post response