{"id":8725,"date":"2024-09-20T11:42:08","date_gmt":"2024-09-20T11:42:08","guid":{"rendered":"https:\/\/metaschool.so\/articles\/?p=8725"},"modified":"2024-12-06T07:26:32","modified_gmt":"2024-12-06T07:26:32","slug":"bash-commands","status":"publish","type":"post","link":"https:\/\/metaschool.so\/articles\/bash-commands\/","title":{"rendered":"Bash Commands Cheat Sheet"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_56_1 ez-toc-wrap-left counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#File_and_Directory_Operations\" title=\"File and Directory Operations\">File and Directory Operations<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#File_Viewing_and_Editing\" title=\"File Viewing and Editing\">File Viewing and Editing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#System_Information\" title=\"System Information\">System Information<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Permissions_and_Ownership\" title=\"Permissions and Ownership\">Permissions and Ownership<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Process_Management\" title=\"Process Management\">Process Management<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Networking\" title=\"Networking\">Networking<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#File_Search\" title=\"File Search\">File Search<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Archiving_and_Compression\" title=\"Archiving and Compression\">Archiving and Compression<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Shell_Scripting\" title=\"Shell Scripting\">Shell Scripting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Package_Management_UbuntuDebian\" title=\"Package Management (Ubuntu\/Debian)\">Package Management (Ubuntu\/Debian)<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Tips\" title=\"Tips\">Tips<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#Bash_in_AI\" title=\"Bash in AI\">Bash in AI<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/metaschool.so\/articles\/bash-commands\/#FAQs\" title=\"FAQs\">FAQs<\/a><\/li><\/ul><\/nav><\/div>\n\n<p><a href=\"https:\/\/opensource.com\/resources\/what-bash\" target=\"_blank\" rel=\"noopener\">Bash<\/a> (Bourne Again Shell) is a widely used command-line shell and scripting language for Linux, macOS, and other Unix-based systems. Use this guide as a handy cheat sheet of common Bash commands to help you navigate and manage your system efficiently.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"File_and_Directory_Operations\"><\/span><strong>File and Directory Operations<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>pwd<\/code><\/strong>: Displays the current working directory.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>ls<\/code><\/strong>: Lists files and directories in the current directory.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>cd<\/code><\/strong>: Changes the current directory.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  cd path\/to\/directory<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>mkdir<\/code><\/strong>: Creates a new directory.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  mkdir new_directory<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>rm<\/code><\/strong>: Deletes a file or directory (<code>-r<\/code> for directories, <code>-f<\/code> to force).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  rm file_name<br>  rm -rf directory_name<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>cp<\/code><\/strong>: Copies files or directories.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  cp source_file destination<br>  cp -r source_directory destination_directory<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>mv<\/code><\/strong>: Moves or renames files or directories.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  mv old_name new_name<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"File_Viewing_and_Editing\"><\/span><strong>File Viewing and Editing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>cat<\/code><\/strong>: Displays the content of a file.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  cat file.txt<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>less<\/code><\/strong>: Views file content one page at a time.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  less file.txt<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>nano<\/code><\/strong>: Opens the <code>nano<\/code> text editor to edit files.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  nano file.txt<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>touch<\/code><\/strong>: Creates a new empty file or updates the timestamp of an existing file.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  touch newfile.txt<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"System_Information\"><\/span><strong>System Information<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>uname -a<\/code><\/strong>: Shows detailed system information.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>top<\/code><\/strong>: Displays active processes and system usage in real-time.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>df -h<\/code><\/strong>: Shows available disk space in human-readable format.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>free -h<\/code><\/strong>: Displays available and used memory.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Permissions_and_Ownership\"><\/span><strong>Permissions and Ownership<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>chmod<\/code><\/strong>: Changes file or directory permissions.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  chmod 755 file.txt<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>chown<\/code><\/strong>: Changes file ownership.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  chown user:group file.txt<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>sudo<\/code><\/strong>: Runs commands with superuser privileges.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  sudo command<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Process_Management\"><\/span><strong>Process Management<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>ps<\/code><\/strong>: Lists running processes.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  ps aux<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>kill<\/code><\/strong>: Terminates a process by its PID (Process ID).<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  kill PID<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>bg<\/code><\/strong>: Resumes a suspended process in the background.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>fg<\/code><\/strong>: Brings a background process to the foreground.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Networking\"><\/span><strong>Networking<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>ping<\/code><\/strong>: Tests connectivity to a network host.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  ping google.com<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>ifconfig<\/code><\/strong>: Displays or configures network interfaces.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>curl<\/code><\/strong>: Transfers data from or to a server using different protocols.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  curl http:\/\/example.com<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"File_Search\"><\/span><strong>File Search<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>find<\/code><\/strong>: Searches for files and directories within a directory hierarchy.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  find \/path -name file.txt<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>grep<\/code><\/strong>: Searches for a pattern within files.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  grep 'pattern' file.txt<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Archiving_and_Compression\"><\/span><strong>Archiving and Compression<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>tar<\/code><\/strong>: Archives and compresses files.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  tar -czvf archive.tar.gz file_or_directory<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>unzip<\/code><\/strong>: Extracts compressed <code>.zip<\/code> files.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  unzip file.zip<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Shell_Scripting\"><\/span><strong>Shell Scripting<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>echo<\/code><\/strong>: Prints text or variables to the terminal.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  echo \"Hello, World!\"<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>alias<\/code><\/strong>: Creates a shortcut for a command.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  alias ll='ls -la'<\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>export<\/code><\/strong>: Sets environment variables.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  export PATH=$PATH:\/new\/path<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Package_Management_UbuntuDebian\"><\/span><strong>Package Management (Ubuntu\/Debian)<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>apt-get update<\/code><\/strong>: Updates the list of available packages.<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>apt-get install<\/code><\/strong>: Installs a package.<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">  sudo apt-get install package_name<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tips\"><\/span><strong>Tips<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use <code>tab<\/code> for auto-completion of file and directory names.<\/li>\n\n\n\n<li>Use <code>Ctrl+C<\/code> to stop a running process in the terminal.<\/li>\n\n\n\n<li>Use <code>Ctrl+Z<\/code> to suspend a process and <code>bg<\/code> to resume it in the background.<\/li>\n<\/ul>\n\n\n\n<p>Keep this cheat sheet handy to improve your efficiency when working with the Bash terminal!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Bash_in_AI\"><\/span>Bash in AI<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Bash is an essential skill for AI experts, as it plays a crucial role in several aspects of their work. It allows users to handle, process, and manipulate large datasets with ease. Automation is another key benefit; many AI workflows involve repetitive tasks like data preprocessing or model training, and Bash scripting can significantly streamline these processes, saving time and reducing the potential for errors.<\/p>\n\n\n\n<p>Bash knowledge is also important for setting up and managing development environments, including installing dependencies and configuring virtual environments, which are often critical for AI projects. Many popular AI tools and frameworks, such as TensorFlow and PyTorch, can be invoked and managed through the command line, making proficiency in Bash highly beneficial. <\/p>\n\n\n\n<p>Version control is integral to AI development, and Bash commands are commonly used alongside Git to track changes and collaborate effectively. Overall, while Bash may not be the core focus of AI, it enhances productivity and efficiency in managing the tasks and environments essential for successful AI development.<\/p>\n\n\n\n<p>For more insights on learning AI, check out our article: <a href=\"https:\/\/metaschool.so\/articles\/how-to-learn-ai\/\">How to Learn AI For Free: 2024 Guide From the AI Experts<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"FAQs\"><\/span>FAQs<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1726832027227\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is Bash and why is it important?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Bash (Bourne Again Shell) is a command-line interface and scripting language widely used in Unix-based systems like Linux and macOS. It allows users to interact with the operating system, automate tasks, manage files, and run scripts, making it essential for system administrators and developers.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1726832037708\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \"><strong>How can I view hidden files in a directory using Bash?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>To view hidden files (which start with a dot), use <code>ls -a<\/code>. This will display all files, including hidden ones, in the directory.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1726832061572\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">What is the difference between <code>&gt;<\/code> and <code>&gt;&gt;<\/code> in Bash?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The <code>&gt;<\/code> operator overwrites a file with new content, while <code>&gt;&gt;<\/code> appends the new content to the end of the file. <\/p>\n<p>For example:<br \/><code>echo \"Hello\" &gt; file.txt # Overwrites file<br \/>echo \"World\" &gt;&gt; file.txt # Appends to file<\/code><\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":19,"featured_media":10975,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","footnotes":""},"categories":[342],"tags":[],"class_list":["post-8725","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software-development"],"_links":{"self":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/8725","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/comments?post=8725"}],"version-history":[{"count":8,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/8725\/revisions"}],"predecessor-version":[{"id":8760,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/posts\/8725\/revisions\/8760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media\/10975"}],"wp:attachment":[{"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/media?parent=8725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/categories?post=8725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/metaschool.so\/articles\/wp-json\/wp\/v2\/tags?post=8725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}