Basic Linux Commands (Managing Files and Directories)

Known for its stability and flexibility, Linux has become an essential part of the computing world. With its open-source nature, Linux offers a variety of options for various needs, ranging from personal use to large servers. For users who want to master Linux, understanding its basic commands is crucial. This is not just about efficiency, but also about fully utilizing all of Linux’s capabilities.

Learning to use commands in Linux is similar to getting to know a new language. Each command helps us control the system more precisely and effectively. From managing files to monitoring the system, these commands are essential for interacting with Linux. In this article, we will discuss the basic commands that are a must-know for Linux users.

Linux Commands for File and Directory Management

1. The ls Command

The ls command is used to display a list of files and directories on the system.

$ ls [path/to/direktori]
    
                                                <img width="1024" height="134" src="https://tobaconsulting.com/wp-content/uploads/2024/02/image-11-2-1024x134.jpg" alt="" srcset="https://tobaconsulting.com/wp-content/uploads/2024/02/image-11-2-1024x134.jpg 1024w, https://tobaconsulting.com/wp-content/uploads/2024/02/image-11-2-300x39.jpg 300w, https://tobaconsulting.com/wp-content/uploads/2024/02/image-11-2-768x100.jpg 768w, https://tobaconsulting.com/wp-content/uploads/2024/02/image-11-2.jpg 1502w" sizes="(max-width: 1024px) 100vw, 1024px" />                                                    
    <p>Jika anda tidak menambahkan&nbsp;<em>path</em>, maka perintah&nbsp;ls&nbsp;akan menampilkan direktori terakhir yang sedang diakses. Berikut beberapa&nbsp;<em>option</em>&nbsp;tambahan yang dapat ditambahkan :</p>

If you do not specify a path, the ls command will display the current working directory. Here are some additional options that can be added:

  • -l is used to display complete details of the files and directories list.
  • -h is used to display the size of a file or directory in a more human-readable format.
  • -a is used to display all files within a directory (including hidden ones).

2. The pwd Command

$ pwd

This command is used to display the current location of the working directory being accessed.

    
                                                <img width="1024" height="169" src="https://tobaconsulting.com/wp-content/uploads/2024/02/image-12-2-1024x169.jpg" alt="" srcset="https://tobaconsulting.com/wp-content/uploads/2024/02/image-12-2-1024x169.jpg 1024w, https://tobaconsulting.com/wp-content/uploads/2024/02/image-12-2-300x50.jpg 300w, https://tobaconsulting.com/wp-content/uploads/2024/02/image-12-2-768x127.jpg 768w, https://tobaconsulting.com/wp-content/uploads/2024/02/image-12-2.jpg 1136w" sizes="(max-width: 1024px) 100vw, 1024px" />                                                    
    <h4>3. Perintah cd</h4>

3. The cd Command

$ cd <options>

This command is used to navigate or change directories. Here are some options that can be used with the cd command:

  • cd [path/to/dir] is used to enter a specific directory.
  • cd .. is used to move up one level from the current directory.
  • cd is used to move to the home directory.

4. The mkdir Command

This command is used to create one or multiple directories at once.

$ mkdir [path/nama direktori]

Let’s say you want to create a directory named test, you simply run the command mkdir test. If you want to create a subdirectory within the test directory without navigating into it, just run the command mkdir test/sub. Furthermore, if you want to create several directories simultaneously, you can run the command mkdir test_dir1 test_dir2 test_dir3.

5. The rmdir Command

$ rmdir [path/nama direktori]

This command is used to remove an empty directory.

6. The rm Command

$ rm [path/namafile]

This command is used to remove files. Additionally, it can be used as an alternative to remove a non-empty directory by adding the -rf option to the rm command, making it rm -rf [directory_name]. As a warning, this -rf option will delete the directory along with its subdirectories and the files inside them, so it is safer to add the -i option to prompt for confirmation before files are actually deleted.

7. The cp Command

$ cp [filename] [dirdest]

This command is used to copy a file to a target location. Besides copying files, this command can also copy a directory by adding the -r option:

$ cp -r [dirsource] [dirdest]

8. The mv Command

$ mv [filename] [dirdest]

While the cp command is used to copy a file or directory, the mv command is used to move a file or directory to a desired location (it is also used for renaming).

9. The touch Command

$ touch [namafile]

This command is used to create a new, empty file inside a directory.

    
                                                <img width="1024" height="248" src="https://tobaconsulting.com/wp-content/uploads/2024/03/image-14-1024x248-1.jpg" alt="" srcset="https://tobaconsulting.com/wp-content/uploads/2024/03/image-14-1024x248-1.jpg 1024w, https://tobaconsulting.com/wp-content/uploads/2024/03/image-14-1024x248-1-300x73.jpg 300w, https://tobaconsulting.com/wp-content/uploads/2024/03/image-14-1024x248-1-768x186.jpg 768w" sizes="(max-width: 1024px) 100vw, 1024px" />                                                  
    <p>Demikianlah beberapa perintah dasar yang digunakan untuk me-manage file dan direktori pada Linux. Dengan menggunakan perintah-perintah tersebut akan membuat efisiensi waktu saat menggunakan Linux. Diperlukan adanya latihan dan melakukan beberapa eksplorasi supaya dapat terbiasa menggunakan perintah-perintah tersebut.</p>       
        <h2>Share this article</h2>

Those are some of the basic commands used to manage files and directories in Linux. Utilizing these commands will improve your time efficiency when working with Linux. Practice and exploration are necessary to become accustomed to using them.

Index