# Other UNIX commands - *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]: 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 `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 `less` command was created as a more powerful version of the `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 (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 **Help** menu. [^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. On a Mac, `emacs` is built-in and you can use it from within Terminal. You'll get the screen-based version instead of the window-based version; do *not* put & after the command. You'll also need to take the tutorial immediately, as suggested in `emacs`' "Welcome" screen, since the editing keypresses for the screen-based `emacs` are not obvious. [^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 the **File** menu. If you're editing many files, try opening them all with **File->Open File\...** and switch between them using the **Buffers** menu. Remember to use **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. :::