sciware

Sciware

Command line and Shell interaction

https://sciware.flatironinstitute.org/27_SummerIntro

Sciware goal

Activities where participants all actively work to foster an environment which encourages participation across experience levels, coding language fluency, technology choices*, and scientific disciplines.

*though sometimes we try to expand your options

Summer Intros

Today’s Agenda

Preparation Instructions

Instructions to get your laptop set up before the session

Windows Instructions

Getting started

Let’s start a terminal!

“Terminal” (or “wsl” on Windows)

Shell Command Example

Here’s a typical shell command, separated by spaces:

Command Line

Working directory

A shell always has a “current working directory”: the directory (or folder) that’s used by default

> pwd
/home/you/somewhere
> cd
> pwd
/home/you
> cd ~
> cd /home/you # same thing, for your home directory path

Clone a git repo

ls lists the files and directories (…in a specific directory, or your current by default)

> ls
Desktop
> git clone https://github.com/flatironinstitute/sciware-command-intro
Cloning into 'sciware-command-intro'...
> ls
Desktop  sciware-command-intro
> cd sciware-command-intro
> pwd
/home/you/sciware-command-intro

Advanced exercises

See advanced/README

https://wiki.flatironinstitute.org/SCC/Software/UnixIntroduction

Paths

Tab completion

No one wants to type all these file names: use tab!

> cd ~
> cd sciware-<tab>
> cd ~/sciware-<tab>

If there are multiple things, press tab twice:

> cd di<tab><tab>

Looking at files

To see inside a file, the contents, you need something else

> cat README
> less README

Listing files

ls lists files in a directory, and has many options to show more/different information

> ls -l # long
> ls -l -t -r # long, sort by modification time, reversed
> ls -ltr # same
> ls --help # may not work on Mac
> man ls # MANual page

Creating directories

Create a new directory with mkdir, remove with rmdir

> mkdir mydir
> cd mydir
> ls
> cd ..
> cd -
> pwd
> cd -
> rmdir mydir

cd - can be used to “go back” or “undo” the last cd

Quoting, spaces, arguments

What if we want to make a directory work stuff?

> mkdir work stuff
> ls
> rmdir work stuff
> mkdir "work stuff"
> cd work<tab>

More file manipulation

> cd ~/sciware-command-intro
> mv filea fileb
> mv fileb dir1
> ls dir1
> rmdir dir1
rmdir: failed to remove 'dir1': Directory not empty
> rm dir1/fileb dir1/deleteme
> rmdir dir1
> ls dir2
> rm -r dir2

Hidden “dot” files

Files and directories that start with . don’t show up by default, but you can access them as usual.

> cd notempty
> ls
> ls -a # all
> ls -la
> mv .hiddenfile nothidden
> ls
> cd ..

Copying files

cp makes an identical copy of a file.

> cp README readnot
> cat readnot

To copy entire directories, use cp -a.

Interactive programs

> python3
Python 3
>>> 1+1
2
>>> ^D

Globbing

You can use * to mean “anything”, any file that matches:

> ls *.txt
> echo *.txt

echo just prints its arguments

> echo "*.txt"
> echo \*.txt

History, navigation

Run something again

> <Up><Down>
> history
> <Ctrl-R>

Navigation

> <Left><Right><Home><End>

Shell interaction

https://vhernando.github.io/keyboard-shorcuts-bash-readline-default

> exit

Shells and configuration

There are multiple different shells with different features.

Shells are extremely customizable, including prompts, keybindings, aliases, plugins

Questions and exercise

Organize the files in animals directory:

VS code

Interactive demo

Homework

Sign up for account at github.com