[{"data":1,"prerenderedAt":736},["ShallowReactive",2],{"\u002F2025\u002F2-dev-null-command-what-is-and-what-is-useful":3,"surround-\u002F2025\u002F2-dev-null-command-what-is-and-what-is-useful":727},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"updated":10,"image":11,"categories":12,"tags":14,"recommend":6,"draft":6,"readingTime":15,"body":20,"_type":720,"_id":721,"_source":722,"_file":723,"_stem":724,"_extension":725,"_original_dir":726},"\u002F2025\u002F2-dev-null-command-what-is-and-what-is-useful","2025",false,"","What is the 2>\u002Fdev\u002Fnull Command and What Does It Do?","You might have seen this command in many places, and it might seem complex at first. But don't worry, in this content, we'll cover the basics and clarify the questions in our minds.","2025-05-03T12:55:53.000Z","https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F1.jpg",[13],"Linux",[],{"text":16,"minutes":17,"time":18,"words":19},"4 min read",3.9,234000,780,{"type":21,"children":22,"toc":706},"root",[23,53,95,100,107,113,182,208,213,224,228,263,301,307,336,341,348,353,357,386,392,397,437,474,480,485,489,512,518,523,527,540,546,551,555,584,590,610,633,637,642,700],{"type":24,"tag":25,"props":26,"children":27},"element","p",{},[28,31,37,39,44,46,51],{"type":29,"value":30},"text","In Linux, ",{"type":24,"tag":32,"props":33,"children":34},"strong",{},[35],{"type":29,"value":36},"STDIN",{"type":29,"value":38},", ",{"type":24,"tag":32,"props":40,"children":41},{},[42],{"type":29,"value":43},"STDOUT",{"type":29,"value":45},", and ",{"type":24,"tag":32,"props":47,"children":48},{},[49],{"type":29,"value":50},"STDERR",{"type":29,"value":52}," are standard file descriptors representing a program's input and output streams. Each is represented by a number:",{"type":24,"tag":54,"props":55,"children":56},"ul",{},[57,73,84],{"type":24,"tag":58,"props":59,"children":60},"li",{},[61,71],{"type":24,"tag":62,"props":63,"children":68},"span",{"className":64,"id":66,"style":67},[65],"example-info","just-like-this","color: #00bb66",[69],{"type":29,"value":70},"STDIN (0)",{"type":29,"value":72}," - Standard Input: Typically data coming from the keyboard.",{"type":24,"tag":58,"props":74,"children":75},{},[76,82],{"type":24,"tag":62,"props":77,"children":79},{"className":78,"id":66,"style":67},[65],[80],{"type":29,"value":81},"STDOUT (1)",{"type":29,"value":83}," - Standard Output: The program's normal output, usually written to the screen.",{"type":24,"tag":58,"props":85,"children":86},{},[87,93],{"type":24,"tag":62,"props":88,"children":90},{"className":89,"id":66,"style":67},[65],[91],{"type":29,"value":92},"STDERR (2)",{"type":29,"value":94}," - Standard Error: Where error messages are output, usually written to the screen.",{"type":24,"tag":25,"props":96,"children":97},{},[98],{"type":29,"value":99},"Yes, these might be confusing at first, but don't worry. We'll understand their meaning and how they work better with examples now. Let's begin;",{"type":24,"tag":101,"props":102,"children":104},"h3",{"id":103},"stdin-and-stdout",[105],{"type":29,"value":106},"STDIN and STDOUT",{"type":24,"tag":108,"props":109,"children":112},"pic",{"src":110,":zoom":111},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F2.jpg","true",[],{"type":24,"tag":25,"props":114,"children":115},{},[116,118,125,127,133,135,139,141,157,159,166,168,174,176,180],{"type":29,"value":117},"Now, in this command, ",{"type":24,"tag":119,"props":120,"children":122},"code",{"className":121},[],[123],{"type":29,"value":124},"echo",{"type":29,"value":126}," is our application. ",{"type":24,"tag":119,"props":128,"children":130},{"className":129},[],[131],{"type":29,"value":132},"\"hello\"",{"type":29,"value":134}," is our standard input, i.e., ",{"type":24,"tag":32,"props":136,"children":137},{},[138],{"type":29,"value":70},{"type":29,"value":140},". Similarly, when we enter this command, meaning ",{"type":24,"tag":119,"props":142,"children":145},{"className":143,"language":144,"style":7},"language-bash shiki shiki-themes catppuccin-latte one-dark-pro","bash",[146,151],{"type":24,"tag":62,"props":147,"children":149},{"style":148},"--shiki-default:#D20F39;--shiki-default-font-style:italic;--shiki-dark:#56B6C2;--shiki-dark-font-style:inherit",[150],{"type":29,"value":124},{"type":24,"tag":62,"props":152,"children":154},{"style":153},"--shiki-default:#40A02B;--shiki-dark:#98C379",[155],{"type":29,"value":156}," \"hello\"",{"type":29,"value":158},", and press the ",{"type":24,"tag":160,"props":161,"children":163},"key",{"code":162},"enter",[164],{"type":29,"value":165},"Enter",{"type":29,"value":167}," key, we get ",{"type":24,"tag":119,"props":169,"children":171},{"className":170},[],[172],{"type":29,"value":173},"hello",{"type":29,"value":175}," as our standard output, i.e., ",{"type":24,"tag":32,"props":177,"children":178},{},[179],{"type":29,"value":81},{"type":29,"value":181},".",{"type":24,"tag":183,"props":184,"children":186},"alert",{"type":185},"info",[187,196],{"type":24,"tag":188,"props":189,"children":190},"template",{"v-slot:title":7},[191],{"type":24,"tag":25,"props":192,"children":193},{},[194],{"type":29,"value":195},"Info",{"type":24,"tag":25,"props":197,"children":198},{},[199,201,206],{"type":29,"value":200},"The ",{"type":24,"tag":119,"props":202,"children":204},{"className":203},[],[205],{"type":29,"value":124},{"type":29,"value":207}," command is basically used to print the given text or variables to the standard output (usually the screen).",{"type":24,"tag":101,"props":209,"children":211},{"id":210},"stderr",[212],{"type":29,"value":50},{"type":24,"tag":25,"props":214,"children":215},{},[216,218,222],{"type":29,"value":217},"Now let's touch upon our third standard, ",{"type":24,"tag":32,"props":219,"children":220},{},[221],{"type":29,"value":92},{"type":29,"value":223},". For this, we need to enter a command that returns an error message. Let's look at the example below.",{"type":24,"tag":108,"props":225,"children":227},{"src":226},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F3.jpg",[],{"type":24,"tag":25,"props":229,"children":230},{},[231,233,239,241,247,249,253,255,261],{"type":29,"value":232},"In this example, we used the ",{"type":24,"tag":119,"props":234,"children":236},{"className":235},[],[237],{"type":29,"value":238},"ls -la hello.txt",{"type":29,"value":240}," command to search for the hello.txt file in the directory. I don't actually have a file named ",{"type":24,"tag":119,"props":242,"children":244},{"className":243},[],[245],{"type":29,"value":246},"hello.txt",{"type":29,"value":248}," in my directory. That's precisely our goal – to get an error. As you can see, we received a standard error ",{"type":24,"tag":32,"props":250,"children":251},{},[252],{"type":29,"value":92},{"type":29,"value":254}," like ",{"type":24,"tag":119,"props":256,"children":258},{"className":257},[],[259],{"type":29,"value":260},"ls: cannot access 'hello.txt': No such file or directory",{"type":29,"value":262},". As you understand, this is a standard error.",{"type":24,"tag":183,"props":264,"children":266},{"type":265},"warning",[267,275],{"type":24,"tag":188,"props":268,"children":269},{"v-slot:title":7},[270],{"type":24,"tag":25,"props":271,"children":272},{},[273],{"type":29,"value":274},"Warning",{"type":24,"tag":25,"props":276,"children":277},{},[278,280,285,287,292,294,299],{"type":29,"value":279},"This command ",{"type":24,"tag":119,"props":281,"children":283},{"className":282},[],[284],{"type":29,"value":238},{"type":29,"value":286}," is used to list the detailed information (permissions, owner, size, last modified date, etc.) of the ",{"type":24,"tag":119,"props":288,"children":290},{"className":289},[],[291],{"type":29,"value":246},{"type":29,"value":293}," file and does not use any standard input (STDIN). ",{"type":24,"tag":119,"props":295,"children":297},{"className":296},[],[298],{"type":29,"value":246},{"type":29,"value":300}," is a file that this command processes, not standard input.",{"type":24,"tag":101,"props":302,"children":304},{"id":303},"redirection",[305],{"type":29,"value":306},"Redirection",{"type":24,"tag":25,"props":308,"children":309},{},[310,312,316,317,321,322,326,328,334],{"type":29,"value":311},"Now that we've learned the concepts of ",{"type":24,"tag":32,"props":313,"children":314},{},[315],{"type":29,"value":36},{"type":29,"value":38},{"type":24,"tag":32,"props":318,"children":319},{},[320],{"type":29,"value":43},{"type":29,"value":45},{"type":24,"tag":32,"props":323,"children":324},{},[325],{"type":29,"value":50},{"type":29,"value":327},", let's move on to the redirection step to explain the ",{"type":24,"tag":119,"props":329,"children":331},{"className":330,"id":66,"style":67},[65],[332],{"type":29,"value":333},"2>\u002Fdev\u002Fnull",{"type":29,"value":335}," concept.",{"type":24,"tag":25,"props":337,"children":338},{},[339],{"type":29,"value":340},"Redirection is the process of changing the default sources (keyboard) or destinations (screen) of these standard streams. It's often used to connect files or other commands to these streams. It's done using special characters:",{"type":24,"tag":342,"props":343,"children":345},"h4",{"id":344},"_1-input-redirection",[346],{"type":29,"value":347},"1. Input Redirection (\u003C)",{"type":24,"tag":25,"props":349,"children":350},{},[351],{"type":29,"value":352},"Takes a command's STDIN from a file instead of the keyboard.",{"type":24,"tag":108,"props":354,"children":356},{"src":355},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F4.jpg",[],{"type":24,"tag":25,"props":358,"children":359},{},[360,362,368,370,376,378,384],{"type":29,"value":361},"It takes the input for the ",{"type":24,"tag":119,"props":363,"children":365},{"className":364},[],[366],{"type":29,"value":367},"cat",{"type":29,"value":369}," command from the ",{"type":24,"tag":119,"props":371,"children":373},{"className":372},[],[374],{"type":29,"value":375},"text.txt",{"type":29,"value":377}," file and writes its content to STDOUT (the screen). This does the same thing as ",{"type":24,"tag":119,"props":379,"children":381},{"className":380},[],[382],{"type":29,"value":383},"cat text.txt",{"type":29,"value":385}," but demonstrates how redirection works.",{"type":24,"tag":342,"props":387,"children":389},{"id":388},"_2-output-redirection-and",[390],{"type":29,"value":391},"2. Output Redirection (> and >>)",{"type":24,"tag":25,"props":393,"children":394},{},[395],{"type":29,"value":396},"Redirects a command's STDOUT to a file instead of the screen.",{"type":24,"tag":398,"props":399,"children":400},"blockquote",{},[401,412,416],{"type":24,"tag":25,"props":402,"children":403},{},[404,410],{"type":24,"tag":62,"props":405,"children":407},{"className":406,"id":66,"style":67},[65],[408],{"type":29,"value":409},"Overwrite (>)",{"type":29,"value":411},": If the target file exists, its content is deleted, and the command's output is written. If the file doesn't exist, it's created.",{"type":24,"tag":108,"props":413,"children":415},{"src":414},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F5.jpg",[],{"type":24,"tag":25,"props":417,"children":418},{},[419,421,427,429,435],{"type":29,"value":420},"The output of the ",{"type":24,"tag":119,"props":422,"children":424},{"className":423},[],[425],{"type":29,"value":426},"ls -la",{"type":29,"value":428}," command is not written to the screen. Instead, it's written to the file named ",{"type":24,"tag":119,"props":430,"children":432},{"className":431},[],[433],{"type":29,"value":434},"list.txt",{"type":29,"value":436},". If the file already exists, its old content is lost.",{"type":24,"tag":398,"props":438,"children":439},{},[440,451,455],{"type":24,"tag":25,"props":441,"children":442},{},[443,449],{"type":24,"tag":62,"props":444,"children":446},{"className":445,"id":66,"style":67},[65],[447],{"type":29,"value":448},"Append (>>)",{"type":29,"value":450},": If the target file exists, the command's output is appended to the end of the file. If the file doesn't exist, it's created.",{"type":24,"tag":108,"props":452,"children":454},{"src":453},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F6.jpg",[],{"type":24,"tag":25,"props":456,"children":457},{},[458,459,464,466,472],{"type":29,"value":420},{"type":24,"tag":119,"props":460,"children":462},{"className":461},[],[463],{"type":29,"value":124},{"type":29,"value":465}," command (System stopped!) is appended to the end of the ",{"type":24,"tag":119,"props":467,"children":469},{"className":468},[],[470],{"type":29,"value":471},"system.log",{"type":29,"value":473}," file. The previous content of the file is preserved.",{"type":24,"tag":342,"props":475,"children":477},{"id":476},"_3-error-redirection-2-and-2",[478],{"type":29,"value":479},"3. Error Redirection (2> and 2>>)",{"type":24,"tag":25,"props":481,"children":482},{},[483],{"type":29,"value":484},"Redirects a command's STDERR (error messages) to a file instead of the screen. This is done using file descriptor 2.",{"type":24,"tag":108,"props":486,"children":488},{"src":487},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F7.jpg",[],{"type":24,"tag":25,"props":490,"children":491},{},[492,494,499,501],{"type":29,"value":493},"As before, I don't have a file named ",{"type":24,"tag":119,"props":495,"children":497},{"className":496},[],[498],{"type":29,"value":246},{"type":29,"value":500}," in my directory, so I will get an error, and this error will be written to the file I specified, not to the screen. I achieved this by redirecting STDERR (2). ",{"type":24,"tag":62,"props":502,"children":505},{"className":503,"id":66,"style":504},[65],"color:rgb(0, 187, 143)",[506],{"type":24,"tag":119,"props":507,"children":509},{"className":508},[],[510],{"type":29,"value":511},"We use numbers when redirecting!",{"type":24,"tag":342,"props":513,"children":515},{"id":514},"_4-redirecting-output-and-error-together",[516],{"type":29,"value":517},"4. Redirecting Output and Error Together",{"type":24,"tag":25,"props":519,"children":520},{},[521],{"type":29,"value":522},"Sometimes you might want to redirect both normal output (STDOUT) and errors (STDERR) to the same file.",{"type":24,"tag":108,"props":524,"children":526},{"src":525},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F8.jpg",[],{"type":24,"tag":25,"props":528,"children":529},{},[530,532,538],{"type":29,"value":531},"In this case, it redirects the compilation output, STDOUT (1), to ",{"type":24,"tag":119,"props":533,"children":535},{"className":534},[],[536],{"type":29,"value":537},"build.log",{"type":29,"value":539},". It also redirects errors, STDERR (2), to where STDOUT (1) is currently being redirected (i.e., to build.log).",{"type":24,"tag":342,"props":541,"children":543},{"id":542},"_5-pipeline-pipe",[544],{"type":29,"value":545},"5. Pipeline ( | ) - Pipe",{"type":24,"tag":25,"props":547,"children":548},{},[549],{"type":29,"value":550},"While not technically redirection, it's closely related to streams. It connects the STDOUT of one command to the STDIN of another command. It allows you to chain commands.",{"type":24,"tag":108,"props":552,"children":554},{"src":553},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F9.jpg",[],{"type":24,"tag":25,"props":556,"children":557},{},[558,560,566,568,574,576,582],{"type":29,"value":559},"In this example, the files in the ",{"type":24,"tag":119,"props":561,"children":563},{"className":562},[],[564],{"type":29,"value":565},"\u002Fetc",{"type":29,"value":567}," directory are listed, and this list is written to STDOUT. Then, using ",{"type":24,"tag":119,"props":569,"children":571},{"className":570},[],[572],{"type":29,"value":573},"|",{"type":29,"value":575},", the STDOUT of the ",{"type":24,"tag":119,"props":577,"children":579},{"className":578},[],[580],{"type":29,"value":581},"ls",{"type":29,"value":583}," command is taken and written as input (STDIN) to the grep tool. Subsequently, grep filters this input and writes its own STDOUT (to the screen).",{"type":24,"tag":101,"props":585,"children":587},{"id":586},"conclusion-2devnull",[588],{"type":29,"value":589},"Conclusion: \"2>\u002Fdev\u002Fnull\"",{"type":24,"tag":25,"props":591,"children":592},{},[593,595,600,602,608],{"type":29,"value":594},"We've thoroughly learned every detail up to this point. Now let's explain the ",{"type":24,"tag":119,"props":596,"children":598},{"className":597,"id":66,"style":67},[65],[599],{"type":29,"value":333},{"type":29,"value":601}," concept. Of course, before that, we need to understand the ",{"type":24,"tag":119,"props":603,"children":605},{"className":604},[],[606],{"type":29,"value":607},"\u002Fdev\u002Fnull",{"type":29,"value":609}," device.",{"type":24,"tag":183,"props":611,"children":612},{},[613,628],{"type":24,"tag":188,"props":614,"children":615},{"v-slot:title":7},[616],{"type":24,"tag":25,"props":617,"children":618},{},[619,621,626],{"type":29,"value":620},"What is the ",{"type":24,"tag":119,"props":622,"children":624},{"className":623},[],[625],{"type":29,"value":607},{"type":29,"value":627}," device?",{"type":24,"tag":25,"props":629,"children":630},{},[631],{"type":29,"value":632},"In short, it can be thought of as the \"system trash can\" or \"bit bucket\". Theoretically, it's an abstraction that allows data to be sent to nothingness. In summary, \u002Fdev\u002Fnull is like a \"virtual black hole where you throw data you want to discard\".",{"type":24,"tag":108,"props":634,"children":636},{"src":635},"https:\u002F\u002Fhackpaper-image-server.pages.dev\u002Fimages\u002Fblogs\u002F2-dev-null-command-what-is-and-what-is-useful\u002F10.jpg",[],{"type":24,"tag":25,"props":638,"children":639},{},[640],{"type":29,"value":641},"Now let's break it down point by point;",{"type":24,"tag":643,"props":644,"children":645},"ol",{},[646,657,676,688],{"type":24,"tag":58,"props":647,"children":648},{},[649,655],{"type":24,"tag":119,"props":650,"children":652},{"className":651},[],[653],{"type":29,"value":654},"command",{"type":29,"value":656}," means it can be any command.",{"type":24,"tag":58,"props":658,"children":659},{},[660,662,666,668,674],{"type":29,"value":661},"As we learned, ",{"type":24,"tag":32,"props":663,"children":664},{},[665],{"type":29,"value":92},{"type":29,"value":667}," is being redirected using the ",{"type":24,"tag":119,"props":669,"children":671},{"className":670},[],[672],{"type":29,"value":673},">",{"type":29,"value":675}," symbol.",{"type":24,"tag":58,"props":677,"children":678},{},[679,681,687],{"type":29,"value":680},"The redirection target is set to ",{"type":24,"tag":119,"props":682,"children":685},{"className":683,"id":66,"style":684},[65],"color:rgb(187, 28, 0)",[686],{"type":29,"value":607},{"type":29,"value":181},{"type":24,"tag":58,"props":689,"children":690},{},[691,693,698],{"type":29,"value":692},"This means that when this redirection is used after any command, our errors (STDERR - 2) are redirected to ",{"type":24,"tag":119,"props":694,"children":696},{"className":695},[],[697],{"type":29,"value":607},{"type":29,"value":699},", i.e., to an irretrievable void (discarded).",{"type":24,"tag":701,"props":702,"children":703},"style",{},[704],{"type":29,"value":705},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":707,"depth":707,"links":708},4,[709,711,712,719],{"id":103,"depth":710,"text":106},3,{"id":210,"depth":710,"text":50},{"id":303,"depth":710,"text":306,"children":713},[714,715,716,717,718],{"id":344,"depth":707,"text":347},{"id":388,"depth":707,"text":391},{"id":476,"depth":707,"text":479},{"id":514,"depth":707,"text":517},{"id":542,"depth":707,"text":545},{"id":586,"depth":710,"text":589},"markdown","content:posts:2025:2-dev-null-command-what-is-and-what-is-useful.md","content","posts\u002F2025\u002F2-dev-null-command-what-is-and-what-is-useful.md","posts\u002F2025\u002F2-dev-null-command-what-is-and-what-is-useful","md","\u002Fposts",[728,732],{"_path":729,"title":730,"date":731},"\u002F2025\u002Ffile-permissions-and-management-in-linux","File Permissions and Permission Management in Linux","2025-05-03T08:11:08.000Z",{"_path":733,"title":734,"date":735},"\u002F2025\u002Fwhat-is-a-proxy","What is a Proxy?","2025-08-07T08:58:18.000Z",1777022959578]