In our previous post “using a file as a storage device” adrian asked a question to us : is it possible to extend the size on the ‘filename’ file? We searched on it and figured out the answer. Let’s roll🙂
Lets say you create a file name /newfile of size 200MB and format it, after a while you want to extend the file size. To do that do the following
Step 1. Lets say you want to increase the file size by 100MB
dd oflag=append conv=notrunc if=/dev/zero of=/newfile bs=1MB count=100
Now, the file is 100MB larger.
Step 2. Run file system check on the file
fsck -f /newfile
Step 3. Now if you formatted the file system in ext2,3 or 4, you can resize it by using
If you are unable to understand this post fully , please visit using file as a storage device first and check out the comments too . Thanks to adrian for comment🙂
Compression of files is a necessity these days. It’s not only helps you in saving your space but also helps you in quick sharing and back up purposes. Text files compresses more than the web images and videos because they are already in the compressed form .You must have observed many open source softwares in the .tar.gz packages. These are the compressed file made out using the tar and gzip (gunzip) utility. So let’s get started with these great utilities😀
Tar : Good practice for compressing a file is to archive the files first and then compress them. So to create an archive of a disk archive that contains a group of files or an entire directory , we should use the tar utility. Another advantage of the tar is that it also compresses the file to some extent. So using tar with gzip means double layer compression. To use the tar we should need to know some of its options:
-c : Create an archive
-x : Extract from the archive
-t : Display the files in archive
-f : Specify the archive named as arch
Create the archive : You can create the archive by following the syntax tar -cvf file.tar file1 file2 . For Example- We created an archive named as html.tar for the html folder by using the command tar -cvf html.tar html . As I told you above tar compresses the file also. You can easily see this in the below screenshot :
compression by tar
Extracting files from tar archive : You can extract the files for tar archive using the ‘-x’ utility. Follow this syntax and your file will get extracted tar -xvf file.tar
Gzip or Gunzip : Using this utility on the tar archive file adds an another layer of compression. As a result of both you got the .tar.gz file format. Challenger of the gzip is the bzip2 utility because it compresses the file in the greater ratio. But bzip2 is a slow compression process. So it depends on your needs which utility to use.
Compress using gzip : You can compress with the gzip using the simple syntax of gzip filename . We are compressing the html.tar archive further using the gzip . You can also use the ordinary files in the filename instead of the archive. We can see the compression ratio by using ‘-l’ option along with this utility. Below is the screenshot of the same :
Extracting the gzip compression : You can easily extract the gzip utility by using either the “gunzip” command or by using the ‘-d’ option with the gzip. In short you need to follow the following syntax : gzip -d filename.gz or gunzip filename.gz.
I hope this tutorial will be useful for you. Suggestions,feedback and queries are always welcome.
Cat is one of the most well know commands of the Linux as well as of Unix systems. It’s mainly use to display the file contents of a small file on the terminal. But scope of the cat commands is not just limited to display, We can use the cat command to create,append and even in the concatenation of the two files. In this post we will learn how to complete these jobs using the same cat command.
Display : As stated above we mostly use cat utility for the display purpose only. To display a file using cat use the following syntax without brackets “cat filename1 filename2…” . You can display single file as well as multiple files in one go. In case of multiple files, file2 will get display after the file1. Example – In the screenshot below we are displaying the contents of the test file using cat command.
Display Using Cat
You can use options like ‘-v’ , ‘-n’ etc to enrich the display. Look at the man pages for the options by typing man cat.
Create : This is the best part about cat. You can even create your text files using this utility. Enter the cat command followed by the redirect output ‘>’ character and the filename. In short, something like this “cat > file” . When you press enter the prompt vanishes. cat now waits to take the input from the user. Enter your text. Press [Ctrl-d] to signify the end of file character.The system will understand that no further text input will be made. The file is written and the prompt is returned. To verify you can use the cat file again.
Append : We can append a file by using append character “>>” utility along with the cat command. Syntax for appending is “cat >> file”. In this cat waits for the user to enter the input on to the terminal and then reads it. After reading it appends it into the file.
Append Your Files
Concatenate : Sometimes you need to concatenate two files especially if you are following the modular coding techniques. You can easily concatenate two files by using the redirecting output parameter ‘>’. We can concatenate two files into the third file by following a syntax like “cat file1 file2 >file3” . It will first write down the file1 and then file2 into the file3.
Scope of cat is not just limited to only these four functions. You can learn more about this utility using the web or by reading the man pages.