🖥️ Basic Linux Commands – Trade Theory for COPA

In Linux, the command line is one of the most powerful tools for interacting with the system. Through various Linux commands, you can manage files, monitor system performance, configure settings, and automate tasks. Mastering these basic Linux commands is essential for any Computer Operator and Programming Assistant (COPA) student.

In this section, we will introduce the most commonly used basic Linux commands and explain how they work.


1. Navigating the File System

Linux uses a hierarchical file system. To navigate and manipulate files and directories, you need to know some basic commands:

1.1 pwd – Print Working Directory

  • Description: Displays the current directory you are in.

  • Usage: To see where you are in the file system.

    bash
    pwd 

1.2 ls – List Directory Contents

  • Description: Lists files and directories in the current directory.

  • Usage:

    bash
    ls 

    You can use flags like -l for a long listing format or -a to show hidden files:

    bash
    ls -la

1.3 cd – Change Directory

  • Description: Changes the current directory to a specified directory.

  • Usage: To navigate to a different directory.

    bash
    cd /path/to/directory
    • cd .. moves up one directory level.

    • cd ~ takes you to your home directory.

1.4 mkdir – Make Directory

  • Description: Creates a new directory.

  • Usage:

    bash
    mkdir directory_name

1.5 rmdir – Remove Directory

  • Description: Removes an empty directory.

  • Usage:

    bash
    rmdir directory_name

2. Managing Files

Linux commands allow you to create, copy, move, and remove files with ease:

2.1 touch – Create an Empty File

  • Description: Creates a new, empty file or updates the timestamp of an existing file.

  • Usage:

    bash
    touch filename.txt

2.2 cp – Copy Files or Directories

  • Description: Copies files or directories from one location to another.

  • Usage:

    bash
    cp source_file destination_file

    To copy directories recursively, use the -r option:

    bash
    cp -r source_directory destination_directory

2.3 mv – Move or Rename Files

  • Description: Moves files or directories from one location to another. It can also rename files.

  • Usage:

    bash
    mv old_file new_file

2.4 rm – Remove Files

  • Description: Removes files.

  • Usage:

    bash
    rm filename.txt

    To remove directories, use the -r option for recursive deletion:

    bash
    rm -r directory_name

    To force deletion without confirmation, use -f:

    bash
    rm -rf directory_name

3. Viewing and Editing Files

Linux provides commands to view and edit file content:

3.1 cat – Concatenate and Display Files

  • Description: Displays the content of a file.

  • Usage:

    bash
    cat filename.txt

3.2 more – View File Content Page by Page

  • Description: Displays content of a file one page at a time.

  • Usage:

    bash
    more filename.txt

3.3 less – View File Content with Scrolling

  • Description: Displays content of a file with the ability to scroll.

  • Usage:

    bash
    less filename.txt

3.4 nano or vi – Edit Files

  • Description: Edits text files.

  • Usage:

    • For nano (simple text editor):

      bash
      nano filename.txt
    • For vi (advanced text editor):

      bash
      vi filename.txt

4. System Information

To gather important details about your system, Linux provides several commands:

4.1 top – System Monitoring

  • Description: Displays system information like CPU usage, memory usage, and active processes.

  • Usage:

    bash
    top

4.2 df – Disk Space Usage

  • Description: Displays disk space usage for all mounted file systems.

  • Usage:

    bash
    df -h

4.3 free – Memory Usage

  • Description: Shows available and used memory in the system.

  • Usage:

    bash
    free -h

4.4 uname – Kernel Information

  • Description: Displays system information such as the kernel version.

  • Usage:

    bash
    uname -r

5. Managing Processes

Linux provides several commands to manage and monitor running processes:

5.1 ps – Display Processes

  • Description: Displays the currently running processes.

  • Usage:

    bash
    ps

    For detailed process information:

    bash
    ps aux

5.2 kill – Terminate Processes

  • Description: Terminates a running process.

  • Usage:

    bash
    kill process_id

    To forcefully kill a process, use:

    bash
    kill -9 process_id

6. File Permissions and Ownership

In Linux, file permissions control who can read, write, or execute files:

6.1 chmod – Change File Permissions

  • Description: Changes the permissions of a file or directory.

  • Usage:

    bash
    chmod permissions filename.txt

    Example: Grant read, write, and execute permissions to the user:

    bash
    chmod u+rwx filename.txt

6.2 chown – Change File Ownership

  • Description: Changes the owner and/or group of a file or directory.

  • Usage:

    bash
    chown user:group filename.txt

7. Searching Files

To find files or content within files, use the following commands:

7.1 find – Search for Files

  • Description: Searches for files in a directory hierarchy.

  • Usage:

    bash
    find /path/to/directory -name filename.txt

7.2 grep – Search for Content Within Files

  • Description: Searches for a pattern in the contents of files.

  • Usage:

    bash
    grep "search_term" filename.txt

Conclusion

Understanding these basic Linux commands will give you a strong foundation for working with Linux systems. As a COPA student, mastering these commands will help you efficiently navigate the system, manage files, monitor processes, and perform essential administrative tasks. The more familiar you become with these commands, the more powerful and flexible your Linux experience will be.