---
title: "Part 2 [echo & ls] - Know your commands"
date: 2019-10-27
url: https://devsv.in/blog/know_your_commands_ls_echo/
tags: ["linux", "terminal", "knowyourcommands"]
description: "Hey folks, this is part 2 of the series Know your commands. This part of the series covers echo and ls."
---

# Part 2 [echo & ls] - Know your commands

Hey folks, this is part 2 of the series `Know your commands`.

If you are new here, please also checkout the other parts of this series.

- Part 1 - [pwd & cd](https://devsv.in/blog/know_your_commands_pwd_cd/)
- Part 2 - [echo & ls](https://devsv.in/blog/know_your_commands_ls_echo/)
- Part 3 - [touch & mkdir](https://devsv.in/blog/know_your_commands_touch_mkdir/)

In this part I will be covering the use of [echo](#echo) and [ls](#ls) commands.

---

## echo

echo command is used to output the strings that is being passed as an argument.

**Syntax**

```bash
echo [optional flag] [string]
```
**Usage**
```bash
$ echo "This will be print to the console"
This will be print to the console
```

___
## ls
ls stands for List. It is used to list the files and folders in current working directory.

**Syntax:**
```bash
ls [optional flags] [optional directory]
```
**Usage:**
```bash
$ pwd
/home/subin

$ ls
Desktop
Documents
Downloads
Music
Pictures
```
* `ls [folder_path]` - This command lists the files and folders in the specified path. The `folder_path` can be absolute or relative.
  ```bash
  $ pwd
  /home/subin

  $ ls Downloads
  movie
  ```
* `ls -a` - By default all files and folders that starts with `.` dot are hidden on your system. These files are hidden but yet it can be accessed by the system or any application installed. So don't try to rename you `Study material` folder to start with a dot to escape from your parents :wink:. 
  ![Study Material Meme](https://devsv.in/_astro/study_material.pwHL0BiY_Z1AlPh1.webp)
  These Dot Files are just plain text configuration files. These files can be listed using the flag `-a`. 


  ```bash
  $ pwd
  /home/subin

  $ ls -a
  .bashrc
  .config
  Desktop
  Documents
  Downloads
  Music
  Pictures
  ```
* `ls -l` - This command provides a long list. Running this command will return folder and files with additional details lik `permissions, owner, group, size, etc` 
  ```bash
  $ pwd
  /home/subin

  $ ls -l
  drwxrwxr-x 2 subin subin 4096 Nov  2 18:01 Desktop
  drwxrwxr-x 8 subin subin 4096 Oct 12 20:55 Documents
  drwxrwxr-x 3 subin subin 4096 Feb 10  2019 Downloads
  drwxrwxr-x 3 subin subin 4096 Feb 3  2019 Music
  drwxrwxr-x 3 subin subin 4096 Feb 7  2019 Pictures

  #Mutiple flags can be combined
  $ ls -la
  -rw-r--r--  1 subin subin 3488 Oct 20 2018 .bashrc
  drwx------  3 subin subin 4096 May 5  2018 .config
  drwxrwxr-x  2 subin subin 4096 Nov 2  2018 Desktop
  drwxrwxr-x  8 subin subin 4096 Oct 12 2018 Documents
  drwxrwxr-x  3 subin subin 4096 Feb 10 2019 Downloads
  drwxrwxr-x  3 subin subin 4096 Feb 3  2019 Music
  drwxrwxr-x  3 subin subin 4096 Feb 7  2019 Pictures
  ```
* Other popular `ls` commands

    Command | Description 
    --------|-------------
    ls -lh  | Long list with readable file size        
    ls -R   | Lists the directory tree recursively      
    ls -r   | Displays the list in Reverse order    
    ls -s   | Displays the list with File Size
    ls -S   | The displayed list is sorted by File Size      
    ls -t   | The displayed list is sorted by Time & Data
    ls -x   | The displayed list is sorted by Extension

* The above flags can be combined in multiple ways to build complex results.

___
## What's next
As of now you should be familiar with `pwd, cd, echo, ls`, with these you should be able to comfortably navigate between the file system with ease. So why wait, let's celebrate your accomplishment.

![Jig Dance Meme](https://devsv.in/_astro/jig_dance.Bt9-IeBW_1G9uMU.webp)

The next part of this series will focus on `touch` and `mkdir` commands. Stay tuned

---

**Note:**
All examples above are based on below imaginary directory structure.

```
.
├── home
│   └── subin
│       ├── .bashrc
│       ├── .config
│       ├── Downloads
│       │   └── movie
│       │       └── some_movie.mp4
│       ├── Desktop
│       ├── Documents
│       │   └── test_doc.txt
│       ├── Music
│       └── Pictures
├── lib
├── opt
└── tmp
```
