Skip to main content

Command Line Basics

What is the Command Line?​

The command line is a text-based interface that allows users to interact with their computer by typing commands. It provides a powerful and efficient way to perform various tasks, from file manipulation to system administration.

Getting Started​

Opening the Command Line​

  • Windows: Use the Command Prompt or PowerShell.
  • MacOS: Open the Terminal application.
  • Linux: Access the terminal through the terminal emulator (e.g., GNOME Terminal, Konsole).

Basic Commands​

  • cd: Change directory.

    user@user:~/$ cd myfolder
    user@user:~/myfolder$

    cd .. is used to return to the parent directory.

    user@user:~/myfolder$ cd ..
    user@user:~/$
  • ls (or dir on Windows): List files and directories. ls -l lists files with more informations.

  • pwd (or echo %cd% on Windows): Print the current working directory.

    user@user:~/myfolder$ pwd
    /home/user/myfolder

File and Directory Operations​

  • mkdir: Create a new directory.
    user@user:~/mkdir myfolder
  • touch (or type nul > on Windows): Create a new empty file.
    touch file.txt
  • cp: Copy files or directories (use cp -r to copy directories).
    cp file.txt /path/to/destination/
  • mv: Move or rename files or directories. The syntax is mv source destination or mv oldname newname.
    mv file.txt /path/to/destination/
    mv file.txt newfile.txt
  • rm (or del on Windows): Remove files or directories (use rm -r to remove directories).

Working with Text Files​

  • cat (or type on Windows): Display the contents of a file.
    cat file.txt
  • less: Display the contents of a file in a page by page, allowing you to scroll. Use the arrow keys to navigate. Use q to quit.
    less file.txt
  • nano (or notepad on Windows): Text editor for editing files.
  • grep (Windows users can use findstr): Search for specific text in files.
    grep "text" file.txt

Advanced Commands​

  • Pipelines (|) allow you to chain multiple commands together. The pipeline is written with AltGr + 6 on the keyboard.

    Example: To list all files ending with .txt in the current directory :

    ls -l | grep "txt"
  • find is a powerful command that allows you to search for files and directories.
    The syntax is find path -name "filename".

    The point . represents the current directory.

    Example: To list all files ending with .txt in the current directory :

    find . -name "*.txt"

To learn more on command line commands, please refer to this tutorial : The UNIX Command Line, A Beginner’s Guide