Basic Ubuntu Commands
This is a list of the most basic but extremely useful commands. Learning these will help you have a
strong foundation to add more sophisticated commands upon.
Here are some words that we use and some meanings that you may associate them with.
We use What you may know them as
directory folder
sudo Run as Administor
terminal Shell
prompt active command line
echo print
Sudo
(Superuser DO) This is the same as "Run as administor"
user@my_computer_name:~$ sudo
apt-get
This command is used to install, update, upgrade, and remove any package. Examples below will
show how to use in different ways:
• sudo apt-get update
superuser privileges. This command updates your system along with the packages that are
installed.
user@my_computer_name:~$ sudo apt-get update
• sudo apt-get upgrade
You will run this command after you ran
user@my_computer_name:~$ sudo apt-get upgrade
This will upgrade the packages that have available updates. You can also upgrade just one
package by adding a space along with the package name after upgrade.
user@my_computer_name:~$ sudo apt-get upgrade node.js
• sudo apt-get install package name you wish to install You would replace the package-
name with the name of the program you wish to install.
user@my_computer_name:~$ sudo apt-get install curl
echo
echo is that useful of a command but we are going to use it to help us learn about command line
arguments. In the example below each word in the command line is an argument.
user@my_computer_name:~$ echo Each word I enter in the command line is an
argument.
Each word I enter in the command line is an argument.
But if we wrap " " or ' ' around the sentence then that sentence would be just one argument.
Example:
user@my_computer_name:~$ echo "This sentence is only one argument"
This sentence is only one argument
The quotes " " or ' ' are ignored by the terminal (shell) but the sentence is counted as just one
argument. This is good to learn because if we have a file or directory with spaces in it's name and
we want to use that file or directory. We will have to use quotes " " or ' ' to tell the terminal to use it.
If we did not and we try to use a command cat to see the content of a file and the file has spaces in
it's name. The command would throw an error. So, in order to not throw an error we use quotes to
make the file or directory as one argument. Example:
user@my_computer_name:~$ cat "my python program.py"
This would return the content in that file.
ls
(list) command will list out the files in the current working directory you are in.
user@my_computer_name:~$ ls
Desktop Documents Webdev Dev
You can also look at different files in other directories by adding a space then the direct path to the
other directory you wish to look into.
user@my_computer_name:~$ ls Dev
Python JS HTML CSS
We can also see hidden files by using the -a
user@my_computer_name:~/Dev$ ls -a
.I_was_hiding Python JS HTML CSS .hidden.txt
This command will list all the files in that directory including hidden files.
• ls -t
This list command will return the directories or files in their time stamp order. This ls -t command
can also be combined with -a. This combination would return a list of the hidden directories or files
in their time stamp order. Example:
user@my_computer_name:~/Dev$ ls -a -t
HTML CSS JS .hidden.txt Python .I_was_hiding
whoami
(who am i) This command will return the username.
user@my_computer_name:~$ whoami
user
cd
(change directory) used to change the current working directory. You use it by typing cd space then
the file name within your current directory or full path to another directory and/or file if in a
different directory. Examples of different ways below:
• cd /
user@my_computer_name:~Dev/Python$ cd /
user@my_computer_name:/$
• This will take me to the root directory. Note that the ~ tilde is not in the return command
line.
• cd ..
user@my_computer_name:~/Dev/JS Practice$ cd ..
user@my_computer_name:~/Dev$
• This will take me from the JS Practice to it's parent directory Dev. Note that JS Practice
has a space. This is not a proper way to name a file
• In the example above: When I am in the Dev directory and want to access the file JS
Practice I can do this two ways:
1. user@my_computer_name:~/Dev$ cd "JS Practice"
2. user@my_computer_name:~/Dev$ cd JS\ Practice
• Both command lines would produce the same results. They would have cd (changed
directory) in to JS Practice. But try not to name files with spaces in them. Use an _
underscore instead of a space.
• cd -
user@my_computer_name:~/Dev$ cd -
user@my_computer_name:~/Dev/JS Practice$
• This took me to my previous directory from my History.
• cd ~
user@my_computer_name:~/Dev/JS Practice$ cd ~
user@my_computer_name:~$
• This took me to the user directory.
• This symbol ~ is called a tilde. This refers to your user directory.