Using BASH
Bash is available by default on Mac and Linux and can be access via git-bash (installed when git is installed) on Windows. Bash is a "command line interpreter" meaning that it awaits your commands, usually one line at a time and executes them.
You know you are in a bash shell if you see a dollar ($) prompt with a
blinking cursor awaiting your command.
Once you are at the bash prompt, you can find out who you are by typing
$ whoami
This will print your username.
Next we can find out where in the filesystem we are by typing
$ pwd
This will print the present working directory (within file system).
Here are some other basic commands to try out
-
$
lsList the contents of the present working directory. You can also- $
ls -a: lists all files including hidden ones. - $
ls -l: list files with details
- $
-
$
cd <directory path>Change directory. If no directory name is specified then present working directory is set to your $HOME. -
$
cat <filename>Prints the content of file<filename>. -
$
man <command>Prints the manual for<command>.
Reference of basic commands
Use $man <command> to learn more about these commands and flags.
basic shell
clear: clear all previous commands' output text from the terminalexit(orlogout) : quits the shellhistory: show a list of all past commands you have typed into this shell
manage directories
ls: list files in a directorypwd: displays the shell's current working directorycd: changes the shell's working directory to the given directory; can be a relative or absolute pathmkdir: creates a new directory with the given namermdir: removes the directory with the given name (the directory must be empty)
file operations
cp: copies a file/directorymv: moves (or renames) a file/directoryrm: deletes a filetouch: update the last-modified time of a file (or create an empty file)cat: output the contents of a filemore(orless) : output the contents of a file, one page at a timehead,tail: output the beginning or ending of a filewc: output a count of the number of characters, lines, words, etc. in a filedu: report disk space used by a file/directorydiff: output differences between two fileschmod: change the permissions on a file or group of fileschown: change the owner of a filechgrp: change the group associated with a fileumask: change the default permissions given to newly created files
searching and sorting
grep: search a file for a given string or expressionsort: convert an input into a sorted outputuniq: strip duplicate linesfind: search for files by name within a given directoryxargs: launch a command over each of a set of lines of input (often used with find)locate: search for files by name on the entire systemwhich: shows the complete path of a command or file
compression
- zip, unzip : create a .zip archive or extract its contents
- tar : Unix archiving/de-archiving program
- gzip, gunzip : GNU compression/decompression programs
- bzip2, bunzip2 : improved compression/decompression programs
system information
date: outputs the current date/timecal: outputs an ASCII calendaruname: print information about the systemtime: measure how long a program takes to run
process management
ps,jobs: list the processes you are running; every process has a unique integer id number (PID)top: see what processes are using the most CPU/memory, and show system memory/CPU statskill: terminate a processkillall: terminate a group of processes by name^C: (hotkey) terminates (kills) the currently running process^Z: (hotkey) suspends the currently running process&: (special character) when & is placed at the end of a command, that command is run in the background (shell does not wait for the command to finish before returning to the input prompt)
users
whoami: outputs your user namepasswd: changes your passwordgroups: list the groups to which a user belongssudo: execute a single command as the super-usersu: log in to a shell as the super-user
network
lynx: text-only web browserssh: connect to a remote Unix serverwget: download from a URL and save it to a file on the local hard drivecurl: download from a URL and output its contents to the console
text editors
vi,vim: good command line editoremacs: a complicated text editor with a steep learning curve
programming
node: run a JavaScript program, or enter JS shelljavac,java,python,perl,ruby,gcc,sml, ... : compile or run programs in various other languages