Using the command line (Bash)

Command line with bash (Bourne Again Shell)

A Unix shell and command language.

  • bash is scripting language that is referred to as a shell
    • because it sits around the kernel making it easy to interact with
  • Often default shell

 

  • bash can be seen as a program that finds and runs other programs
  • The command-line interface: the bash prompt
$

shell.jpg

 

 

 

unix_architecture.jpg

 

The prompt

[info]$ program word1 word2 word3 […]

  • [info] is configurable, and usually tells you who you are, on what system, and where in the file system.

Example: 

[bjornc@rackham3 linux_tutorial]$

 

  • The program to run is the first word
    • All words are separated by spaces
  • The following words can be arguments to the program, file names, flags etc...

 

Program, flags, and files

  • Input to the program:
    • Flags: specific single letters or words that change the behaviour of a program.
    • Arguments: text given to the program when started, e.g. file names.
    • Terminal input: text given to the program while it runs.
  • Output from the program:
    • Most Linux programs output to the terminal.
    • Some programs also write to files.

 

folders.png

 

 

 

 

 

Example bash command

mv inbox.png

program flags.png

  •   Terminal screen shows the output

screen.png               

 

Tab Completion

tab.png

 

Whenever you’re writing a path or filename on the bash prompt, you can strike the ‘tab’ key to
ask Bash to complete what you’re writing.

  • Get in the habit of this — it will save you many hours!

 

Editing files with text editors

edit.png

  • gedit (graphical user interface — GUI, needs X-server)

 

  • Graphical editor within MobaXterm

 

 

 

  • gvim vim with a GUI, lots of features
    • very Fast!

 

 

  • When starting the graphical versions, add "&" to be able to use the command line while program is open.
    • $ gedit &
    • If not, you can "Ctrl+z" and type bg to send program to background.

 

  • Try them out and pick one favorite editor!

 

Typical sources of error

cross.png

  • Capitalization matters in file names and program names
  • Spaces matter.
    • Always have a space after the program name.
    • Don’t add spaces within file names.
  • Check that you are in the right place in the file system.
  • File permissions. Check that the right read, write and execute permission are set.

 

Caution!!

caution.png

Beware of overwriting files and deleting the wrong ones.

  • There is no undo for
    • copy (cp)
    • move (mv)
    • remove (rm)

 

  • Tip: make "rm" ask if you really want to erase:
    • Within a session: Type in the command prompt
      alias rm='rm -i'
    • Override asking with 
      rm –f <filename>
    • Edit file ".bashrc" in /home directory by adding the alias line for this to start everytime in a new shell
  • This will also work for mv and cp!

 

  • If you do destroy your data, email UPPMAX support, we MAY be able to help.