chsh
command can be used to select any installed shellchs -s SHELL_PATH USER_NAME
man
command followed by the command nameinfo
command instead....bash
also has it's own help utility, help
which provides help on bash specific commandsman cp
help cd
-e
flag to accomplish this-n
flag-s
flagecho "This will print as expected"
echo This will too
echo "This\ndoesn't\nhave\nnewlines"
echo -e "This\ndoes\nhave\nnewlines"
cat src/perl/anchored.pl
cat -n src/perl/anchored.pl
cat src/perl/anchored.pl src/perl/unanchored.pl
-r
flag will sort in revers order-u
flag, each unique line will be printed only oncesort data/elements.txt
sort -n data/elements.txt
sort --key=2 data/elements.txt
sort -n data/dir_sizes.txt
sort -h data/dir_sizes.txt
uniq
in its default form accomplishes the same as sort -u
uniq
is assumed to be sorted alreadyuniq
is useful to:sort data/git_files.txt | uniq -c
sort data/git_files.txt | uniq -c -w3
shuf
randomly permutes the lines of a fileshuf data/elements.txt
head
and tail
commands display the first 10 or last 10 lines of a file by default-n
option-n
when using head
can be negative. This means return everything but the last n linescat data/git_files.txt
head -n1 data/git_files.txt
tail -n1 data/git_files.txt
head -n-1 data/git_files.txt
-d
argument to change the delimiter-f
argument #head regex_starter_code/food_facts.tsv
cut -f1,2 data/food_facts.tsv | head
cut -f1-4,10 -d, data/states.csv | head
paste
does the opposite of cut
-d
flag to change the delmiterpaste data/elements.txt data/dir_sizes.txt
paste -d, data/elements.txt data/dir_sizes.txt
find
is like an extremely powerful version of ls
find
will list all the files under a directory passed as an argument-name
matches the name of the file or directory-type
restricts the output to files (f
) or directories(d
)-maxdepth
restricts the amount of recursion done-size
restricts results to directories or files of the exact size+
or -
before the numberfind . | head
find . -type d | head
find . -maxdepth 1 -type d
find . -name "*ipynb"
find ~/Teaching -type f -size +50M
wc
or word count command returns the number of lines, words, and characters in a file-l
, -w
or -m
flags respectively wc to_sort1.txt
wc -l to_sort1.txt
bash hello_simple.sh
#!
, that line indicates which program to use to run the file#!/bin/bash
#!/bin/python
#!/bin/perl
chmod +x FILE
./src/shell/hello.sh
a_scalar=UMBC
another_scalar="This needs quotes"
more_scalars=40
even_more=3.14
an_array=(letters "s p a c e s" 1.0)
#Don't do this
bad= "not what you want"
echo $a_scalar
echo ${a_scalar}
echo $more_scalars
echo $even_more
echo ${an_array[1]}
#Don't Do This
echo $an_array
echo ${an_array[1]}
echo ${an_array[*]}
letters=(a b c d e f g h i j)
echo 'This class is at ${a_scalar}'
echo "This class is at $a_scalar"
echo "The schools website is www.$a_scalar.edu"
echo "The athletics website is www.$a_scalarretrievers.com"
echo "The athletics website is www.${a_scalar}retrievers.com"
echo ${a_scalar} ${#a_scalar}
echo ${a_scalar} ${a_scalar:1}
echo ${a_scalar} ${a_scalar:2:2}
echo ${a_scalar} ${a_scalar::2}
echo ${a_scalar} ${a_scalar/U/u}
echo ${a_scalar} ${a_scalar/V/u}
echo ${another_scalar} ${another_scalar/e/x}
echo ${another_scalar} ${another_scalar//e/x}
echo ${another_scalar} ${another_scalar//[a-z]/x}
#From the front of the string
echo ${another_scalar} "->" ${another_scalar#T*s}
#Longest possible match
echo ${another_scalar} "->" ${another_scalar##T*s}
#From the back of the string
echo ${another_scalar} "->" ${another_scalar%e*s}
#Longest possible match
echo ${another_scalar} "->" ${another_scalar%%e*s}
string_to_change="Lecture01.ipynb"
an_empty_var=
echo "1." $an_empty_var
echo "2." ${an_empty_var:-Default}
echo "3." $an_empty_var
echo "4." ${an_empty_var:=Default}
echo "5." $an_empty_var
echo "Your home dir is: $HOME"
echo "You are logged into: $HOSTNAME"
echo "Your shell is: $SHELL"
echo "Your path is: $PATH"
echo "Your terminal is set to: $TERM"
cat src/shell/cla_examples.sh
./src/shell/cla_examples.sh --some-flag a_path additional_options another_one
echo "Process ID (PID) is: $$"
echo "Parent PID (PPID) is: $PPID"
whoami
echo "Status of last command: $?"
./src/shell/demo1.sh data/noodles