From Documentation
Revision as of 15:00, 28 October 2015 by Merz (Talk | contribs) (Basic bash command line behavior)

Jump to: navigation, search

Basic UNIX concepts

  • Unix is an operating system, all SHARCNET systems run some variant of Unix (eg. Linux)
  • Most Unix-based systems have a GUI interface, but the command line offers more complex and abstract interactions with far less effort
  • At login the system starts a shell process for you which acts as your command line interpreter to interface with the operating system
    • Borne Again Shell ( bash ) is the default shell at SHARCNET

Common terms

  • File
    • data stored in a standard format that behaves in a certain way depending on it’s function in the system; everything is a file in Unix
  • Program
    • a file that can be executed (run)
  • Process
    • a program that is being executed (eg. your computing job is made of one or more processes)
  • Ownership
    • files/programs/processes are owned by a user and group
  • Hierarchical Directory Structure
    • files are organized in directories (folders) that can have a parent, eg. /home/$USER/sim1
    • The base of the hierarchy is root , ie: / (forward-slash)

Managing your files and processes is crucial to effectively using the systems!

Basic bash command line behavior

Basic key sequences / commands

  • first you ssh to the system you’d like to use
    • you see the message of the day and are left at a command prompt
  • each time you type in a command you are executing one or more processes
  • you can see commands you ran in the past with history
  • you can scroll through previous commands with the ↑ and ↓ arrow keys
  • you can complete commands / arguments with the Tab ↹ key !!!
  • depending on your terminal (the software you are connecting with) you should be able to go to the start of a line with Ctrl-a or the end with Ctrl-e, and cut to the end with Ctrl-k
  • to exit, run the exit command
  • if your terminal is not responding:
    • you may be able to exit the foreground process by pressing Ctrl-c
    • you may be able to disconnect your ssh session gracefully by entering ~. (sometimes repeatedly, while mashing the Enter↲ key in between…)

Executing Commands

  • To run a command you simply type its name in and hit Enter↲
  • The command must be in your $PATH and be executable (we’ll get to that later…)

General syntax of a command:

 $ command [[-]option(s)] [option argument(s)] [command argument(s)]
  1. command: the name of the command or utility: ls, man, cat, mv
  2. options: change the behaviour of the basic command: ls -l vs. ls
    • may or may not be preceded by “-”
  3. option arguments: change the behaviour of an option: tail –c 5 file1 vs. tail –c 15 file1
  4. command arguments: what is affected by the command, usually files or the output of another command

Basic Commands

  • Getting help with commands (the most important command!):
    • man
  • Figuring out who we are and where we are:
    • whoami, hostname, date
  • Navigating directories:
    • cd, pwd
  • Manipulating files and directories:
    • cp, mv, rm, rmdir, mkdir
  • Listing files and their properties:
    • ls, file
  • Displaying the contents of files:
    • cat, tail, head, more, wc
  • Investigating running programs:
    • ps, top

File systems and permissions

Managing files

Text editing

Command pipes and redirection

Shell variables, initialization, and scripts