Ade Malsasa Akbar contact
Senior author, Open Source enthusiast.
Thursday, March 29, 2018 at 17:09


This the first part of a command lines practical tutorial for new users of Ubuntu. This article gives you the first lesson of navigation (pwd, ls, cd) in 12 set of commands by comparing terminal and file manager windows on same screen. The aim of this first part is so that a beginner has very basic skills of using commands in Terminal. This set of basic skills is needed to continue to any of the next command lines lessons. Happy exercising!

Subscribe to UbuntuBuzz Telegram Channel to get article updates directly.

Intro


This series is a practical, less theoretical tutorial for beginners starting from the easiest lessons. This tutorial stresses the user to practice the command lines on their own Terminal. This means it doesn't make user busy with terms and explanations, but rather busy with practicing. This series is verily intended for students at schools and such kind of users who want to learn command lines without any previous experience of it. This tutorial is based on Ubuntu 17.10 "Artful Aardvark" and is applicable to any other Ubuntu version.

To follow this series of tutorial, you open your Terminal on Ubuntu by pressing Ctrl+Alt+T or find it from desktop menu either it is named Terminal, GNOME Terminal, Konsole, or LXTerminal. A terminal looks like this while running commands:


  • The prompt of your Terminal is like that master@master:~$
  • Second name after @ "master" means your Home is located at /home/master.
  • The command starting with $ means to be run as normal user.
  • The command starting with # means to be run as root user.
  • To run a command, type the command and press Enter key on your keyboard.

The Command Lines Used


Mastering navigation is mastering three commands:
  • pwd
  • ls
  • cd

Preparation


Learning command lines (or, operating the Terminal) is just the same as operating your file manager. Same. So to learn basic navigation you compare your Terminal screen with your file manager screen. So make your desktop looks like this:


Command 1


$ pwd
$ ls
$ ls -d */

Command 2


Change "master" below with your own directory.

$ pwd
$ cd ~
$ pwd
$ ls

$ cd $HOME
$ pwd
$ ls

$ cd /home/master
$ pwd
$ ls

$ cd ~
$ pwd

Command 3


$ pwd
$ cd ~/Desktop/
$ pwd
$ ls

$ cd ~/Download/
$ pwd
$ ls

$ cd ~/Pictures/
$ pwd
$ ls

$ cd ~/Music/
$ pwd
$ ls

$ cd ~/Public/
$ pwd
$ ls

$ cd ~/Videos/
$ pwd
$ ls

$ cd ~/Templates/
$ pwd
$ ls

Command 4


$ pwd
$ cd $HOME/Desktop/
$ pwd
$ ls

$ cd $HOME/Download/
$ pwd
$ ls

$ cd $HOME/Pictures/
$ pwd
$ ls

$ cd $HOME/Music/
$ pwd
$ ls

$ cd $HOME/Public/
$ pwd
$ ls

$ cd $HOME/Videos/
$ pwd
$ ls

$ cd $HOME/Templates/
$ pwd
$ ls

Command 5


Change "master" below with your own directory.

$ pwd
$ cd /home/master/Desktop/
$ pwd
$ ls

$ cd /home/master/Download/
$ pwd
$ ls

$ cd /home/master/Pictures/
$ pwd
$ ls

$ cd /home/master/Music/
$ pwd
$ ls

$ cd /home/master/Public/
$ pwd
$ ls

$ cd /home/master/Videos/
$ pwd
$ ls

$ cd /home/master/Templates/
$ pwd
$ ls

Command 6


$ pwd
$ cd /
$ ls
$ ls -d */

Command 7


$ pwd
$ cd /
$ cd /home
$ ls

$ pwd
$ cd /
$ ls -d */
$ cd /home/master/
$ ls -d */
$ cd /home/master/Downloads/
$ ls -d */
$ pwd

$ cd /
$ pwd

Command 8


Before everything, show / folder in your file manager.



Then, do these commands:

$ cd /
$ cd /usr
$ pwd
$ ls -d */

$ cd /bin
$ pwd
$ ls -d */

$ cd /boot
$ pwd
$ ls -d */

$ cd /etc
$ pwd
$ ls -d */

$ cd /home
$ pwd
$ ls -d */

$ cd /lib
$ pwd
$ ls -d */

$ cd /media
$ pwd
$ ls -d */

$ cd /sbin
$ pwd
$ ls -d */

$ cd /tmp
$ pwd
$ ls -d */

Command 9


$ ls /
$ ls -d */

$ ls /home
$ ls -d /home/*/

$ ls /home/master
$ ls -d /home/master/*/

$ ls /home/master/Downloads/
$ ls -d /home/master/Downloads/*/

$ ls /home/master/Documents/
$ ls -d /home/master/Documents/*/

$ ls /home/master/Pictures/
$ ls -d /home/master/Pictures/*/

$ ls /home/master/Public/
$ ls -d /home/master/Public/*/

Command 10


Just like Command 8, compare these to your file manager.

$ ls /
$ ls -d */

Then, perform following commands:

$ ls /bin
$ ls -d /bin/*/

$ ls /lib
$ ls -d /lib/*/

$ ls /sbin
$ ls -d /sbin/*/

$ ls /media
$ ls -d /media/*/

$ ls /tmp
$ ls -d /tmp/*/

Command 11


Where is your USB flash drive? Where are your partitions? Open up your file manager and open your drives from it. Assume their name are MIGNU and libre2. However, MIGNU is actually my personal flash drive and libre2 is my data storage partition.


Then perform these commands, by changing "master" into your username:

$ cd /media
$ ls
$ cd master/
$ ls
$ cd MIGNU/
$ ls
$ pwd

$ cd /media
$ ls
$ cd master/
$ ls
$ cd libre2/
$ ls
$ pwd

Compare the output with your file manager opening the flash drive MIGNU.


Compare also the second result with file manager opening libre2 partition.


Command 12


How if your folder has space in its name? For example, how to enter folder named 'my files' and 'my folder' like those in MIGNU above? Now perform these commands:

$ cd /media/master/MIGNU/
$ ls
$ cd "my files/"
$ pwd
$ cd ..
$ cd "my folder/"
$ pwd



Summary


What do you get from those lessons? In general, you get these:
  • pwd is print working directory, same as Ctrl+L (address bar) in file manager
  • ls is list, same as main area of file manager where you see folders & files
  • cd is change directory, same as double-clicking folder in file manager

Detailed Summary


In details, from what you have practiced above you get these:

  • directory address is separated by / (slash) and not by \ (backslash)
  • a command is usually followed by address such as cd /home
  • a command can have option such as -d
  • your user location is at* /home/master, with the alias ~ or $HOME
  • your root filesystem is at /, where your /home, /bin, /etc located
  • your external partitions and USB flash drives, when mounted (activated), are located at /media/{your_username}/{your_drive_name}
  • your file manager cannot show only-folders (hide files) but your command can, by using ls -d */
  • you use quotes ( " " ) to type folder name that has space


*) change "master" with your actual username.


to be continued...



This article is licensed under CC BY-SA 3.0.