[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-1-en-105":3,"doc-seo-573361-105":53,"doc-detail-573361-en":126},{"code":4,"msg":5,"data":6},0,"success",[7,14,19,24,29,34,39,44,49],{"id":8,"doc_module":9,"doc_module_name":10,"category_name":11,"show_sort_weight":12,"slug":13},11,1,"Template","Presentations",90,"presentations",{"id":15,"doc_module":9,"doc_module_name":10,"category_name":16,"show_sort_weight":17,"slug":18},12,"Resumes",80,"resumes",{"id":20,"doc_module":9,"doc_module_name":10,"category_name":21,"show_sort_weight":22,"slug":23},14,"Invoices",70,"invoices",{"id":25,"doc_module":9,"doc_module_name":10,"category_name":26,"show_sort_weight":27,"slug":28},15,"Posters",60,"posters",{"id":30,"doc_module":9,"doc_module_name":10,"category_name":31,"show_sort_weight":32,"slug":33},16,"Social Media",50,"social-media",{"id":35,"doc_module":9,"doc_module_name":10,"category_name":36,"show_sort_weight":37,"slug":38},17,"Forms",40,"forms",{"id":40,"doc_module":9,"doc_module_name":10,"category_name":41,"show_sort_weight":42,"slug":43},18,"Letters",30,"letters",{"id":45,"doc_module":9,"doc_module_name":10,"category_name":46,"show_sort_weight":47,"slug":48},21,"Paper Templates",5,"papers-templates",{"id":50,"doc_module":9,"doc_module_name":10,"category_name":51,"show_sort_weight":4,"slug":52},158,"General","general-158",{"code":4,"msg":54,"data":55},"ok",{"site_id":56,"language":57,"slug":58,"title":59,"keywords":60,"description":61,"schema_data":62,"social_meta":119,"head_meta":121,"extra_data":123,"updated_unix":125},105,"en","bash-redirections-cheat-sheet","Bash Redirections Cheat Sheet","","Bash Redirections Cheat Sheet provides a compact reference for redirecting standard input, standard output, and standard error in shell commands. It covers truncating and appending output to files, discarding streams with /dev/null, and combining stdout and stderr (including fd-based alternatives where order matters). The sheet also includes input redirection, here-documents, here-strings, exec-level persistent redirection, custom file descriptors, and advanced process substitution and pipelines.",{"@graph":63,"@context":118},[64,80,101],{"@type":65,"itemListElement":66},"BreadcrumbList",[67,71,74,77],{"item":68,"name":69,"@type":70,"position":9},"https://docshare.wps.com","Home","ListItem",{"item":72,"name":10,"@type":70,"position":73},"https://docshare.wps.com/template/",2,{"item":75,"name":11,"@type":70,"position":76},"https://docshare.wps.com/template/presentations/",3,{"item":78,"name":59,"@type":70,"position":79},"https://docshare.wps.com/template/bash-redirections-cheat-sheet/573361/",4,{"url":78,"name":59,"@type":81,"image":82,"author":87,"headline":59,"publisher":90,"fileFormat":93,"inLanguage":57,"description":61,"dateModified":94,"datePublished":95,"encodingFormat":93,"isAccessibleForFree":96,"interactionStatistic":97},"DigitalDocument",{"url":83,"@type":84,"width":85,"height":86},"https://docshare.wps.com/thumbnails/bash-redirections-cheat-sheet/573361.png","ImageObject",442,249,{"name":88,"@type":89},"Emma Wilson","Person",{"url":68,"name":91,"@type":92},"DocShare","Organization","application/pdf","2026-10-18","2026-10-14",true,{"@type":98,"interactionType":99,"userInteractionCount":76},"InteractionCounter",{"@type":100},"ViewAction",{"@type":102,"mainEntity":103},"FAQPage",[104,110,114],{"name":105,"@type":106,"acceptedAnswer":107},"How do I redirect standard output and standard error to different places in Bash?","Question",{"text":108,"@type":109},"Use fd-based redirection: `cmd > file` redirects stdout, and `cmd 2> file` redirects stderr. You can also redirect both by using combined forms such as `cmd &> file`.","Answer",{"name":111,"@type":106,"acceptedAnswer":112},"What is the difference between `cmd > file 2>&1` and `cmd 2>&1 > file`?",{"text":113,"@type":109},"They are not equivalent because redirection order matters. Set up the intended order so that the stream is redirected after the target mapping is established.",{"name":115,"@type":106,"acceptedAnswer":116},"Which constructs help send multiple lines or single text into a command’s stdin?",{"text":117,"@type":109},"Use a here-document `cmd \u003C\u003C EOL ... EOL` for multiple lines, and a here-string `cmd \u003C\u003C\u003C \"string\"` for a single line of text passed to stdin.","https://schema.org",{"og:url":78,"og:type":120,"og:title":59,"og:site_name":91,"og:description":61},"article",{"robots":122,"canonical":78},"index,follow",{"doc_id":124,"site_id":56},573361,1792019192,{"code":4,"msg":5,"data":127},{"doc_id":124,"user_id":128,"nickname":88,"user_avatar":129,"doc_module":9,"category_id":8,"category_name":11,"doc_title":59,"doc_description":61,"doc_content":130,"file_id":131,"file_url":132,"file_type":133,"file_size":134,"view_count":76,"is_deleted":4,"is_public":9,"is_downloadable":9,"audit_status":9,"page_count":9,"language":135,"language_code":57,"site_id":56,"html_lang":57,"table_of_contents":136,"faqs":137,"seo_title":138,"seo_description":61,"update_tm":139,"read_time":4},3848291630094,"https://eur-avatar.wpscdn.com/davatar_085a072bc5b1113ac321206ff7593b45","Bash Redirections Cheat Sheet  \n\n| Redirection | Description |\n| --- | --- |\n| cmd > file | Redirect the standard output (stdout) of cmd to a 􀀌le. |\n| cmd 1> file | Same as cmd > file. 1 is the default 􀀌le descriptor (fd) for stdout. |\n| cmd 2> file | Redirect the standard error (stderr) of cmd to a 􀀌le. 2 is the default fd for stderr. |\n| cmd >> file | Append stdout of cmd to a 􀀌le. |\n| cmd 2>> file | Append stderr of cmd to a 􀀌le. |\n| cmd &> file | Redirect stdout and stderr of cmd to a 􀀌le. |\n| cmd > file 2>&1 | Another way to redirect both stdout and stderr of cmd to a 􀀌le. This is not the same as cmd 2>&1 > file. Redirection order matters! |\n| cmd > /dev/null | Discard stdout of cmd. |\n| cmd 2> /dev/null | Discard stderr of cmd. |\n| cmd &> /dev/null | Discard stdout and stderr of cmd. |\n| cmd \u003C file | Redirect the contents of the 􀀌le to the standard input (stdin) of cmd. |\n| cmd \u003C\u003C EOL line1\u003Cbr>line2\u003Cbr>EOL | Redirect a bunch of lines to the stdin. If ' EOL ' is quoted, text is treated literally. This is called a here-document. |\n| cmd \u003C\u003C -EOL \u003Ctab>foo\u003Cbr>\u003Ctab>\u003Ctab>bar EOL | Redirect a bunch of lines to the stdin and strip the leading tabs. |\n| cmd \u003C\u003C\u003C \"string\" | Redirect a single line of text to the stdin of cmd. This is called a here-string. |\n| exec 2> file | Redirect stderr of all commands to a 􀀌le forever. |\n| exec 3\u003C file | Open a 􀀌le for reading using a custom 􀀌le descriptor. |\n| exec 3> file | Open a 􀀌le for writing using a custom 􀀌le descriptor. |\n| exec 3\u003C> file | Open a 􀀌le for reading and writing using a custom 􀀌le descriptor. |\n| exec 3>& - | Close a 􀀌le descriptor. |\n| exec 4>&3 | Make 􀀌le descriptor 4 to be a copy of 􀀌le descriptor 3. (Copy fd 3 to 4.) |\n| exec 4>&3- | Copy 􀀌le descriptor 3 to 4 and close 􀀌le descriptor 3. |\n| echo \"foo\" >&3 | Write to a custom 􀀌le descriptor. |\n| cat \u003C&3 | Read from a custom 􀀌le descriptor. |\n| (cmd1; cmd2) > file | Redirect stdout from multiple commands to a 􀀌le (using a sub-shell) . |\n| { cmd1; cmd2; } > file | Redirect stdout from multiple commands to a 􀀌le (faster; not using a sub-shell) . |\n| exec 3\u003C> /dev/tcp/host/port | Open a TCP connection to host:port. (This is a bash feature, not Linux feature) . |\n| exec 3\u003C> /dev/udp/host/port | Open a UDP connection to host:port. (This is a bash feature, not Linux feature) . |\n| cmd \u003C(cmd1) | Redirect stdout of cmd1 to an anonymous 􀀌fo, then pass the 􀀌fo to cmd as an argument. Useful when cmd doesn't read from stdin directly. |\n| cmd \u003C \u003C(cmd1) | Redirect stdout of cmd1 to an anonymous 􀀌fo, then redirect the 􀀌fo to stdin of cmd. Best example: diff \u003C(find /path1 | sort) \u003C(find /path2 | sort) . |\n| cmd \u003C(cmd1) \u003C(cmd2) | Redirect stdout of cmd1 and cmd2 to two anonymous 􀀌fos, then pass both 􀀌fos as arguments to cmd. |\n| cmd1 >(cmd2) | Run cmd2 with its stdin connected to an anonymous 􀀌fo, and pass the 􀀌lename of the pipe as an argument to cmd1 . |\n| cmd1 > >(cmd2) | Run cmd2 with its stdin connected to an anonymous 􀀌fo, then redirect stdout of cmd to this anonymous pipe. |\n| cmd1 | cmd2 | Redirect stdout of cmd1 to stdin of cmd2 . Pro-tip: This is the same as cmd1 > >(cmd2) , same as cmd2 \u003C \u003C(cmd1) , same as > >(cmd2) cmd1, same as \u003C \u003C(cmd1) cmd2 . |\n| cmd1 | & cmd2 | Redirect stdout and stderr of cmd1 to stdin of cmd2 (bash 4.0+ only) . Use cmd1 2>&1 | cmd2 for older bashes. |\n| cmd | tee file | Redirect stdout of cmd to a 􀀌le and print it to screen. |\n| exec {filew}> file | Open a 􀀌le for writing using a named 􀀌le descriptor called {filew} (bash 4.1+) . |\n| cmd 3>&1 1>&2 2>&3 | Swap stdout and stderr of cmd. |\n| cmd > >(cmd1) 2> >(cmd2) | Send stdout of cmd to cmd1 and stderr of cmd to cmd2 . |\n| cmd1 | cmd2 | cmd3 | cmd4 echo ${PIPESTATUS[@]} | Find out the exit codes of all piped commands. |\n\nI explained each one of these redirections in my article All About Bash Redirections:  \n[www.catonmat.net/blog/bash-one-liners-explained-part-three/](www.catonmat.net/blog/bash-one-liners-explained-part-three/)  \nDid I miss any redirectio","cbCaivsU5jzUp82d","https://ap.wps.com/l/cbCaivsU5jzUp82d","pdf",103691,"English","# Redirection operators\n## File descriptor and stream redirection\n## Input redirection and here-documents\n## Process substitution and pipelines\n## Miscellaneous redirection helpers","[{\"question\":\"How do I redirect standard output and standard error to different places in Bash?\",\"answer\":\"Use fd-based redirection: `cmd \\u003e file` redirects stdout, and `cmd 2\\u003e file` redirects stderr. You can also redirect both by using combined forms such as `cmd \\u0026\\u003e file`.\"},{\"question\":\"What is the difference between `cmd \\u003e file 2\\u003e\\u00261` and `cmd 2\\u003e\\u00261 \\u003e file`?\",\"answer\":\"They are not equivalent because redirection order matters. Set up the intended order so that the stream is redirected after the target mapping is established.\"},{\"question\":\"Which constructs help send multiple lines or single text into a command’s stdin?\",\"answer\":\"Use a here-document `cmd \\u003c\\u003c EOL ... EOL` for multiple lines, and a here-string `cmd \\u003c\\u003c\\u003c \\\"string\\\"` for a single line of text passed to stdin.\"}]","Bash Redirections Cheat Sheet | PDF",1791938003]