"Superior quality instructions for the discerning online educator!" 🧐

Basic Linux Commands for your Self-hosted LMS

We can use the command line interface (CLI) to manage our LMS server remotely. This tutorial presents the basic commands that are used in LMStutorials.com instructional articles.

CLI icon

Why You Need a Few Linux Commands

In many of the tutorials on this site, we will interact with a remote server. We do so by sending Linux commands from the terminal on our local machine. You won’t need to be a whiz, but a bit of basic knowledge of the command line will help you get the most out of these lessons. This article is intended for future LMS administrators who are coming with no prior knowledge. We introduce the very basics: namely, 1) how to navigate your server’s file system, and 2) how to create, read, edit, and delete files. Of course, there are many commands that are not covered in this article, but this should be enough to get you started. Other, more specific commands regarding SSH access, permissions, installing software, etc., will be introduced in later articles that are targeted towards specific server operations. Patience, young grasshopper!


How to Access the Command Line

You can access the command line on macOS easily with the terminal application:

  1. Open Finder: Click on the Finder icon located on the Dock (the bar at the bottom of your screen).
  2. Navigate to Applications: In the Finder window, locate the "Applications" folder in the sidebar.
  3. Locate Utilities: Within the Applications folder, find and click on the "Utilities" folder.
  4. Launch Terminal: In the Utilities folder, you'll find an application named "Terminal."
Terminal icon in MacOS

The terminal icon in MacOS


Alternatively, you can press Command + Spacebar to open Spotlight Search and type "Terminal" to launch it.

Once launched, you'll see a fresh command line, where you can enter commands!

Fresh CLI prompt

For Linux, many distributions have a default keyboard shortcut to quickly access the terminal. It's usually Ctrl + Alt + T. Pressing these keys simultaneously should open a terminal window.

If you are using Windows, click on the Start button (Windows icon) at the bottom left corner of the screen. In the search bar, type "Command Prompt" or "cmd" and press Enter. This will open the Command Prompt window.

Next, let's introduce some of the basic commands which you will come across in the tutorials on this site...


Table of contents


print working directory icon

pwd

("print working directory")

It may not be the command that you will use most often, but it's one that will bring you comfort and secuity. When you enter the 'pwd' command, Linux will tell you exactly where you are in the file system. It stands for "print working directory," 'pwd' displays the full path of the directory you're in, i.e., starting from the root directory and listing each directory in the path leading up to your current location.

Examples:

  • If you enter pwd when you are currently in the "root" directly (i.e., the lowest level, or "trunk", of the file tree), Linux will return a slash:

      /                        
    This slash represents the root directory.

  • If you enter pwd when you are currently in the "home" directory for your user: Linux might return:

      /home/jonathan

    In other words, from the root directory (/), we enter the "home" directory, and from there the "jonathan" directory. This would be where Jonathan might find files that belong to him that shouldn't be readily accesed by other users on the computer.


change directory icon

cd

("change directory")

The 'cd' command in Linux lets us change our current directory. It's a bit like a teleportation device because we can transport ourselves instantly to a far-away directory without having to go through for navigating through the parent directories filesystem like we would have to do when using a graphical user interface (GUI; i.e., monitors, windows, mouse clicks).

Examples:

  • Change to the "home" directory:

      cd ~
                
  • Change to your system's log directory:

      cd /var/log
                

    Notice that the log directory is found in the "var" directory, where "variable" files that are often changed or overwritten live.



list command icon

ls

("list")

The 'cd' command lets us change directories, but how do we know what directories are even there? This is where the 'ls', or "list", command comes in. It's a bit like a flashlight, as we can both point at our current location, but also at locations where we are not. It displays a list of all the files names and directory names, but can also reveal various details such as file permissions, ownership, size, and modification dates.

Examples:

  • List the contents of your current directory:

      ls 

  • List the contents of your server's root directory:

      ls / 

  • List the contents of the "Apache 2" directory:

      ls /etc/apache2 

    Notice that the apache2 directory is found in the "etc" (pronounced et-see) directory, where the Linux system configuration files live.



remove icon

nano

("open the 'GNU nano' text editor")

The 'nano' command in Linux opens a simple yet powerful command line text editor. Similar to opening a blank document in a word processor, invoking 'nano' followed by the name of the file allows you to edit a new file with that name. Within 'nano', users can input and modify text, navigate through the document, and perform various editing tasks using intuitive keyboard shortcuts displayed at the bottom of the screen. Unlike more complex text editors, 'nano' is designed for ease of use, making it accessible to novice users.

You can close the nano editor with control + x

Examples:

  • Edit a new text file called "text.txt" in the GNU nano editor:
      nano test.txt
                            

  • make directory icon

    mkdir

    ("make directory")

    The 'mkdir' command in Linux creates a new directory at your current location in the filesystem. It stands for "make directory." After 'mkdir' you follow with the desired name of the directory you wish to create.

    Examples:
    • Make a directory called "new" at your current location.
        mkdir new
                              
    • Make a directory called "img" in your home directory. (~ is shorthand for the "home directory"). This could be a place to put photos!
        mkdir ~/img
                              

    move icon

    mv

    ("move")

    The 'mv' command in Linux allows you to move files and directories from one directory to another. You can use it for single files or an entire directories.

    You can also use it to rename files: just "move" one file to a file of a different name!

    Examples:

    • Move "demo.txt" from the home folder to a directory in the home folder called "new":

        mv ~/demo.txt ~/new 

    • Rename a file in our current directory, "test1.txt", to "test2.txt":

        mv test1.txt test2.text 


    remove icon

    rm

    ("remove")

    The 'rm' command in Linux "removes" a file or directory from the filesystem permenantly. It's short for "remove." It's important to exercise caution when using 'rm' as it does not send items to a recycle bin—they are deleted immediately and cannot be easily recovered. Therefore, it's crucial to double-check the items you intend to delete to avoid accidental data loss.

    To delete a directory/folder, you need to append the -r flag, which specifies that, not only should the directory be removed, but also everything inside should also be removed, recursively. If you forget, Linux will remind you with a friendly error message that the item in question "is a directory."

    Examples:
    • Delete the file, "demo.txt".

    •   rm demo.txt
    • Delete the folder, "new", and all of its contents:

    •   rm -r new


    Conclusion


    Learning these basic Linux commands will open up a world of possibilities for you! Of course, there are many more, but these are some of the most-used and will let you begin to explore your server. We'll cover new commands in other tutorials on LMStutorials.com.

    xf