This shows you the differences between two versions of the page.
|
fyi:useful_linux_commands [2009/10/15 10:03] lass Add link to unix help page |
fyi:useful_linux_commands [2012/06/15 10:18] (current) admin |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| The following will help you get started with Linux on the SCS Network. It will only describe the very basics. For an in-depth look at Linux, the internal workings, and how the operating system works see the O'Reilly set of books in particular 'Essential System Administration' by Aeleen Frisch. | The following will help you get started with Linux on the SCS Network. It will only describe the very basics. For an in-depth look at Linux, the internal workings, and how the operating system works see the O'Reilly set of books in particular 'Essential System Administration' by Aeleen Frisch. | ||
| + | |||
| + | <note>A lot of the content has not yet been moved to the new support site. For more information, please visit the [[http://www.scs.carleton.ca/nethelp/linux_help.shtml|old linux help page]].</note> | ||
| ==== Opening a Terminal Window==== | ==== Opening a Terminal Window==== | ||
| - | Linux has a window manager, and windows that you can work with. (SCS uses Gnome as the default window manager). Although GUIs are useful, and many tasks can now be done using GUIs, much of the work in Linux is still done on the command line. Essentially all work can be done on the command line, without using the GUI at all. The terminal window is used to type command line arguments. For the Gnome window manager you have to access the menu (top left corner icon) and then select “Accessories – Terminal”. | + | Linux has a window manager, and windows that you can work with. (SCS uses Gnome as the default window manager). Although GUIs are useful, and many tasks can now be done using GUIs, much of the work in Linux is still done on the command line. Essentially all work can be done on the command line, without using the GUI at all. The terminal window is used to type command line arguments. For the Gnome window manager you have to access the menu (top left corner icon) and then select “Accessories → Terminal”. |
| ==== Basic Linux Commands ==== | ==== Basic Linux Commands ==== | ||
| Line 23: | Line 26: | ||
| For more help with Linux commands, you can use the built-in help system. Type ‘''//man **command**//''’ to see the help page for a particular command. In addition, you can read the [[http://unixhelp.ed.ac.uk/|online unix help]]. | For more help with Linux commands, you can use the built-in help system. Type ‘''//man **command**//''’ to see the help page for a particular command. In addition, you can read the [[http://unixhelp.ed.ac.uk/|online unix help]]. | ||
| + | ==== Linux Command-Line Examples ==== | ||
| + | |||
| + | Here are some examples of more complicated commands which you may find useful. | ||
| + | |||
| + | ^ Linux Command ^ Description ^ | ||
| + | | <code bash>less README.txt</code> | Display the file ''README.txt'' on the screen, allowing you to scroll through it with arrow keys. Press ‘Q’ to exit. | | ||
| + | | <code bash>date > date.txt</code> | Get the current system date and time, and save the output to the text file ''date.txt'' | | ||
| + | | <code bash>grep keyword README.txt</code> | Search the file ''README.txt'' for ''keyword'', and display any matching lines. | | ||
| + | | <code bash>uname -a</code> | Display the version of the operating system which you are using. | | ||
| + | | <code bash>tar -acvf archive.tar.gz project/</code> | Create a compressed archive of a directory, much like a zip file. | | ||
| + | | <code bash>tar -xvf archive.tar.gz</code> | Extract a compressed archive to the current directory. | | ||
| + | | <code bash>whoami</code> | Display the name of the user that you are currently logged in as. | | ||
| + | | <code bash>ssh lambda02</code> | Use a secure, encrypted protocol to log into a different computer. You will get a command prompt on the remote computer. You can use ''exit'' to return to your original computer. | | ||
| + | ==== Linux Text Editors ==== | ||
| + | |||
| + | Linux has two different types of editors; command line editors and gui-style editors. Command line editors are useful because they are fast and they can be run from an xterm window. Two command line editors that you can find on Linux systems are “''nano''” and “''vi''”. | ||
| + | |||
| + | Nano is a very easy to use and simple text editor. You can use arrow keys to move around within a file, and a list of all the commands that you can use is printed at the bottom of the screen. For example, “''^X Exit''” means that if you type ''Ctrl-X'', the editor will exit. | ||
| + | |||
| + | The popular vi editor is an old editor which is very powerful, but more difficult to use. It is known as a “modal” editor, because it has two modes. In Normal mode, typing runs different editing commands. Some commands, such as “''i''” switch to Insert mode, where you can type text in the file. Pressing “''Escape''” returns to Normal mode. In addition to the old “''vi''” editor, there is an updated version called “''vim''” which is installed on many systems. | ||
| + | |||
| + | A summary of commonly used ''vi'' commands is presented here. In many versions of ''vi'', you can type “'':help''” to see a help screen. In addition, on systems with ''vim'', you can run the “''vimtutor''” command on the command line to run through a tutorial designed to teach the basics of ''vi''. | ||
| + | |||
| + | ^ Command ^ Description ^ | ||
| + | | ''i'' | Insert. This changes the editor mode so you can start typing text at the position where the cursor is located. | | ||
| + | | ''<Esc>'' | Exits insert mode, so you can type editor commands. | | ||
| + | | ''a'' | Append. Changes the editor to insertion mode, but you start typing after the current character instead of before. | | ||
| + | | ''x'' | Delete a single character located under the cursor. | | ||
| + | | ''dd'' | Delete the entire line that the cursor is on. | | ||
| + | | ''//n//G'' | Jump to line //n// in the file that you are editing. | | ||
| + | | ''Ctrl-F'' | Go forward one page. | | ||
| + | | ''Ctrl-B'' | Go backwards one page. | | ||
| + | | ''u'' | Undo the latest change made to the file. | | ||
| + | | ''///keyword//'' | Search for //keyword// in the file. | | ||
| + | | '':q'' | Quit the ''vi'' editor. | | ||
| + | | '':w'' | Save the changes made to the file you are editing. | | ||
| + | | '':q!'' | Quit the ''vi'' editor, discarding any changes you have made. | | ||
| + | |||
| + | There are many GUI Linux text editors available, which can be easier to use. Gnome includes an advanced text editor called “''gedit''” which can be found in the Applications menu under “Accessories → Text Editor”. | ||
| + | |||
| + | If you are looking for a word processor, like Microsoft Word, try “Open Office”, which will be located in the “Office” section of the menu. | ||
| + | |||
| + | ==== SSH Without a Password ==== | ||
| + | |||
| + | Sometimes you may want to be able to ssh (secure-shell) between linux hosts without typing your password. This can be useful when doing some sort of parallel programming, using lam or mpi, or just for convenience. Instead of entering a password, SSH can authenticate you using high-strength encryption keys. | ||
| + | |||
| + | To set up passwordless ssh between SCS Linux hosts, run these commands: | ||
| + | |||
| + | <code bash>ssh-keygen</code> | ||
| + | |||
| + | The command will prompt you for a filename. Press Enter to accept the default ''id_rsa''. You will also be prompted for a passphrase. For passwordless ssh, press Enter without entering a passphrase. | ||
| + | |||
| + | <code bash>cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys | ||
| + | chmod 600 ~/.ssh/authorized_keys</code> | ||
| + | |||
| + | This tells ssh that the key which was just generated has permission to access this computer. As all of the SCS network computers share the same home directory using NFS network mounts, this permission will be granted on all SCS computers. | ||
| + | |||
| + | If your account is not NFS mounted you must scp (or copy) the ~/.ssh/authorized_keys file to the destination host and account. | ||
| + | |||
| + | You must now log into every SCS linux machine at least once to initialize the encryption key per host. After you logged in once you should be able to ssh to the host without typing your password. | ||