https://sciware.flatironinstitute.org/27_SummerIntro
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
Instructions to get your laptop set up before the session
xcode-select --install
Let’s start a terminal!
“Terminal” (or “wsl” on Windows)
Here’s a typical shell command, separated by spaces:
-
A shell always has a “current working directory”: the directory (or folder) that’s used by default
pwd
shows you the current directory (“print working directory”)cd
changes the current directory, by default to your “home” directory (~
)> pwd
/home/you/somewhere
> cd
> pwd
/home/you
> cd ~
> cd /home/you # same thing, for your home directory path
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
See advanced/README
https://wiki.flatironinstitute.org/SCC/Software/UnixIntroduction
/
to make longer paths/
start at the “top” or root of the system, full absolute path.
means current directory..
means parent directory (up one)pwd
is /home/you
, then these are all the same:
/home/you/dir/file
dir/file
./dir/file
../you/dir/../dir/file
../..///../.././home//you/dir/./file
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>
To see inside a file, the contents, you need something else
cat
just prints an entire file to the terminalless
lets you scroll around (q
to quit)> cat README
> less README
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
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
What if we want to make a directory work stuff
?
> mkdir work stuff
> ls
> rmdir work stuff
> mkdir "work stuff"
> cd work<tab>
\
, which “escapes” any character_
underscores)mv
renames or moves files or directoriesrm
removes files, or rm -r
removes directories and contents (careful!)> 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
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 ..
cp
makes an identical copy of a file.
> cp README readnot
> cat readnot
To copy entire directories, use cp -a
.
<Ctrl-X>
(or sometimes ^X
or C-X)
<Ctrl-D>
tells a program you’re done<Ctrl-C>
tells a program to exit (“cancel”)> python3
Python 3
>>> 1+1
2
>>> ^D
You can use *
to mean “anything”, any file that matches:
> ls *.txt
> echo *.txt
echo
just prints its arguments
> echo "*.txt"
> echo \*.txt
Run something again
> <Up><Down>
> history
> <Ctrl-R>
Navigation
> <Left><Right><Home><End>
<Ctrl-A>
= Home (beginning of line), <Ctrl-E>
= End (end of line)<Ctrl-Left>
, <Ctrl-Right>
= move by word<Ctrl-L>
= clearhttps://vhernando.github.io/keyboard-shorcuts-bash-readline-default
> exit
There are multiple different shells with different features.
.bashrc
.zshrc
Shells are extremely customizable, including prompts, keybindings, aliases, plugins
Organize the files in animals
directory:
ls
, cat
, mkdir
, mv
Interactive demo
Sign up for account at github.com