Skip to content

Instantly share code, notes, and snippets.

@aviflombaum
Created June 6, 2012 20:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save aviflombaum/a8a7ca963e37e0b108b9 to your computer and use it in GitHub Desktop.
Save aviflombaum/a8a7ca963e37e0b108b9 to your computer and use it in GitHub Desktop.
Bash Basics
BASH Basics
BASH is a text-based shell for controlling your computer (or operating system).
From it you can navigate the files on your computer and execute programs.
You can also connect to other computers and basically do everything you can do
in your GUI Operating System (like OS X or Windows).
When you open a terminal, you're basically within your file system, or in a
directory, just like you are when you open a Finder window or an Explorer window.
Open up command prompt or terminal. Type in: pwd
You should see some output describing the directory you are currently within.
/Users/avi
That output is describing a location on your computer. You have a file system
and within that file system are directories and files.
The command pwd stands for print working directory.
/User/avi means that I am currently working within a directory /Users on the
root of my machine, and then within that directory, a directory named avi.
That's my home directory. It belongs to the user I am currently logged in as.
A short cut for a users home directory is the ~ character.
Try this:
cd ..
pwd
You should now see that you are one directory above where you were, in my case
/Users
cd stands for change directory
.. stands for the directory above the working directory.
Try this:
cd .
pwd
You can see you are still in the same directory.
. is a shortcut for the current directory.
So three shortcuts within your filesystem
~ - Home directory
. - current directory
.. - directory above
You can supply any path to the cd command to navigate to that location.
Try this:
ls
You should see a list of all the files within your working directory.
ls stands for list.
Try this:
cd /Users/avi
pwd
The working directory is back to /Users/avi.
The path supplied to the cd command, /Users/avi is known as an absolute path.
Systems can use either absolute or relative paths.
An absolute path is a path that points to the same location on the file system regardless of the working directory. They start with / because that is the root
A relative path is a path relative to the working directory of the user or application, so the full absolute path will not have to be given. They start
with the name of a directory or a file.
Paths use / to denotate levels.
How many levels are within the following path?
/Users/avi/Desktop/Rails Course/ruby course/summer 2012/lecture1
More on paths:
http://en.wikipedia.org/wiki/Path_(computing)
From within a shell, you can also execute programs. Navigate to where you saved
your hello_world.rb file and try:
ruby hello_world.rb
This command is no different then the cd command. We're executing the ruby program by supplying a path to a file to execute.
Most programs also accept flags or options for execution.
A flag is denotated by a -
A common flag 99% of programs and commands accept is h, for help.
ruby -h
Login Routine
bash_profile
PATH and Environment Variables
/usr and /usr/local
bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment