Bash comands: Udacity intro to shell commands


I am using the command line daily now as a dev. Before starting as a dev I was a fulltime Windows user, because games, that's why.

Since april I've been using MacOs and the terminal daily. Though I don't feel as expressive in the terminal as I feel in my IDE. So it's time to become more proficient. Deliberate practice!

I found a basic course at Udemy to strengthen some fundamentals:
https://classroom.udacity.com/courses/ud595/

[Lesson 1]
Terminal emulator: nothing more than a data entry point
BashShell: interpreter of terminal commands
BashShell is a command line interface, like the python or ruby interpreter or js console

date > prints date and time
expr 2 + 2 > evaluates the expression 2 + 2
echo You rock > prints you rock
uname > prints the unix flavour, for me "Darwin"
hostname > prints hostname of current machine
host cd udacity.com > prints info on the host
bash --version > shows bash version
history > shows bash history

A function in code and a shell command:
- consist units of code
- both have a name
- can both take arguments

but:
commands are commands to programs
functions are used to organise a program

>>'<< A quote signals that the command will continue to the next line


[Lesson 2]

ctrl + r > search your history for a certain command
tab > also autocompletes file names, completes with a shared part if multiple files with a similar name exist

wc name.txt > prints line count, word count, character count
diff name.txt name_draft.txt > compares two text files and shows difference

man [shellprogram] > shows manual pages of a program
options between [***] are optional

[ls] by default doesn't display files starting with a dot, use it with [-a]

!!!DON'T RUN THIS!!!
[ rm -rf / ] > remove all files and directories recursively and forcefully, starting at your root folder

stop a command line program like ping with ctrl + c

some programs read [ stdin ] > write [ stdout ]  in a chained pipeline and run after receiving an end of file character (ctrl + d)

bc > calculator program

[Lesson 3]
If a filename has a punctuation like ! or @, use quotes ['filename!'] or escape with backslash [filename\!].

In a linux file system the top directory is (root).
There is no seperate root per disk, like in windows.

filepaths:
cwd > abbreviation for current working path
pwd > program that prints patch of current working directory

[waka] > waka is located in the current working directory

. /[waka] > waka is located in current working directory

 . . /[waka] > waka is located in the parent directory

~/[waka] > waka is located in the personal user directory *on Mac that's [Users/${username}]

a few basic crud programs:
rm
cp
touch 
mkdir
rmdir

globbing (how to use wildcards)
bean.jpg
Mean.JPEG

ls *ean* > shows both
ls *{jpg, JPEG} > shows both !!!this command does not accept spaces!!!
ls *b* > shows bean.jpg

[Combine it all]

folderstructure:
home/username/ > cwd
home/username/www
home/username/backup

copy all the files in the www directory ending with html to backup
cp www/*html backup/

list all the files in the cwd ending with jpg or png
ls *{jpg,png}

print "Short names:" followed by all the one character filenames
echo Short names: ?

Comments

Popular posts from this blog

Deep fakes, fake news, it's old news!

Thinking about tech: Technological Determinism

Software development as a growing profession - Present