> For the complete documentation index, see [llms.txt](https://42-guide.gitbook.io/42-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://42-guide.gitbook.io/42-guide/piscine-life/shell00/midls.md).

# midLS

**Objective:**

The goal of this exercise is to create a command that lists all files and directories in the current directory (excluding hidden files and directories) in a specific format. The output should be sorted by modification date, and directory names should be followed by a slash (`/`).

**Instructions:**

1. **Create a File Named `midLS`:**
   * In the `ex04/` directory, create a file named `midLS`.
   * This file should contain a command or script that lists all files and directories in the current directory, excluding hidden files (those starting with a dot `.`), and separates them by a comma and a space.
2. **Format the Output:**
   * The output should list files and directories in order of their modification date (oldest first).
   * Directory names should be followed by a slash (`/`).
   * The output should not include hidden files or directories (those starting with a dot `.`).
3. **Example Output:**
   * If your directory contains the following files and directories:

     ```
     file1.txt
     dir1/
     file2.txt
     dir2/
     ```
   * The output of your `midLS` command should look like this:

     ```
     file1.txt, dir1/, file2.txt, dir2/
     ```

**Detailed Steps:**

1. **Create the `midLS` File:**
   * Open your terminal and navigate to the `ex04/` directory.
   * Create a file named `midLS`:

     ```bash
     touch midLS
     ```
2. **Write the Command:**
   * Open the `midLS` file in a text editor and add the following command:

     ```bash
     ls -ptm
     ```
   * This command does the following:
     * Lists all files and directories in the current directory, excluding hidden files.
     * Sorts them by modification date.
     * Appends a slash (`/`) to directory names.
     * Separates the output with a comma and a space.
3. **Make the File Executable:**
   * After saving the file, make it executable by running:

     ```
     chmod +x midLS
     ```
4. **Test the Command:**
   * Run the `midLS` command to see if it produces the expected output:

     bashCopy

     ```
     ./midLS
     ```

**What You Will Learn:**

* **File Listing:** You will learn how to list files and directories in a specific format using the `ls` command.
* **Sorting by Date:** You will understand how to sort files and directories by their modification date.
* **Excluding Hidden Files:** You will learn how to exclude hidden files (those starting with a dot `.`) from the output.
* **Formatting Output:** You will gain experience in formatting command output using tools like `awk`, `xargs`, and `sed`.

**Useful Resources:**

* [**Linux LS Command**](https://linux.die.net/man/1/ls)**:** Official documentation for the `ls` command.
* [**AWK Command**](https://www.gnu.org/software/gawk/manual/gawk.html)**:** A guide to using `awk` for text processing.
* [**SED Command**](https://www.gnu.org/software/sed/manual/sed.html)**:** Documentation for the `sed` stream editor.
* [**Xargs Command**](https://linux.die.net/man/1/xargs)**:** A guide to using `xargs` for building and executing command lines.

**Conclusion:**

This exercise helps you understand how to manipulate and format file listings in a Unix-like environment. By completing this exercise, you will gain practical experience in using command-line tools to filter, sort, and format output, which are essential skills for any developer working in a terminal environment.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://42-guide.gitbook.io/42-guide/piscine-life/shell00/midls.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
