Cheat Sheet
The shell is dark and full of terrors. Take this:
File Navigation
ls
Lists the contents of a directory
ls -t
Sorts entries by time
ls -a
Lists all contents, even hidden
ls -1
Forces single column output
ls -h
Lists contents in human-friendly units
pwd
Shows the current working directory with full path
ls -l
Displays permissions, links, owners, etc.
cd
Changes directory, cd ..
changes to parent directory. Alternatively, can enter full path, e.g. cd /home/user1/Documents/
ls -m
Displays content in single line, separated by comma
cd d + TAB key
TAB will auto-fill IF there is a unambiguous match
ls -R
Lists content recursively, e.g. including content from directory
cd /dir
Regardless of current working dir, user will change to /dir
File Manipulation
mkdir dir1
Creates new directory
mv origFile newLoc
Moves file to new location
mkdir dir1 dir2
Creates directory, or several ones
mv doc1 doc2 new
Moves multiple files to new location
cp origFile newDes
Copies file to new destination
mv -n doc1
Does not overwrite existing file
cp doc1 doc2 new
Link mkdir, can copy many files at once to a destination
rm -R
Deletes a directory
cp -i origFile new
interactive mode, ensures no overwrite
rm doc1
Deletes a file
cp doc* dir
*wildcard copies all files that start with "doc" into dir
rmdir dirName
Deletes an empty directory
cp file *.jpg new
Copies all jpg's that start with file into new
rm doc1 doc2
Deletes multiple files at once
sort
Sorts input
uniq
Filters out consecutive duplicated lines
Redirection & Pipelining
cat file
Displays content of a file
ls | sort
Pipelining, first lists then sorts
cat doc1 > doc2
Performs like a copy, using redirection operator
ls /home -a sort | uniq
All unique items in home dir
cat doc1 >> doc2
Appends doc1 to end of doc2
wc file1
Word, line, and byte count of file1
ls -l /user/home > home.txt
Lists contents of home to home.txt
wc -l file1
Returns lines in file1
sort file1
Sorts the contents of file1 line-by-line
grep
Processes text line-by-line and prints any matching patterns
sort file1 > sorted
Sorted file1 content saved to sorted
ls dir1 | grep "zip"
Shows all zip files in our dir1 path
uniq file1
Filters out duplicate lines from file1
grep -c "Error" log.txt
returns number of "Error" in log.txt
grep -i Error log
case insensitive search for "Error" in log
ls -R /home | grep "txt" | less
Shows all text files in /home
ls -a /home | sort > homeDir.txt
Saves sorted list of /home into homeDir.txt
Utility
clear
Clears the console, same as ctl-L
echo $HOME
Displays contents of the home directory
history
Shows complete list of previously executed commands
head File1
Displays first ten lines of File1
man ls
Show the documentation for a command
tail File1
Displays last 10 lines of File1
You can also print this list for later reference:
About TryBash:
TryBash was initially created as a student project at the HTW Berlin in the summer semester of 2016.
The idea was to create an interactive learning game that teaches some basics of modern Unix shells, like bash
. During the semester we wrote content, developed a JavaScript based Bash Emulator, and combined those parts into the game.
All our code and everything we did is open source on GitHub. If you want to contribute ideas, add a lesson, or just fix a really obvios tpyo, feel free to engage in any way.
You are just searching for a command line emulator to try quickly out something in your browser?
That's exactly what you can do with our standalone Bash Emulator.