📱 The Shell - CLI vs GUI
Generally, a shell is the outermost layer of an operating system. It exposes an interface that allows a user to communicate with the kernel. This can be a graphical user interface (GUI) like a desktop environment, or a command line interface (CLI).
With some experience, the CLI is a much quicker way to navigate your operating system and perform any actions like opening an application or installing software. You're also not dependant on which parts a particular GUI exposes to you, or where to find the button you're looking for.
Ubuntu (like all Linux distributions) comes with the Bash Shell. Per Bash convention, the command prompt for a non-root user has the form
~ shows what the default working directory is (for a regular user, that's the
/home directory), the
$ indicates that the logged in user has no root priviliges. The root user would see a
Within a command, the
# character marks a comment, everything that follows will be ignored. Using it makes little sense unless you write a shell script with multiple lines.
📱 General Commands
# clear the terminal window clear # list the last 500 commands history # enter the most recent command into command line <up_arrow> # print user manual for a command man <command> # list all processes top # list information about hardware and kernel (see uname --help for options) uname
📱 Files and Directories
# list all files and folders in the current directory ls # detailed list ls -l # include hidden files and folders ls -a # list all files and folders in any directory ls </absolute/path/to/directory> # print current working directory pwd # go to root directory cd / # go to home directory cd cd ~ # locate the binary that is executed for a command which <command> # locate the binary, source and manual-page for a command whereis <command>
Handling files and directories
# open file manager with *root* priviliges sudo nautilus # create directory mkdir <dirname> # create file touch <filename> # rename and/or move a file mv <oldPath/oldFilename> <newPath/newFilename> # copy file cp <filename> <filenameOfCopy> # remove file rm <filename> # remove directory rmdir <dirname> # recursively remove non-empty directory rm -R <dirname>
Reading and writing to text files
# add text on a new line to a textfile echo <your-text> >> <filename> # display text content of file cat <filename> # join two text files and put the content in a third file cat <filename1> <filename2>><filename3>
# display the computer's hostname hostname # display IP address instead of hostname hostname -i # list network properties ifconfig # ping another computer ping <ipaddress> ping <domain> # display nameserver records for a domain nslookup -type=ns <domain> # download a file from the internet to the current directory wget <file_url>