Basic UNIX commands reminder

Connecting to the front-end machines of the clusters:
Note: you have to replace <user_name> with your UNIL user name.

  • ssh <user_name>
  • ssh <user_name>

Navigating the directory tree:

  • pwd print's the current working directory. Useful to see where you currently are.
  • cd <directory> change working directory to <directory>.
  • cd .. move one directory up.
  • cd ~ change working directory to your home directory.

List the content of a directory: Note: if you don't specify any <directory> in the commands below the content of the current directory is listed.

  • ls <directory> list content of specified directory.
  • ls -l <directory> list content in greater details.

Creating and copying/moving files and directories:

  • mkdir <directory name> create a new directory.
  • touch <new file> create an empty file named .
  • mv <file> <destination> moves <file> to the specified <destination>
  • cp <file> <copy name> creates a copy of <file> named . if is a directory then the file is copied to the specified directory and keeps the same name as the original.
  • cp -r <directory> <new path> copies an entire <directory> to the specified new location.

Copying files from a local machine to the cluster: The following command will copy <fileName> to your home directory in the cluster. To copy files to a different directory, replace ~ with the /path/where/to/copy/files

  • scp <fileName> <userName>

Display file content in terminal:

  • cat <file> prints the entire content of <file> to the terminal.
  • less <file> opens <file> with the less program where you can scroll down/up the file. Press q to exit less. This is useful to look at larger files.
  • head <file> print the first 10 lines of <file> to the terminal.
  • tail <file> print the last 10 lines of <file> to the terminal.

Simple text editors available on most GNU-Linux machines:

  • nano: follow the instructions given at the bottom of the terminal, e.g. Ctrl + o to save your edits and Ctrl + x to exit nano.
  • vim: press i to enter edit mode and Esc to exit edit mode. In the non-edit mode, press :wq to save your edits and exit vim, or :q/:q! to exit without saving your changes.

Change file permissions:

  • chmod a+x <file> add execution permissions to file.
  • chmod a-x <file> remove execution permissions to file.
  • chmod a+w <file> add write permissions to file.
  • chmod a-w <file> remove write permissions to file.

If you need more background information on UNIX, the following e-learning module is available here.

Last modified: Thursday, 19 September 2019, 11:42 AM