Terminal Tutorial
An introduction to using a Unix/Linux/Something-else-nix Terminal.
something-here:~$
$
$ pwd
/home/urawesome
$
(Your terminal will say something different depending on the settings and your username.)$ ls
Desktop monkey.txt
Documents zebra.txt
$
(Again, your results will be different.)$ mkdir programs
$ ls
Desktop programs
Documents zebra.txt
monkey.txt
$
$ cd programs
$ ls
$
Notice there are no files in the new directory. Now let's use pwd to show the current directory:$ pwd
/home/urawesome/programs
$
$ touch textFile.txt
$ ls
textFile.txt
$
$ ls -l
-rw-rw-r-- 1 urawesome urawesome 0 Jan 1 14:11 textFile.txt
$
$ ls -a
. .. textFile.txt
$
. refers to this directory, while .. refers to the parent directory (where you were before changing directory).$ ls -al
drwxr-xr-x 2 urawesome urawesome 4096 Jan 1 14:09 .
drwxr-xr-x 49 urawesome urawesome 4096 Jan 1 14:10 ..
-rw-rw-r-- 1 urawesome urawesome 0 Jan 1 14:11 textFile.txt
$
$ ls ..
Desktop programs
Documents zebra.txt
monkey.txt
$ ls ../
Desktop programs
Documents zebra.txt
monkey.txt
$
Or we can specify only specific types of files:$ ls *.txt
textFile.txt
$
* is a 'wildcard' symbol, so that command will display all files ending in .txt (all text files). We can combine the two parts like so:$ ls ../*.txt
monkey.txt zebra.txt
$
However:$ ls ..*.txt
ls: cannot access ..*.txt: No such file or directory
$
$ ls ../programs
textFile.txt
$ ls ../programs/*.txt
textFile.txt
$
$ cd ..
$ pwd
/home/urawesome
$ cd ..
$ pwd
/home
$
Alternatively, you can specify the full directory path:$ cd /home/urawesome/programs
$ pwd
/home/urawesome/programs
$ cd ~
$ pwd
/home/urawesome
$
(The tilde, ~, is shorthand for the home directory.)$ cd programs
$ ls
textFile.txt
$ mv textFile.txt emptyFile.txt
$ ls
emptyFile.txt
$
$ mv emptyFile.txt ../emptyFile.txt
$ ls
$ cd ..
$ ls
Desktop emptyFile.txt monkey.txt
Documents programs zebra.txt
$
The signature for mv always looks like: mv <source> <destination>$ mv emptyFile.txt programs/emptyFile.txt
$ cd programs
$ ls
emptyFile.txt
$
If we specify the destination folder name, but not the destination filename, it will preserve the old name:$ mkdir textFiles
$ ls
emptyFile.txt textFiles
$ mv emptyFile.txt textFiles/
$ ls
textFiles
$ cd textFiles
$ ls
emptyFile.txt
$
$ cd ..
$ ls
textFiles
$ mv textFiles textOnly
$ ls
textOnly
$ ls textOnly/
emptyFile.txt
$
$ cp textOnly/emptyFile.txt textOnly/blankFile.txt
$ ls textOnly/
blankFile.txt emptyFile.txt
$
$ cp textOnly textFiles
cp: omitting directory `textOnly'
$
We can get around this by using the -r parameter:$ cp -r textOnly textFiles
$ ls
textFiles textOnly
$
$ ls textFiles/
blankFile.txt emptyFile.txt
$ rm textFiles/blankFile.txt
$ ls textFiles/
emptyFile.txt
$
$ rm textOnly/*.tx
rm: cannot remove `textOnly/*.tx': No such file or directory
$ rm textOnly/*.txt
$ ls textOnly/
$
Warning: there is no undo command! rm will permanently delete your files! Always proceed with caution, especially when using wildcards! As a safeguard, rm won't delete directories unless you include the -r parameter. Don't type in the following commands unless you want to remove all files, then all folders in the directory you're in.$ rm *
rm: cannot remove `textFiles': Is a directory
rm: cannot remove `textOnly': Is a directory
$ rm -r *
$ ls
$
Do not use rm lightly!$ mkdir superMonkeyBonusDirectory
$ mkdir superMonk
We don't want to type out the whole thing. Instead, hit tab. Since there is only one possibility, it will automatically fill out the rest for you:$ mkdir superMonkeyBonusDirectory
$ mkdir superMonkeyBonusDirectory/
We're not done with that line yet; we're going to make a subdirectory of the previous one:$ mkdir superMonkeyBonusDirectory
$ mkdir superMonkeyBonusDirectory/jackalCupcake
$
Let's make yet another directory inside that last one. Use tab completion to make it easy:$ mkdir s
Since there is only one file/folder in the working directory starting with 's', press tab:$ mkdir superMonkeyBonusDirectory/
Since there is only one file/folder in the subdirectory, press tab again:$ mkdir superMonkeyBonusDirectory/jackalCupcake/
Now type in the name of the new (subsub)directory you're creating:$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel
$
$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel
$
Press up once to see:$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel
$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel
Tab to get the slash:$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel
$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel/
And now enter the name of the new folder.$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel
$ mkdir superMonkeyBonusDirectory/jackalCupcake/oleOleBiscuitBarrel/cheeseWeasel
$
You can press up multiple times to see old commands. This is very useful if you're running the same program multiple times between editing files.