Advanced terminal Flashcards
What are package managers?
A Package management system is a collection of software tools that automate the process of installing, upgrading, configuring and removing computer programs for a computers OS and/or web dev environment in a consistent manner.
Package managers such as npm or Yarn basically help speed up the process of downloading and using sourcecode (their package format) from the web in your app development.
What are the differences between Homebrew, Yarn and npm?
Homebrew is a package manager for your OS, Yarn and npm are managers for source code useful during software development. Homebrew can be used to download Node and Yarn. Node.js comes with its own installer on Nodejs.org. Homebrew is also written in the Ruby version that comes installed in your mac. Homebrew also is wired up to git so when you choose to install any new OS feature you also connect to git and run your ruby code.
What was the downloading process before package managers? With package managers?
Before package managers, if you wanted to download code from a company you would download it like you would a compressed zipped file (in this case the file would be an archive of code), you would need to unzip that file (or unarchive it), you would then have to run a bunch of cryptic commands to configure the code.
Package managers do all these things for you plus it uploads all dependencies needed to run the code successfully (if you don’t already have them) and it looks to see if there are any updated versions of your desired package automatically.
How would you install Yarn?
$ brew install yarn -g (npm would NOT be the package manager to use)
What are some commands for Homebrew useful in maintaining the package manager?
$ brew update, $ brew doctor, $ brew upgrade. $ brew outdated (returns programs that are outdated on ur machine)
When you run update what’s the one specific technical thing that happens?
In homebrew we deal with instructions to install called formula or formulae. Running brew upgrade mongodb would trigger homebrew finding and installing the formula needed to upgrade mongodb. Whereas homebrew update would have homebrew update itself. When you update your Homebrew, it searches for updates and downloads all new (ruby written) formulae (instructions on how to install and where to find the necessary files and dependencies).
Why use Homebrew over npm?
Homebrew helps you install OS software that Apple computers don’t come installed with. Brew is not geared towards software development and software packages (unless of course you’re downloading another package manager).
What is cURL and wget?
cURL and wget are tools available with Homebrew to install software from the web (you use cURL when writing the rubbish ruby code to install Yarn for example). Both can also help in downloading entire websites by typing the urls.
The GNU Linux wget command, formerly named Geturl, is used to download non-interactive information from web servers such as web sites info. It supports HTTP, HTTPS, FTP, and reading of HTTP proxies. You might type in for example wget http://website.com/files/file.zip. It does NOT come installed in macs.
macs comes preinstalled with cURL. IOS does not come preinstalled with curl. curl is more interactive than wget in that it lets us read information from web servers but also let’s us write to them as well. It allows for 10+ different protocols. It also has a ton of features like authentication, cookie mgt., HTTP post, saving files from the web and testing RESTful APIs!!!
Running $ curl google.com would return the entire html script from the google website.
If you ran $ curl http://localhost/:3000 you would have returned to your cli whatever would otherwise be returned on a browser, you’d also get a response status code, a Content-Type (ex: application/json), Content-length (95), Server (server name), Date (date type).
curl -d “first=Mike&last=Yolo” http://localhost:3000/methods would actually run a POST method.
What are brew services and give examples of them.
Brew services are tools used in integrating the Homebrew formulas downloaded during software updates to MacOs, in the end helping use the formulas to download and configure code.
Brew services are tools built inside Homebrew useful in integrating Homebrew formulae with macOS. Some examples of these services are:
- $ brew install mysql
- $ brew services start mysql
- $ brew services run mysql
- $ brew services stop mysql
- $ brew services restart mysql
- $ brew services list
- $ brew services run|start|stop|restart -all
What is the bin directory and where is it found?
The bin directory stores applications, many of them essential binary code necessary to run some of your important utilities like your terminal. It is part of the filesystem hierarchy standard created by Linux for Unix-styled software to follow.
Bin is short for binary, this folder contains essential binary files or binary appications or system applications such as shells (like bash) and commonly used commands like ‘cp’,’mv’,’rm’,’cat’. it’s where you can expect to find apps on your OS.
To find the bin directory on your mac open your finder application from the dock and in the mac menu bar click on ‘Go’, then ‘go to folder’, lastly type in what you want to go to like ‘/usr/local/bin’.
How would you create a custom bin folder?
Easy. Create a folder as you would otherwise (mkdir) then make sure to include the following code in your bin file: PATH=$PATH:$HOME/bin, this will ensure your bin folder is in your $PATH variable. Then to use it simply add working scripts into the bin folder. To run the scripts simply call them from the cli like so –> $ yourShellScript.sh
Explain piping
To understand piping you need to understand what the Process object is. The process object is a global object within Node (meaning it’s always available to Node apps without using the require( ) method) that allows users to control the flow of data in a current running process.
Process listens for several events that fire during your process such as event warning, event unhandledRejection, uncaughtException, etc. These events are basically things that your process can be asked to listen to and responde with functions to.
Every process/running program has 3 pipes, each pipe has one of three data streams: stdin(0), stdout(1), stderr(2), all of which handle data flow. process.on( ‘warning’, function )
Then you have methods that sit on the Process object, methods like argv, abort, chdir, config, env, stdin, stderr, stdout!!! You’d call these using:
process. stdin.on( ‘readable’, function )
process. stdin( ‘end’, function )
process. stdin.setEncoding( ‘utf8’ )
process. stdout.pipe( process.stdout )
process. env –> returns an object w/ env info about a process
process. argv(2)
These pipes have 3 data streams: STDIN(0), STDOUT(1) STDERR(2). Think of STDIN as text we pass into a file and STDOUT as text we pass into the terminal or shell. When the program errors out it goes through the STDERR pipe.
You’re familiar with piping (using data streams) and redirecting of data give examples of how you would do this.
If you were to use pipe or redirect you should know that pipe and redirect are really just ways to manage I/O system inputs and outputs. If we want to redirect the output of a certain process to a file we might type:
$ ps -ax > myFile.txt
To append output of a process to a file:
$ ps -ax»_space; myFile.txt
To pass output of a process to something that does some function on that output we’d use piping:
$ ps -ax | grep Finder
http://www.westwind.com/reference/os-x/commandline/pipes.html
$ cat ace - print file contents to the shell
$ echo ‘start of something great’ > myFile.txt
$ echo ‘and more awesome’»_space; myFile.txt
$ mail -s ‘I…have a dream’ mike < speech.txt
$ ps aux | less
I (pipe)
> (redirect)
SHELL COMMANDS. What do these do: $ ^Z $ ^R $ ^C $ fg $ Bg $ ^T $ ^K
^ (ctrl)
$ ^Z –> ( ctrl z ) suspends a program, never to be brought up again.
$ ^R –> ( ctrl r ) “search terminal history.”
$ ^C –> ( ctrl c ) the nice version of suspending a process, this is a polite kill. Entered twice.
$ fg –> foreground. This recovers the work if you suspend a program. Brings program into foreground.
$ Bg –> background. This puts the process into the bg
$ ^T –> open new tab.
$ ^K –> clear page
SHELL COMMANDS What do these do $ tail /path/to/file.log $ tail -f /path/to/file.log $ tail -20 /path/to/file.log $ grep 'find me in the file' rolodex.txt $ man cd $ kill $ sudo kill | sudo open | sudo -u mike rm ~/mike/Documents/deleteme.txt $ wc fileName.txt ( think wordcount ) $ du fileName.txt $ chmod $ ps $ pdcopy $ pbpaste $ file fileName.txt
$ tail /path/to/file.log –> this prints to the screen the last 10 lines of the file.
$ tail -f /path/to/file.log –> this prints to the screen the last 10 lines of the file and anything added.
$ tail -20 /path/to/file.log –> this prints to the screen the last 20 lines using the STDOUT data stream.
$ grep ‘find me in the file’ rolodex.txt –> what do you think grep does?
$ man cd –> easy, think on it.
$ kill –> kills processes and for use on system processes you’d need to prepend sudo to it.
$ sudo kill | sudo open | sudo -u mike rm ~/mike/Documents/deleteme.txt –> system changes! Sudo usually needs to confirm the user password and username though.
$ wc fileName.txt –> think word count, this returns information about the file to the screen. It displays the number of newlines, words and bytes (-c), words (-w), and lines (-l) inside the file, and even multibyte characters (-m).
$ du fileName.txt –> returns disk usage info.
$ chmod –> change mode is used to change permissions or alter special mode flags on files and directories. Usage: chmod o-w file1 (r=readable, w=writable, x=executable, d=directory, -=if a file). https://www.seas.upenn.edu/cets/answers/chmod.html
$ ps –> process status command is used to provide info about the current running process, reminiscent of brew services list.
$ pdcopy –> clipboard copy.
$ pbpaste –> clipboard paste.
$ file fileName.txt –> determine the file type (usually unneccessary since the extension usually tells the file type).