The Command Line

Purpose

The purpose of this presentation is to give a quick introduction to the command line computing environment.

Objectives

  1. Be proficient in navigation between directories in the command line environment.
  2. Understand basic shell programming.
  3. Be able to write a for loop to complete a repetitive task.

You're going to need Unix

(there is a Windows 10 subsystem for linux)

Installing Linux (Ubuntu distribution) on Windows

What is the command line?

What is the command line?

Basic parts

Syntax

command argument1 argument2 argument3 ... <press enter>
output
[EyeMac: ~]echo charlie bit me!
charlie bit me!
[EyeMac: ~]
[EyeMac: ~]say -v Zarvox brains are amazing

Getting Help: man

ECHO(1)                   BSD General Commands Manual                  ECHO(1)

NAME
     echo -- write arguments to the standard output

SYNOPSIS
     echo [-n] [string ...]

DESCRIPTION
     The echo utility writes any specified operands, separated by single blank
     (` ') characters and followed by a newline (`\n') character, to the stan-
     dard output.

     The following option is available:

     -n    Do not print the trailing newline character.  This may also be
           achieved by appending `\c' to the end of the string, as is done by
           iBCS2 compatible systems.  Note that this option as well as the
           effect of `\c' are implementation-defined in IEEE Std 1003.1-2001
           (``POSIX.1'') as amended by Cor. 1-2002.  Applications aiming for
           maximum portability are strongly encouraged to use printf(1) to
           suppress the newline character.

     Some shells may provide a builtin echo command which is similar or iden-
     tical to this utility.  Most notably, the builtin echo in sh(1) does not
     accept the -n option.  Consult the builtin(1) manual page.

EXIT STATUS
     The echo utility exits 0 on success, and >0 if an error occurs.

SEE ALSO
     builtin(1), csh(1), printf(1), sh(1)

STANDARDS
     The echo utility conforms to IEEE Std 1003.1-2001 (``POSIX.1'') as
     amended by Cor. 1-2002.

BSD                             April 12, 2003                             BSD
(END)
[EyeMac: ~]man echo

Useful commands

[EyeMac: ~]pwd
/Users/ben88

[EyeMac: ~]ls
@update.afni.binaries     Library                   bin
Applications              Movies                    build
Box                       Music                     get-pip.py
Desktop                   OneDrive - BYU Office 365 logfiles
Documents                 Pictures                  matlab
Downloads                 Public                    research_bin
Dropbox                   abin                      rubygems-2.7.5

[EyeMac: ~]cd Documents/
[EyeMac: Documents]pwd
/Users/ben88/Documents

[EyeMac: ~]mkdir myDirectory
[EyeMac: ~]ls
@update.afni.binaries     Movies                    get-pip.py
Applications              Music                     logfiles
Box                       OneDrive - BYU Office 365 matlab
Desktop                   Pictures                  myDirectory
Documents                 Public                    research_bin
Downloads                 abin                      rubygems-2.7.5
Dropbox                   bin
Library                   build

The For Loop

Some times you have to carryout a task that is repetitive, with a slight tweak for each iteration. The for loop is great for this.

for i in {<list of variables>}; do
	<commands>
done
for i in { 1 2 3 4 5 6 7 8 9 10 }; do
	touch subject_${i}.txt
done
[EyeMac: ~]ls
subject_1.txt
subject_2.txt
subject_3.txt
..
subject_10.txt

Next time

  • Complete the command line tutorial by Ubuntu.
  • Write and send me your working for loop.

fMRI 6 – The Command Line

By Ben Carter

fMRI 6 – The Command Line

These slides will give a basic introduction to command line computing and a few of the commands used for navigation, as well as a simplified for loop.

  • 346