(other-commands)= # Other UNIX commands[^hs] [^hs]: A colleague of mine once said, "The commands in UNIX are the initials of the people that the designers went to high school with." A good story, but it's not true. The reality is that when [UNIX was first developed](https://en.wikipedia.org/wiki/History_of_Unix) in the 1960s, computers had six orders of magnitude less memory than they do today. The space for internal tables containing items like command names was at a premium. From then to now, UNIX command names tend to be terse. - *To copy a file:* use the `cp` command.[^f8] For example, to copy the file `CreateSubdirectories.C` from the directory `~seligman/root-class` to your current working directory, type: > cp ~seligman/root-class/CreateSubdirectories.C $PWD In UNIX, `$PWD` means the results of the `pwd` command.[^f9] [^f8]: Over the years, as students began to use laptops, I noticed that many of them had an interesting misconception: The `cp` command copies a file from one place to another on the same computer. It does *not* copy a file from a remote server to your laptop! For that you use `scp`; use `man scp` to learn more. Note that if you're working on a remote server such as the ones at Nevis, there's no reason to use `scp` for this tutorial. [^f9]: A period (`.`) is the usual abbreviation in UNIX for "the current directory" (did you remember that `..` means "the directory above this one"?) but many students missed the period the first time I taught this class. - *To look at the contents of a text file:* Use the {command}`less` command.[^f10] This command is handy if you want to quickly look at a file without editing it. To browse the contents of file `CreateSubdirectories.C`, type: > less CreateSubdirectories.C While `less` is running, type a space to go forward one screen, type `b` to go backward one screen, type `q` to quit, and type `h` for a complete list of commands you can use. [^f10]: If the name is confusing: the {command}`less` command was created as a more powerful version of the {command}`more` command. - *To get help on any UNIX command:* type `man ` While `man` is running, you can use the same navigation commands as `less`. For example, to learn about the `less` command, type: > man less (rm)= - *To delete a file:* Use the {command}`rm` command.[^notrash] For example: > rm CreateSubdirectories.C [^notrash]: **Super-duper warning: There is no Trash folder or "undo" operation in command-line UNIX!** If you use {command}`rm` on a file and later realize that was a mistake, there's pretty much nothing you can do except re-create the file from scratch. Be warned: A notorious UNIX prank is for someone to get you to type `rm -rf ~` which performs an unrecoverable delete of all of your files without any warning. Don't fall for it! (emacs)= - *To edit a file:* I suggest you use `emacs`.[^f11] For example, to edit the file CreateSubdirectories.C: > emacs CreateSubdirectories.C This may appear to "lock up" your UNIX window. If this is an issue, either create a new UNIX window or learn about [ampersands at the end of a command line](https://bashitout.com/2013/05/18/Ampersands-on-the-command-line.html). The `emacs` environment is complex, and you can spend a lifetime learning it.[^f12] For now, just use the mouse to move the cursor and look at the menus. When you get the chance, I suggest you take the `emacs` tutorial by selecting it under the {guilabel}`Help` menu.[^whyemacs] [^f11]: If you\'re already familiar with another text-based UNIX editor, such as `nano` or `vim`, you can use it instead. If you're not using a remote UNIX server and you're editing files on your laptop, make sure you're using a plain-text editor. If you use an editor whose default mode is to *not* save files in plain text (Microsoft Word is one example; the poorly-named TextEdit on the Mac is another) you're going to get confused. If you don't already have such an editor, I suggest [Notepad++](https://notepad-plus-plus.org/) on MS-Windows and the free version of [BBEdit](https://www.barebones.com/products/bbedit/) for the Mac. What do I mean by "you're going to get confused" in the previous paragraph? When I taught Python to my father, he tried to use Microsoft Word to edit code. He didn't understand why you couldn't apply a bold or italic font style to text in a program. He also often forgot to use `Save As...` and switch the file format to `Plain Text`, so his code was saved as a Word document. Of course, you're not my father; otherwise I'd ask you if I could stay out late this Saturday. You may find Word is the best plain-text editor for you. [^whyemacs]: As a final aside: There's [lots](https://www.redhat.com/sysadmin/3-text-editors-compared) of [debate](https://unkertmedia.com/emacs-vs-nano-vs-vim/) over which is the best UNIX editor: `emacs`, `vim`, or `nano`. I'm aware that `emacs` is now the minority choice. I recommend `emacs` because it's the one I always use, for two reasons: - As I discuss on the next web page, the keyboard commands are useful on the UNIX command line.

- Emacs has a large number of [modes](https://www.gnu.org/software/emacs/manual/html_node/emacs/Modes.html) that make it easier to edit code. This includes syntax highlighting and auto-indentation. If you're used to Python, the notion of auto-indenting will seem trivial to you: You have to indent your code anyway. For a language like C++, emacs can automatically indent code to make it more readable. This helps a lot when someone sends you a code file that's an unreadable mish-mash. These modes are language-dependent; e.g., the syntax highlighting and indentation are different when you're editing a C++ file, a shell script, or a web file. To me, this more than makes up for any perceived deficiencies between emacs and vim. [^f12]: I've spent two of your lifetimes already, and the class has just started! :::{tip} Are you quitting emacs after you change a file, only to start up the editor again a moment later? Hint: look at {menuselection}`File`. If you're editing many files, try opening them all with {menuselection}`File --> Open File` and switch between them using {menuselection}`Buffers`. Remember to use {menuselection}`File --> Save` once in a while. Learn how to cut and paste in whatever editor you use. If you don't, you'll waste a lot of time typing the same things over and over again. ::: :::{figure-md} real_programmers-fig :class: align-center xkcd real_programmers by Randall Munroe. If you're feeling bored, type `Meta-x butterfly` in emacs and see what happens. :::