Module lessons (1/2)
Where am I? (pwd and ls)
The Linux command line (or terminal) is an extremely powerful tool that lets you interact with the operating system by typing text commands instead of using a graphical user interface.
All files and folders in Linux are organized in an inverted tree structure starting from a common root directory, represented by a single forward slash / (referred to as root). Every user has their own personal folder inside /home, for example, /home/user. This is known as the home directory.
Knowing Where You Are: pwd
In the terminal, you are always positioned inside a specific folder, called the current working directory.
To find out which folder you are currently in, you can use the command:
pwdThis command stands for Print Working Directory. If you run it right after opening the terminal, you will typically see the path to your home folder, for example:
/home/userListing Contents: ls
To see what files and folders are present inside your current directory, use the command:
lsThis command stands for List. It will show the names of all visible files and folders in your current location.
Useful Options for ls
Linux commands can be customized using options (also called flags or arguments), prefixed with a hyphen -:
ls -a: Lists all files, including hidden files that start with a dot (like.bashrcor.git).ls -l: Displays the listing in long format, including details such as file permissions, owner, file size, and the date/time of last modification.- You can combine these flags by writing
ls -laorls -alto see all files in a detailed list.
For example, running ls -la in a sample folder might display a structured output like this:
drwxr-xr-x 2 user user 4096 May 22 12:00 .
drwxr-xr-x 3 user user 4096 May 22 12:00 ..
-rw-r--r-- 1 user user 220 May 22 12:00 .bashrc
-rw-r--r-- 1 user user 18 May 22 12:00 info.txt
drwxr-xr-x 2 user user 4096 May 22 12:00 documentsIn this output:
- Lines starting with
d(e.g.drwxr-xr-x) represent directories (folders). - Lines starting with
-(e.g.-rw-r--r--) represent regular files. .and..are special shortcuts linking to the current and parent directories..bashrcis a hidden file, recognized by its leading dot.
Try it yourself
Exercise 1: Find your position
Write the command to find the current working directory you are in.
Show hint
Use the command that prints the absolute path of the current directory.
Solution available after 3 attempts
Exercise 2: List files
List the files in the current folder to see what resources are available.
Show hint
Use the fundamental command for listing contents.
Solution available after 3 attempts
Exercise 3: Show hidden files
Use the ls command with the appropriate flag to display all files in the current directory, including hidden files starting with a dot.
Show hint
Use ls combined with the -a option.
Solution available after 3 attempts