> For the complete documentation index, see [llms.txt](https://sh.howtocode.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sh.howtocode.dev/3.0.0.part3intro/3.6.0.archiving-and-backup/3.6.1.compressing-data.md).

# ডাটা কম্প্রেশন

ডাটা কম্প্রেশনের মাধ্যমে আমরা বেশি ডাটা কম জায়গায় রাখতে পারি। বাস্তব জীবনে এর ব্যবহার প্রচুর। এমন অনেককিছুই আছে যা আমরা কম্প্রেসড্ অবস্থাতেই ব্যবহার করি। যেমন এমপিথ্রি মিউজিক ফাইল বা জেপিইজি ইমেজ।

ডাটা কম্প্রেশন টুলসগুলো ডাটা কম্প্রেসড করতে বিশেষ গাণিতিক পদ্ধতি ব্যবহার করে যাকে কম্প্রেশন এ্যালগরিদম বলে। খুব সহজ থেকে খুব কঠিন, বিভিন্নরকমের এ্যালগরিদম আছে। যেমন মনে করুন, একটা টেক্সট ফাইলে আপনি শুধু 'A' লিখলেন একহাজারবার। ফাইলের মূল ডাটার পরিমান হবে ১ হাজার বাইট। এখন আপনি একটি কম্প্রেশন মেথড তৈরী করলেন। সেটা দিয়ে কম্প্রেস করার সময় সেটি লিখলো, "একহাজারটা A". এটুকু লিখতে কিন্তু আপনার একহাজার বাইট লাগছে না। আনকম্প্রেস করার সময় আনকম্প্রেসিঙ টুলটি আবার একহাজারটি 'A' বসিয়ে দেবে। এটি খুব সাধারণ পদ্ধতি কিন্তু আসলে এভাবেও কম্প্রেশন করা হয়। বাস্তবে আরো চমৎকার সব এ্যালগরিদম ব্যবহার করা হয়।

কম্প্রেশন মেথড কীভাবে কাজ করে এটি না জানলেও ক্ষতি ছিল না। পরে মাথা না ঘামালেও চলবে। এবার আমরা দুটি কম্প্রেশন টুল এর ব্যবহার দেখি:

## gzip ও gunzip

`gzip` ও `gunzip` যথাক্রমে ফাইল কম্প্রেস ও আনকম্প্রেস করে। আসুন এদের ব্যবহার করা যাক:

```
me@howtocode-pc:~$ ls -l /etc > etc-ls.txt
me@howtocode-pc:~$ ls -l etc-ls*
-rw-rw-r-- 1 me me 15820 Apr  4 19:30 etc-ls.txt
me@howtocode-pc:~$ gzip etc-ls.txt
me@howtocode-pc:~$ ls -l etc-ls*
-rw-rw-r-- 1 me me 3265 Apr  4 19:30 etc-ls.txt.gz
me@howtocode-pc:~$ gunzip etc-ls.txt.gz
me@howtocode-pc:~$ ls -l etc-ls*
-rw-rw-r-- 1 me me 15820 Apr  4 19:30 etc-ls.txt
```

আমরা প্রথমে `ls -l /etc > etc-ls.txt` কমান্ড থেকে /etc ডিরেক্টরির কন্টেন্ট লিস্ট দিয়ে একটি ফাইল বানিয়েছি etc-ls.txt নামে। এবার আমরা `ls -l etc-ls*` দিয়েছি এবং দেখেছি ওই ফাইলটির সাইজ 15820 বাইট। এবার `gzip etc-ls.txt` কমান্ড দিয়ে আমরা ফাইলটি কম্প্রেস করেছি। আবারও `ls -l etc-ls*` কমান্ড দিয়ে এবার আমরা দুটো জিনিস লক্ষ্য করেছি। প্রথমত, etc-ls.txt ফাইলটি নেই। বরং etc-ls.txt.gz তৈরী হয়েছে। এবং এর সাইজ অনেক কম, 3265 বাইট। এবার আমরা `gunzip etc-ls.txt.gz` কমান্ড দিয়ে আনকম্প্রেস করেছি। এবারও `ls -l etc-ls*` কমান্ড দিয়ে আমরা দেখলাম কম্প্রেসড ফাইলটি আনকম্প্রেসড হওয়া etc-ls.txt দ্বারা প্রতিস্থাপিত হয়েছে এবং এর সাইজ আগের অবস্থাতেই ফিরে এসেছে।

এবার দেখে নেয়া যাক **gzip** ও **gunzip** এর কিছু অপশন:

| অপশন      | কাজ                                                                                                                                                                                                  |
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| -c        | আউটপুট স্ট্যান্ডার্ড আউটপুটে পাঠাবে। যেটাকে আমরা কোনো ফাইলে রিডিরেক্ট করতে পারি। এতে সুবিধা হল অরিজিনাল ফাইলটি মুছবে না।                                                                             |
| -d        | ডিকম্প্রেশন মোড। অর্থাৎ gzip gunzip এর মত কাজ করবে।                                                                                                                                                  |
| -f        | ইতমধ্যে একইনামে কম্প্রেসড ফাইল থাকলেও নতুন করে কম্প্রেস করবে।                                                                                                                                        |
| -h        | হেল্প দেখাবে।                                                                                                                                                                                        |
| -l        | কম্প্রেসড ফাইলের পরে ব্যবহার করতে হয়। ফাইলটি সম্পর্কে বিভিন্ন তথ্য দেখায়।                                                                                                                            |
| -r        | রিকার্সিভ মোড।                                                                                                                                                                                       |
| -t        | কম্প্রেসড ফাইল ঠিকঠাক আছে কিনা পরীক্ষা করবে।                                                                                                                                                         |
| -v        | ভারবস মোড। বিভিন্ন তথ্য দেখাবে কাজ করার সময়।                                                                                                                                                         |
| -*number* | নাম্বারের জায়গা 1 থেকে নয়ের মধ্যে নাম্বার দেওয়া যাবে। 1 বা `--fast` দিলে সবচেয়ে দ্রুত  কম্প্রেসশন করবে কিন্তু কম্প্রেসড হবে কম। অপরপক্ষে 9 বা `--best` দিলে সবচেয়ে আস্তে কিন্তু বেশি কম্প্রেসড করবে। |

এবার আমরা নীচের কমান্ডটি দেখি:

```
me@howtocode-pc:~$ ls -l /etc | gzip -v > foo.txt.gz
79.5%
```

এখানে আমরা `ls -l /etc` এর ফলাফল পাইপ দিয়ে সরাসরি `gzip -v` কমান্ডে পরিচালিত করেছি এবং তার আউটপুটকে foo.txt.gz তে রিডিরেক্ট করেছি। আমরা এবার এই ফাইলটি টেস্ট করতে পারি এভাব:

```
me@howtocode-pc:~$ gzip -tv foo.txt.gz
foo.txt.gz:        OK
```

আবার আমরা চাইলে আনকম্প্রেস না করেই তথ্য পড়তে পারি এভাবে:

```
me@howtocode-pc:~$ zless foo.txt.gz
```

`zless` কম্প্রেসড ফাইলের ওপর `less` কমান্ডের মত কাজ করে।

## bzip2 ও bunzip2

`bzip2` ও `bunzip2` কমান্ডটি একদম `gzip` ও `gunzip` এর মতই ব্যবহার করতে হয়। তবে এটি তুলনামূলক ধীর কিন্তু আরো উন্নত কম্প্রেসশন এ্যালগরিদম ব্যবহার করে।`gzip` ও `gunzip` এর প্রথম উদাহরণটি আমরা `bzip2` ও `bunzip2` এর জন্য দেখবো:

```
me@howtocode-pc:~$ ls -l /etc > etc-ls.txt
me@howtocode-pc:~$ ls -l etc-ls.txt
-rw-rw-r-- 1 me me 15820 Apr  4 21:17 etc-ls.txt
me@howtocode-pc:~$ bzip2 etc-ls.txt
me@howtocode-pc:~$ ls -l etc-ls*
-rw-rw-r-- 1 me me 2860 Apr  4 21:17 etc-ls.txt.bz2
me@howtocode-pc:~$ bunzip2 etc-ls.txt.bz2
me@howtocode-pc:~$ ls -l etc-ls*
-rw-rw-r-- 1 me me 15820 Apr  4 21:17 etc-ls.txt
```

আমরা একটা জিনিস এবার লক্ষ্য করছি তা হল এবার কম্প্রেসড ফাইলের এক্সটেনশন bz2, gz নয়। এবং আকারেও ছোট।


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sh.howtocode.dev/3.0.0.part3intro/3.6.0.archiving-and-backup/3.6.1.compressing-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
