Command Line Basics

This page’s content is authored by AvanRocks

The CLI, or Command Line Interface, is a text-based way to do stuff on your Linux computer. (Back in the old days, this was actually the only way to interact with the computer).

Terminology

Filesystem hierarchy

Note: if you append a slash (/) to a directory name, it doesn't change the meaning (it doesn't matter). This is not the case for files, however.

You may be familiar with these terms from using Windows/macOS, but it is useful to know how to use file paths in a Terminal.

Terminal

Commands

sudo - super user do

pwd - print working directory

ls - list

cd <name> - change directory

cd Documents/notes/

You can even chain ‘..’ like this:

cd ../../../

man <command> - manual

More Basic Commands

mkdir (make directory)

mkdir myDir
mkdir -p dir1/dir2/dir3

rmdir (remove directory)

rmdir myDir

touch

touch myFile

ls (some more options for ls)

only shows files with the name “myFile”

ls myFile
ls myF?le
    ls myF*
    ls myFile[ab]
    ls myFile[a-z]
    ls myFile[!a]

echo

echo Hello, world!
    echo stuff > myFile
    echo stuff >> myFile

cat (concatenate)

cat myFile
    cat -n myFile

rm (remove)

rm myFile
    rm -i myFile
    rm -r myDir
    rm -ir myDir

cp (copy)

cp myFile myCopiedFile
    cp -i myFile myNewFile
    cp -r myFile myNewFile
    cp myFile otherDir/overHere/myCopiedFile

mv (move)

mv myFile myNewFile
    mv -i myFile myNewFile
    mv myFile myDir/myNewFile
    mv myFile ../myNewFile
    mv myDir1 myDir2/
    mv myFile myDir/

tree

tree