Command Line Walkthrough
1. Setup
./setup.sh
cd ~
2. structure of a command
grep -r capital etext/*
command, flags/options, arguments
3. white spaces in commands: white spaces separate arguments and options, use quotes to include spaces in things like filenames
grep -r "they were" etext/*
4. the file system, files, folders, user folder
pwd
ls
ls -l
cd mydir
cd ~
mkdir mynewdir
mkdir -p mynewdir/mysubdir/mysubsub/subx3
touch goodbye.txt
rmdir mynewdir/mysubdir/mysubsub/subx3
rm goodbye.txt
rm -r mynewdir
cp hello.txt mydir/hello_copy.txt
mv mydir/hello_copy.txt ./
5. working with files: cat, less
cat hello.txt
cat aesopa10.txt
less aesopa10.txt
6. pipes and redirection
| pipes take the output from one command and sends it as an argument of the second one
>, > pipe output as input to the file/stream
echo "hello world." > hello.txt
cat aesopa10.txt | less
grep -r they etext/* > them.txt
cat > dummy.txt
*Use ctrl-d to finish entering text
7. finding stuff: grep, find
files:
find . -name "*.txt" -print
text:
grep -r race ./*
grep -r " race" ./*
case insensitive:
grep -ir german ./*
wildcards:
grep -ir "fr.nc[eh]" ./*
8. getting help: man, apropos, –help
man grep
apropos find
grep --help
9. autocompletion, bash history
10. exit
Additional Stuff
A. keyboard shortcuts: http://en.wikipedia.org/wiki/Bash_%28Unix_shell%29#Keyboard_shortcuts
ctrl-c: kill the command
ctrl-d: exit
ctrl-z: pause and return to the command line (%n to resume)
ctrl-a: jump to the beginning of a line
ctrl-e: jump to the end of a line
up/down: previous/next command
tab: autocomplete
ctrl-l: clear the display
B. installing stuff:
Debian Linux (Mint, Ubuntu, etc.): apt (apt-get)
OS X: brew (recommended) or macports
Windows: cygwin + cyg-apt
C. other topics to look into: users, groups, permissions, linking, processes, shell scripts, loops…
D. Google is your friend!!!
Additional Resources
- http://cli.learncodethehardway.org/book/
- http://www.davidbaumgold.com/tutorials/command-line/
- http://learnpythonthehardway.org/book/appendixa.html
- http://ryanstutorials.net/linuxtutorial/commandline.php
Advanced Resources
- http://ohmyz.sh/
- https://github.com/revans/bash-it
- http://zachholman.com/2010/08/dotfiles-are-meant-to-be-forked/
- http://dotfiles.github.io/
Workshop Evaluation
Please take a moment to fill out the evaluation form: https://digitalfellows.commons.gc.cuny.edu/workshopevaluationform/