{"id":451,"date":"2022-02-25T04:39:09","date_gmt":"2022-02-25T04:39:09","guid":{"rendered":"http:\/\/miriamposner.com\/classes\/is270s23\/?page_id=451"},"modified":"2023-05-25T16:17:10","modified_gmt":"2023-05-25T16:17:10","slug":"getting-started-with-the-command-line-mac","status":"publish","type":"page","link":"http:\/\/miriamposner.com\/classes\/is270s23\/resources\/command-line-unix\/getting-started-with-the-command-line-mac\/","title":{"rendered":"Getting started with the command line"},"content":{"rendered":"\n<p>Every Mac comes equipped with a program called&nbsp;<strong>Terminal.<\/strong>&nbsp;This program allows you to communicate via typing with your Unix operating system. (Sometimes people call this&nbsp;<strong>using the command line.<\/strong>) <\/p>\n\n\n\n<p>PCs don&#8217;t use Unix operating systems, but you can download programs that allow you to interact with your computer in the same way. When you downloaded <a rel=\"noreferrer noopener\" href=\"https:\/\/gitforwindows.org\/\" target=\"_blank\">Git for Windows<\/a>, the download included a program called <strong>Git Bash<\/strong>, which will allow you to interact with your PC using textual commands, just like on Unix-based systems.<\/p>\n\n\n\n<p>Why would you want to do this? While graphical user interfaces (GUIs) are convenient, using the command line allows you to perform actions programmatically and to chain actions together so that, in many cases, you can perform a task much more quickly (or, in some cases, at all). Plus you look cool.<\/p>\n\n\n\n<p>You&#8217;ll hear the terms terminal, bash, shell, CLI, command line, and Unix used frequently (and often overlapping) to refer to this kind of work.&nbsp;<a href=\"https:\/\/www.geeksforgeeks.org\/difference-between-terminal-console-shell-and-command-line\/\">Here&#8217;s an explanation of these terms<\/a>. For now, it&#8217;s really just important to know that we&#8217;re working in the shell.<\/p>\n\n\n\n<p class=\"has-yellow-background-color has-background\">Before we get started, download <a href=\"https:\/\/www.dropbox.com\/s\/x0i689m2lfivb3i\/commandline.zip?dl=1\">t<\/a><a rel=\"noreferrer noopener\" href=\"https:\/\/www.dropbox.com\/s\/az13rafkll81a6t\/commandline%202.zip?dl=1\" target=\"_blank\">his file<\/a> of sample data and <strong>decompress<\/strong> it. (On a PC, the process of decompression is called &#8220;extraction,&#8221; and <a rel=\"noreferrer noopener\" href=\"https:\/\/support.microsoft.com\/en-us\/windows\/zip-and-unzip-files-f6dde0a7-0fec-8294-e1d3-703ed85e7ebc#:~:text=zipped)%20folder.-,To%20unzip%20files,-Open%20File%20Explorer\" target=\"_blank\">here&#8217;s<\/a> how you do it.) Make sure you&#8217;ll be able to find the folder again later.<a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#1-open-your-terminal\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Open your shell<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-0.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-0.jpeg\" alt=\"Open your terminal\"\/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">On a Mac: <\/h4>\n\n\n\n<p>To get started, use your computer&#8217;s search function (or press&nbsp;<strong>command<\/strong>&nbsp;and the&nbsp;<strong>space bar<\/strong>) and search for the terminal. (You can also open it by looking in your computer&#8217;s <strong>Utilities<\/strong> folder.)<\/p>\n\n\n\n<p>Then open it!<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">On a PC: <\/h4>\n\n\n\n<p>Locate the program called Git Bash. If you kept all the default settings during installation, it should be available on your Start menu. If it&#8217;s not there, use your computer&#8217;s search function to locate Git Bash. Going forward, you&#8217;ll mostly see images of the Mac&#8217;s terminal, but these instructions should also work on Git Bash.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">On a Chromebook: <\/h4>\n\n\n\n<p>Please follow the instructions <a rel=\"noreferrer noopener\" href=\"https:\/\/melaniewalsh.github.io\/Intro-Cultural-Analytics\/01-Command-Line\/01-The-Command-Line.html#chromebook\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#2-what-are-we-looking-at\"><\/a>2. What are we looking at?<\/h2>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-1.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-1.jpeg\" alt=\"What are we looking at?\"\/><\/a><figcaption class=\"wp-element-caption\">Terminal on a Mac<\/figcaption><\/figure>\n<\/div>\n\n\n<p>This is a terminal window, also called a shell! It has a&nbsp;<strong>command prompt<\/strong>&nbsp;waiting for you to tell it what to do. You can tell it&#8217;s waiting for you to type something because it displays a&nbsp;<strong>%<\/strong>&nbsp;(or a&nbsp;<strong>$<\/strong>, they mean the same thing).<\/p>\n\n\n\n<p>To work in the shell, you&#8217;ll type out a command and then press return. Let&#8217;s try our first command. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>whoami <\/code><\/pre>\n\n\n\n<p>and press <strong>return<\/strong>. The terminal returns your username. (Mine&#8217;s miriamposner.)<\/p>\n\n\n\n<p>And now the command prompt displays again, ready for you to issue your next instruction. <\/p>\n\n\n\n<p>(You don&#8217;t need to delete previous commands; you can just keep going, and as you go, you&#8217;ll be able to scroll backwards to see what you&#8217;ve already typed.)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#3-say-hello\"><\/a>3. Say hello<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-2.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-2.jpeg\" alt=\"Say hello\"\/><\/a><\/figure>\n\n\n\n<p>This is another easy one. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo 'Hello world'<\/code><\/pre>\n\n\n\n<p>and press return. The command&nbsp;<strong>echo<\/strong>&nbsp;instructs the terminal to repeat whichever characters you include in the quotation marks.<\/p>\n\n\n\n<p>Great! Now you should see the command prompt again.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#4-getting-around-in-the-terminal\"><\/a>4. Getting around in the terminal<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-3.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-3.jpeg\" alt=\"Getting around in the terminal\"\/><\/a><\/figure>\n\n\n\n<p>As you&#8217;ve probably already noticed, you can&#8217;t do too much in the terminal using your mouse. Instead, the terminal awaits typed commands. Here are some keyboard shortcuts that may make your life a little easier:<\/p>\n\n\n\n<p>Use the&nbsp;<strong>up and down arrows<\/strong>&nbsp;on your keyboard to move back (up) and forward (down) through the previous commands you typed. This often saves you typing. Try pressing the up arrow once to rewind to the&nbsp;<strong>echo<\/strong>&nbsp;command you typed earlier. Then use the left and right arrows to delete the current contents of the quotation marks, replacing them with whatever you want. Then press&nbsp;<strong>return<\/strong>.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To move to the start of a line: hold down the&nbsp;<strong>control<\/strong>&nbsp;key and then press&nbsp;<strong>a<\/strong><\/li>\n\n\n\n<li>To move to the end of a line:&nbsp;<strong>control e<\/strong><\/li>\n\n\n\n<li>To clear the screen: type&nbsp;<strong>clear<\/strong>&nbsp;into the terminal and press return<\/li>\n\n\n\n<li>If you press enter and the terminal window displays a <strong>&gt;<\/strong> but does nothing else, it&#8217;s awaiting your input. If you didn&#8217;t mean to do this, type <strong>control c<\/strong> to exit the process<\/li>\n\n\n\n<li>To quit: type&nbsp;<strong>exit<\/strong>&nbsp;or just close the window (but don&#8217;t do that yet!!)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#5-get-your-bearings-1\"><\/a>5. Get your bearings (1)<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-4.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-4.jpeg\" alt=\"Get your bearings (1)\"\/><\/a><\/figure>\n\n\n\n<p>When you&#8217;re using the terminal, you&#8217;re always working from somewhere on your computer. In order to understand where that is, you need to learn a little bit about&nbsp;<strong>paths<\/strong>.<\/p>\n\n\n\n<p>Your computer&#8217;s file system is an upside-down tree. The root is your hard drive. In the next set of branches come a set of folders (also called &#8220;directories&#8221;) that are used by everyone who uses your computer. In the folder called&nbsp;<strong>users<\/strong>&nbsp;are folders for different user profiles (the desktop you see when you log into your computer), and beneath that, usually, is a set of folders associated with your user profile, including Applications, Desktop, Documents, Downloads, etc. Each of these folders hold their own files or folders, each of&nbsp;<em>these<\/em>&nbsp;folders might contain their own folders, and so on. <\/p>\n\n\n\n<p>Your computer might be set up differently from mine, with different folders, but the idea is the same.<\/p>\n\n\n\n<p>When you move up and down the tree, you&#8217;re moving closer or farther from the root, along the different branches.<\/p>\n\n\n\n<p>By default, when you use the terminal, you&#8217;re dropped just below the root, into the folder for your user profile.<\/p>\n\n\n\n<p>In the image above, the circles represent folders (AKA directories) and the uncircled nodes represent individual files.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#6-get-your-bearings-2\"><\/a>6. Get your bearings (2)<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-5.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-5.jpeg\" alt=\"Get your bearings (2)\"\/><\/a><\/figure>\n\n\n\n<p>Let&#8217;s make this more concrete. In the terminal window, type this command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwd<\/code><\/pre>\n\n\n\n<p>(That stands for &#8220;print working directory.&#8221;) You should see something like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/Users\/miriamposner\n<\/code><\/pre>\n\n\n\n<p>This is called a path! That&#8217;s because it leads to your location. When you see a backslash (<strong>\/<\/strong>) at the start of a path, that stands for the root of your computer. Subsequent slashes indicate that you&#8217;re moving into a subfolder. So, in the path above, I&#8217;m in the <strong>miriamposner<\/strong> folder, which is inside the <strong>Users<\/strong> folder, which is located at the <strong>root<\/strong> of my computer! You should be in the folder associated with the name of your own profile. (But if you&#8217;re not, it&#8217;s not a big deal!)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#7-meet-your-neighbors\"><\/a>7. Meet your neighbors<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-6.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-6.jpeg\" alt=\"Meet your neighbors\"\/><\/a><\/figure>\n\n\n\n<p>Let&#8217;s see what&#8217;s in the same folder as you. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls<\/code><\/pre>\n\n\n\n<p>and press return. (By the way, that&#8217;s an &#8220;L&#8221; in the above code, not the number one!) This command means &#8220;list&#8221; and it will list your cohabitants within the folder for your user profile. (Hmm, I really need to clean out my computer! What even are those folders?)<\/p>\n\n\n\n<p>You&#8217;ll probably see a list of folders like those in the image. Generally, you can tell you&#8217;re looking at a folder because the name is not followed by a file extension (e.g., .doc, .xls, .txt). A name followed by a file extension usually indicates that you&#8217;re looking at a file. If you want to be sure about what you&#8217;re looking at, type <code><strong>ls -al<\/strong><\/code> to see detailed information about each item in the folder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#8-move-down-the-tree\"><\/a>8. Move down the tree<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-7.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-7.jpeg\" alt=\"Move down the tree\"\/><\/a><\/figure>\n\n\n\n<p>Now that we know where we are, let&#8217;s try moving down our branch. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd Desktop<\/code><\/pre>\n\n\n\n<p>(Or the name of another folder at the same level as you.) Better yet, type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd Desk<\/code><\/pre>\n\n\n\n<p>and then press the tab key. The terminal will autocomplete for you! Then press <strong>return<\/strong>. <\/p>\n\n\n\n<p>(It won&#8217;t autocomplete if you just type <strong>D<\/strong>, however. That&#8217;s because you&#8217;re not being specific enough; you have both a <strong>D<\/strong>esktop folder and a<strong> D<\/strong>ownloads folder. You might see a list of possible options; keep pressing <strong>tab<\/strong> until the folder you want is selected.)<\/p>\n\n\n\n<p>The command&nbsp;<strong>cd<\/strong>&nbsp;stands for &#8220;change directory,&#8221; and it will take you into the folder you specify. When we navigate around the file system that way, we say that we&#8217;re using&nbsp;<strong>relative paths<\/strong>&nbsp;&#8212; that is, they&#8217;re relative to our position in the tree.&nbsp;<strong>Absolute paths<\/strong>&nbsp;start at the root and use slashes to indicate subfolders. The path you saw in the sixth step, which looked like this:<\/p>\n\n\n\n<p>\/<code>Users\/miriamposner<\/code><\/p>\n\n\n\n<p>is an example of an absolute path. The \/ at the front of the path stands for the root of my computer. Then I specify the Users folder, and finally, I specify the miriamposner folder <em>inside<\/em> the Users folder. You can use either relative paths or absolute paths with the&nbsp;<strong>cd<\/strong>&nbsp;command.<\/p>\n\n\n\n<p>Once you&#8217;ve executed the&nbsp;<strong>cd<\/strong>&nbsp;command, you should be at your computer&#8217;s desktop (or whichever folder you specified). You can tell because the name of the folder appears in the command prompt.<\/p>\n\n\n\n<p>Type&nbsp;<strong>ls<\/strong>&nbsp;to see what&#8217;s on your desktop. If you&#8217;re like me, it&#8217;s too many screenshots.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#9-move-back-up-the-tree\"><\/a>9. Move back up the tree<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-8.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-8.jpeg\" alt=\"Move back up the tree\"\/><\/a><\/figure>\n\n\n\n<p>Let&#8217;s head back up toward the root. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd ..<\/code><\/pre>\n\n\n\n<p>Note that there&#8217;s a space after <strong>cd<\/strong>! The two adjacent periods (<strong>..<\/strong>) are a special code that tells the terminal to move up the tree by one folder. So this will take you back up to where you were before you cd&#8217;d the first time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#10-move-into-a-specific-folder\"><\/a>10. Move into a specific folder<\/h2>\n\n\n\n<p>If you&#8217;re on a Mac, there&#8217;s a cool way to move directly into the folder you&#8217;re interested in. (Unfortunately, I don&#8217;t think this works on PCs.) We&#8217;ll use this trick to navigate to the folder you downloaded at the beginning of this tutorial. First, type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd<\/code><\/pre>\n\n\n\n<p>Next locate the icon for the folder your downloaded. (Mine is in my Downloads folder.)<\/p>\n\n\n\n<p>Then drag the folder icon directly onto the terminal window and drop it there. The terminal will automatically display the folder&#8217;s absolute path. (My path looks weird because I have Dropbox installed on my computer.)<\/p>\n\n\n\n<p>Then type&nbsp;<strong>control e<\/strong>&nbsp;to move your cursor to the end of the line.<\/p>\n\n\n\n<p>When you press <strong>return<\/strong> (from anywhere on the line you typed), you&#8217;ll be taken into the folder you dropped into the terminal.<\/p>\n\n\n\n<p><em>It&#8217;s a bit hard to explain the process, so you can watch me do it instead:<\/em><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"copy folder path\" width=\"750\" height=\"563\" src=\"https:\/\/www.youtube.com\/embed\/COnbjVzOscA?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>You can type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pwd<\/code><\/pre>\n\n\n\n<p>and press <strong>return<\/strong> to confirm you&#8217;re where you want to be.<\/p>\n\n\n\n<p><strong>If you&#8217;re on a PC or Chromebook<\/strong>, you&#8217;ll have to navigate down or up your file system until you find the folder you downloaded! If you&#8217;re lost and need a map to help you navigate around the file hierarchy, you can use the <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/learn.microsoft.com\/en-us\/windows-server\/administration\/windows-commands\/tree\" target=\"_blank\">tree<\/a><\/strong> command.<\/p>\n\n\n\n<p class=\"has-yellow-background-color has-background\">Are you seeing something like &#8220;permission denied&#8221; when you try to access the commandline folder? We may need to <a href=\"https:\/\/kb.iu.edu\/d\/abdb#:~:text=To%20change%20file%20and%20directory,%2C%20write%2C%20and%20execute%20permissions.\" target=\"_blank\" rel=\"noreferrer noopener\">alter your permissions using the chmod command<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#11-magically-create-a-file\"><\/a>11. Magically create a file<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-10.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-10.jpeg\" alt=\"Magically create a file\"\/><\/a><\/figure>\n\n\n\n<p>Now we can start to get a sense of what you can do with the command line. We&#8217;ll start with something easy but cool. Type the following into your terminal<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>touch magicfile.txt<\/code><\/pre>\n\n\n\n<p>and press return. Now look inside the&nbsp;<strong>commandline<\/strong>&nbsp;folder you downloaded. You should have a new file called&nbsp;<strong>magicfile.txt<\/strong>.<\/p>\n\n\n\n<p>That&#8217;s what the&nbsp;<strong>touch<\/strong>&nbsp;command does: It creates an empty file. Open magicfile.txt and type something in it. Then save the document and close it.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#12-check-your-work\"><\/a>12. Check your work<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-11.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-11.jpeg\" alt=\"Check your work\"\/><\/a><\/figure>\n\n\n\n<p>Now, back in your terminal window, type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat magicfile.txt<\/code><\/pre>\n\n\n\n<p>(Or you can type&nbsp;<strong>cat m<\/strong>&nbsp;and press the tab key!)<\/p>\n\n\n\n<p>Your terminal window now shows you the contents of your new file.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#13-concatenate-1\"><\/a>13. Concatenate! (1)<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-12.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-12.jpeg\" alt=\"Concatenate! (1)\"\/><\/a><\/figure>\n\n\n\n<p>Let&#8217;s see what else <strong>cat<\/strong> (concatenate) can do. Back in your terminal window, type:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat *.txt &gt; mergedfile.txt<\/code><\/pre>\n\n\n\n<p>Then press return. In the statement we just typed,&nbsp;<strong>cat<\/strong>&nbsp;is the command, while&nbsp;<strong>*.txt<\/strong> tells the computer what we want to concatenate. The asterisk (*) acts as a <strong><a href=\"https:\/\/swcarpentry.github.io\/shell-novice\/03-create\/index.html#wildcards\" target=\"_blank\" rel=\"noreferrer noopener\">wildcard<\/a><\/strong>: It can stand for any string of characters, as long as they&#8217;re followed by <strong>.txt<\/strong>. Then we have an arrow, and finally the name of the new file we want to create.<\/p>\n\n\n\n<p>So, essentially, you&#8217;ve told your computer, &#8220;Concatenate all the files in this folder with the file extension<strong> .rtf <\/strong>and put their contents in a new document called <strong>mergedfile.rtf<\/strong>.&#8221;<\/p>\n\n\n\n<p>(You can use the <strong>cat<\/strong> command for many kinds of files, including audio and video!)<\/p>\n\n\n\n<p>After you&#8217;ve run the command, check inside your&nbsp;<strong>commandline<\/strong>&nbsp;folder. You should have a new file that merges all of your text files into one!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#14-concatenate-2\"><\/a>14. Concatenate! (2)<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-13.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-13.jpeg\" alt=\"Concatenate! (2)\"\/><\/a><\/figure>\n\n\n\n<p>That was fun, so let&#8217;s do it again. This time, type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat *.csv &gt; mergedfile.csv<\/code><\/pre>\n\n\n\n<p>and press return. Can you tell what we&#8217;re doing? This time we&#8217;re telling the computer to concatenate every file in the folder with the file extension&nbsp;<strong>.csv.<\/strong><\/p>\n\n\n\n<p>When you&#8217;re done, check in your commandline folder. The document&nbsp;<strong>mergedfile.csv<\/strong>&nbsp;should now contain data from both spreadsheets! (In order to concatenate like this, the layout of both sheets must be identical; otherwise you&#8217;ll have columns with different data in them.)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#15-remove-files\"><\/a>15. Remove files!<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-14.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-14.jpeg\" alt=\"Remove files!\"\/><\/a><\/figure>\n\n\n\n<p>I grow tired of these files! Let&#8217;s get rid of them. This time, type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>rm mergedfile*<\/code><\/pre>\n\n\n\n<p>We&#8217;re using the command&nbsp;<strong>rm<\/strong>, which removes the designated items. This time we&#8217;ve told the computer to remove anything whose name starts with&nbsp;<strong>mergedfile<\/strong> (remember, the asterisk is a wildcard). <\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#16-move-files\"><\/a>16. Move files!<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-15.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-15.jpeg\" alt=\"Move files!\"\/><\/a><\/figure>\n\n\n\n<p>Let&#8217;s keep cleaning things up. I&#8217;m going to make a new folder (AKA directory) to hold my CSV files. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir csv<\/code><\/pre>\n\n\n\n<p>This tells your computer to make a new directory called csv.<\/p>\n\n\n\n<p>Now let&#8217;s move those CSVs. Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mv *.csv csv<\/code><\/pre>\n\n\n\n<p>See what we did? We used the&nbsp;<strong>mv<\/strong>&nbsp;(move) command to move everything with the file extension&nbsp;<strong>.csv<\/strong>&nbsp;into the&nbsp;<strong>csv<\/strong>&nbsp;folder! Much neater.<\/p>\n\n\n\n<p>Can you do the same for the text files?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#17-get-a-word-count\"><\/a>17. Get a word count<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-16.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-16.jpeg\" alt=\"Get a word count\"\/><\/a><\/figure>\n\n\n\n<p>If each of my text files contained a chapter in my novel and I wanted to see how many pages I had total, I could open each document individually, check the word count, and then add up all the values.<\/p>\n\n\n\n<p>We&#8217;re too smart to do that, though. We&#8217;re going to use the&nbsp;<strong>wc<\/strong>&nbsp;command. (Before you run this command, you may have to&nbsp;<strong>cd<\/strong>&nbsp;into a subfolder if you created a directory for your text files in the last step!)<\/p>\n\n\n\n<p>Type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wc *.txt<\/code><\/pre>\n\n\n\n<p>The command&nbsp;<strong>wc<\/strong>&nbsp;means, appropriately enough, word count. And there&#8217;s that wildcard again! This time, we told our computer to add up the words contained in every document with the file extension&nbsp;<strong>.txt<\/strong>.<\/p>\n\n\n\n<p>Hmm, looks like I&#8217;ve got a ways to go on my novel&#8230;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#18-a-little-about-syntax\"><\/a>18. A little about syntax<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-17.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-17.jpeg\" alt=\"A little about syntax\"\/><\/a><\/figure>\n\n\n\n<p>You&#8217;re almost done, but before you go, here&#8217;s some information that will help you understand Unix commands if you encounter them elsewhere on the web.<\/p>\n\n\n\n<p>You&#8217;ve already seen&nbsp;<strong>commands<\/strong>; they tell your computer to do something. Many commands also have&nbsp;<strong>options<\/strong>, which are indicated by a hyphen (-). For example, you could type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -a<\/code><\/pre>\n\n\n\n<p>which would force your terminal to display all of the files in a directory, including the ones that are usually hidden. Sometimes these are called&nbsp;<strong>flags<\/strong>&nbsp;or&nbsp;<strong>switches<\/strong>.<\/p>\n\n\n\n<p>Finally, commands can have&nbsp;<strong>arguments.<\/strong>&nbsp;They tell your computer what to perform the operation on \u2014 for example, a particular file or directory.<\/p>\n\n\n\n<p>So you could type<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ls -a csv<\/code><\/pre>\n\n\n\n<p>from inside your <strong>commandline<\/strong> folder to get a list of everything in your&nbsp;<strong>csv<\/strong>&nbsp;folder.<\/p>\n\n\n\n<p>Commands don&#8217;t need to have arguments or options, and they can have more than one of both.<\/p>\n\n\n\n<p>You can also chain together multiple commands using the vertical bar (|), often called a&nbsp;<strong>pipe<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/getting_started_with_unix.md#19-great-job\"><\/a>19. Great job!<\/h2>\n\n\n\n<figure class=\"wp-block-image\"><a href=\"https:\/\/github.com\/miriamposner\/unix\/blob\/main\/steps-getting_started_with_unix\/step-18.jpeg\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" src=\"https:\/\/github.com\/miriamposner\/unix\/raw\/main\/steps-getting_started_with_unix\/step-18.jpeg\" alt=\"Great job!\"\/><\/a><\/figure>\n\n\n\n<p>You&#8217;ve navigated the terminal! Now that you know about it, you&#8217;ll find lots of opportunities to use it.<\/p>\n\n\n\n<p>Here&#8217;s a&nbsp;<a href=\"https:\/\/www.guru99.com\/linux-commands-cheat-sheet.html\">cheat sheet<\/a>&nbsp;for you! And if you&#8217;re ready to start learning more,&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/swcarpentry.github.io\/shell-novice\/03-create\/index.html#copying-files-and-directories\" target=\"_blank\">this lesson<\/a>&nbsp;will show you how to download files from the internet, search inside files, and more.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Every Mac comes equipped with a program called&nbsp;Terminal.&nbsp;This program allows you to communicate via typing with your Unix operating system. (Sometimes people call this&nbsp;using the command line.) PCs don&#8217;t use&hellip; <a class=\"more-link\" href=\"http:\/\/miriamposner.com\/classes\/is270s23\/resources\/command-line-unix\/getting-started-with-the-command-line-mac\/\">Continue reading <span class=\"screen-reader-text\">Getting started with the command line<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":453,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_eb_attr":"","footnotes":""},"class_list":["post-451","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/451","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/comments?post=451"}],"version-history":[{"count":5,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/451\/revisions"}],"predecessor-version":[{"id":751,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/451\/revisions\/751"}],"up":[{"embeddable":true,"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/pages\/453"}],"wp:attachment":[{"href":"http:\/\/miriamposner.com\/classes\/is270s23\/wp-json\/wp\/v2\/media?parent=451"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}