Introduction to Files and File Types in Linux (text, binary, special files)

Linux एक bold idea को इसके logical end तक ले जाता है: लगभग सब कुछ एक file है, आपके documents, आपके programs, यहाँ तक कि आपके devices, और ls -l listing का पहला character बताता है आप किस kind की file देख रहे हैं।

10 min read · 7 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

सब कुछ एक File है

Linux एक strikingly simple idea पर built है: लगभग सब कुछ एक file है। आपके text documents files हैं, obviously। पर आपके compiled programs, आपकी directories, और यहाँ तक कि आपके hardware devices भी, keyboard, disk, terminal, सब files की तरह appear होते हैं जिन्हें आप read और write कर सकते हैं।

यह 'everything is a file' philosophy का मतलब है tools और ideas का एक consistent set पूरे system के across काम करता है। यह lesson उन kinds of files introduce करता है जो Linux के पास हैं, और दिखाता है इन्हें एक glance में कैसे बताया जाए, जिस पर आप लगातार rely करेंगे।

Theory

Main File Types

Linux files कुछ types में fall करती हैं:

Regular files ordinary data hold करती हैं। ये split होती हैं text files (human-readable: scripts, configuration, notes) और binary files (machine data: compiled programs, images) में।

Directories खुद एक type of file हैं, एक file जिसके contents दूसरी files की एक list हैं। यही तरीका है folders nest करने का।

Special files उन चीज़ों को represent करती हैं जो plain data नहीं हैं। सबसे important हैं device files: आपका hardware यहाँ appear होता है (उदाहरण के लिए एक disk या terminal), तो same read और write operations devices पर वैसे ही काम करते हैं जैसे documents पर। बाकी special files में symbolic links (दूसरी files की तरफ़ pointers), named pipes, और sockets शामिल हैं।

Formula

ls -l का पहला Character Type है

जब आप ls -l चलाते हैं, हर line -rwxr-xr-x जैसे characters के एक block से शुरू होती है। वही बिल्कुल पहला character आपको file type बताता है:

- regular file, d directory, l symbolic link, c character device, b block device, p named pipe, s socket।

तो नाम पढ़ने से पहले भी, पहले character पर एक glance आपको बताता है आप किस तरह की चीज़ देख रहे हैं। यह जल्दी build करने लायक एक habit है।

Practical

ls -l से File Types पढ़ना

$ ls -l /etc/hostname /bin /dev/null
-rw-r--r-- 1 root root   13 ... /etc/hostname     # -  regular (text) file
lrwxrwxrwx 1 root root    7 ... /bin -> usr/bin    # l  symbolic link
crw-rw-rw- 1 root root ... /dev/null              # c  character device

# First character:  -=regular  d=directory  l=link  c=char device  b=block

Quiz

एक ls -l listing 'd' character से शुरू होने वाली एक line दिखाती है। यह किस तरह की file है?

  1. एक device file, क्योंकि 'd' device के लिए खड़ा है
  2. एक directory, क्योंकि leading 'd' एक directory mark करता है
  3. एक regular data file
  4. एक symbolic link
Show the answer

एक directory, क्योंकि leading 'd' एक directory mark करता है

ls -l listing में leading 'd' एक directory mark करता है, एक file जिसके contents दूसरी files की एक list हैं। Option A एक natural-looking trap है: 'd' का मतलब device NAHI है; device files 'c' (character device) या 'b' (block device) से दिखाई जाती हैं। Option C ग़लत है क्योंकि एक regular file leading '-' से दिखाई जाती है, 'd' से नहीं। Option D ग़लत है क्योंकि एक symbolic link leading 'l' से दिखाई जाती है। Common first characters memorise कीजिए: '-' regular, 'd' directory, 'l' link, 'c' और 'b' devices। वह single character सबसे तेज़ तरीका है यह जानने का आप किस चीज़ से deal कर रहे हैं।

Think first

Devices को बिल्कुल Files की तरह क्यों Treat करें?

एक hard disk कोई document नहीं है। Linux आपके keyboard, disk, और terminal को files की तरह क्यों appear कराता है? फिर tap कीजिए।

Show the answer

क्योंकि यह tools का एक simple, consistent set सब कुछ पर काम करने देता है, जो enormously powerful है। अगर एक device एक file की तरह behave करता है, फिर वही operations जो आप पहले से जानते हैं, read, write, और वही commands, cat, cp, redirection, hardware पर भी काम करते हैं, बिना कोई special नया interface सीखे। एक terminal को text send करना चाहते हैं? इसकी file में write कीजिए। एक disk से raw data पढ़ना या output discard करना चाहते हैं? सही device file से पढ़िए या इसमें write कीजिए (जैसे /dev/null, वह 'इसे फेंक दो' file)। Programs को special cases नहीं चाहिए 'क्या यह एक file है या एक device?'; वे बस read और write करते हैं, और kernel appropriately इसे route करता है। यह uniformity है वजह Linux commands इतनी खूबसूरती से compose होती हैं: क्योंकि directories, documents, और devices सब same 'file' language बोलते हैं, एक के लिए built tools दूसरों पर काम करते हैं। यह एक single elegant abstraction है जो enormous complexity remove करता है, यही exactly वजह है 'everything is a file' को Unix और Linux के great design ideas में से एक माना जाता है। सब पर राज करने वाला एक interface।

Summary

Key takeaways

  • Linux एक 'everything is a file' philosophy follow करता है: data, directories, और यहाँ तक कि devices भी files की तरह access होते हैं।
  • Regular files data hold करती हैं: text files (human-readable) और binary files (programs जैसा machine data)।
  • Directories वे files हैं जिनके contents दूसरी files list करते हैं; यही तरीका है folders nest करने का।
  • Special files में device files (files की तरह hardware), symbolic links, named pipes, और sockets शामिल हैं।
  • एक ls -l line का पहला character type देता है: '-' regular, 'd' directory, 'l' link, 'c' char device, 'b' block device।
  • Devices को files की तरह treat करना same commands और read/write operations को पूरे system के across काम करने देता है।
  • Memory hook: पहले ls -l character पर एक glance आपको file type बताता है।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from Introduction to Linux Operating System

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati