Creating, editing and displaying files

There are several ways to create new file. Since usually you would want to write something in the new file, you can just use one of the text editors available on the cluster.

If you don’t know how to use vi/vim, we recommend using nano, which is a small and friendly editor. If you’re used to emacs, it's also installed on our clusters.

Whether to create a new file or edit an existing file in the current directory, issue “nano <file_name>” command, where <file_name> is the name of the file you would like to create/edit. Within nano use PgDn, PgUp and arrow keys to move cursor to the different part of the file. Pressing Enter key will create new line. At the bottom of the editor window you will find the list of hot keys for various actions with ‘^’ meaning Ctrl key. For example, among the commands you will see:

^X Exit

That means that to exit editor, you need to press Ctrl-X. Read carefully the questions that editor will ask. For example, it may ask if you would like to save changes that you’ve made to the file before closing the editor.

If you don’t need to edit file and just want to see the contents, you can use one of the following commands: "cat", "less", "head", "tail".

cat <file_name>” will print contents of the file on the screen. Usually you would use it on small files. For larger files it’s better to use “less” command which initially will print only the first page. As in the “man” command, to navigate between pages, use PgDn, PgUp and arrow keys. Alternatively, you can use Space, 'b' and Enter keys. To search for a term, type '/<search_term>' and hit Enter. To repeat the same search, type ‘/’ and press Enter. To exit “less” command, use 'q' key.

If you need to see only the first N lines of a file, use “head -N” command. If number of lines is not specified, 10 lines will be displayed. Similarly, “tail -N” command will display last N lines of the file. It’s useful to display the end of a log file that is being actively written to.