Introduction to the command line (2024)

You are welcome to go through our tutorials but please keep in mind that as we rely on community PRs for maintainance they may be out of date.

What is the command line?

The command line is a text interface for your computer. Just like Windows Explorer on Windows or Finder on Mac OSX it lets you navigate through the files and folders of your computer, but it is completely text based. The command line works by typing commands against a prompt, which then gets passed to the operating system of the computer that runs these commands.

How do I access the command line?

To access the command line, we use a terminal emulator, usually called a terminal. On Mac OSX you can access the terminal by opening the Terminal application from your Applications folder. On Windows you can download Git here which includes a terminal.

Before we get started, you should note some DO’s and DONT’s while using the command line. The command line is a powerful tool that can significantly speed up your workflow but can also irreversibly harm your computer so make sure you use it responsibly.

If you are not sure what a command does DO NOT type it into your terminal. The command rm -rf / is a classic one that you should never use, it will delete all the files in your computer. If you are stuck and in need of help make sure you ask from someone you trust. It goes without saying that all commands in this tutorial are safe to use.

Example 1: navigating around in the terminal

Once you opened up your terminal, type in the following after the $ or > sign and hit enter: ($ or > is the prompt, you don’t have to retype that in the terminal, only the characters that come after them):

$ pwd

What do you think happened there? In your own words, try to explain what this command does.

pwd or print working directory

The pwd command prints out the current directory you are in. What are directories? Directories are folders, these terms are used interchangeably. If you just opened up your terminal, you are probably in the home directory of your computer, and should get an output similar to this:

/Users/your-username

Now that you know how to tell where you are in your computer, you might ask yourself: how I do know which files are in a directory? That’s where the ls command comes in handy.

ls or list

In your terminal type:

$ ls

and hit enter. Most likely this command returned you a bunch of files and folders. The ls command prints out the contents of a directory. If you are in the home directory of your computer you should see directories printed out such as Documents, Applications, etc. Now, how do you move across directories?

cd or change directory

The cd command allows you to move between directories. The cd command takes an argument, usually the name of the folder you want to move to, so the full command is cd your-directory.

In the terminal, type:

$ ls

Let’s say we wanted to move to the Desktop folder: just type in your terminal

$ cd Desktop

Now type:

$ pwd

This should return you something like:

See Also
xcopy

/Users/your-username/Desktop

Now that we moved to your Desktop, you can type ls again, then cd into it. We have just changed into a new directory. You can use these two commands to navigate around your computer.

This is all good so far, but sometimes you might want to go deeper than one level in one command. cd allows you to do this by chaining the directories with a /, so cd your-directory becomes cd your-directory/directory-inside-your-directory.

We now know how to move forward. But how to go back up the directory tree? Type in your terminal:

$ cd ..

Now do a pwd. You just went back one directory! Chaining works backwards too, so if you type cd ../.. you should be taken back two directories.

If you want to go back to the home directory of your computer, simply type cd into the terminal. cd without an argument takes you back to the home directory regardless of where you are currently in the directory structure

Exercise 1: use ls and cd to move in and out of a few directories on your computer

These are the basics of navigating around in the terminal. What else would we want to do in there? How about creating directories and files?

Example 2: creating directories and files

mkdir or make directory

Go back to the home directory of your computer, and type:

$ cd$ mkdir temp

into the terminal. Now use ls to see the contents of the home directory. You should see a new folder, temp there. You just created a new folder! As its name suggests, mkdir creates directories. What if we wanted to create a directory inside a directory? cd into temp and type:

$ mkdir -p stuff/bits

Now do an ls and you should see the stuff folder. Now run cd stuff and do another ls. Inside stuff, the bits directory was created.

What if you wanted to create files?

touch or create files

Inside the bits folder, type:

$ touch bobs.txt

Do an ls to check whether the file has been created. Inside bits, there should be a new file called bobs.txt. We used touch to create files. With touch you can create files with any extension, just don’t forget to specify what kind of file you are creating: for example, index.html, script.js, style.css are all valid extensions.

mv or move item

What if you created a file in the wrong place? There’s a command for that. Let’s move bobs.txt to somewhere new. Inside the bits folder type:

$ mv bobs.txt ..

Type ls and the file is no longer there. Type cd .., this moves you one folder up to the stuff folder. Then type ls and the bobs.txt file will be there. There are 3 parts to this command, the mv command, the item to be moved, here it’s bobs.txt, and the new destination for the item, here we have it as .. or one directory up the structure. You could also type the destination directory, replacing the .. with stuff and it would do the same job.

Exercise 2: cd back into temp and create a couple of new folders with files in them

Bonus: if you are on a Mac, type this into your terminal:

$ say hello
Introduction to the command line (2024)

FAQs

What is the introduction of command line? ›

While a GUI is a visual way for operating your computer, the Command Line is a text-based interface for doing the same tasks you perform when clicking, dragging, and dropping files. It has a range of capabilities that make it a powerful tool for those who need more precision in their work.

How do you explain command line? ›

A command-line interface (CLI) is a text-based user interface (UI) used to run programs, manage computer files and interact with the computer. Command-line interfaces are also called command-line user interfaces, console user interfaces and character user interfaces.

What is the introduction of Command Prompt? ›

What is the Command Prompt. In Windows operating systems, the Command Prompt is a program that emulates the input field in a text-based user interface screen with the Windows Graphical User Interface (UI). It can be used to perform entered commands and perform advanced administrative functions.

What is the basic use of command line? ›

The Command Line Interface (CLI) is an editing environment that is text-based. It uses specified text (known as commands) to interact with the computer and perform numerous operations, including installing and working with programs. Every operating system comes with an inbuilt command prompt.

What is command line examples? ›

Examples include Bash, cmd.exe, PowerShell, and others for more specific functions. The shell is responsible for handling various tasks such as command parsing, environment management, and process execution.

What are the three parts of a command line? ›

In general, a command is composed of the three following elements separated by one or more space characters: a name, a list of options also called flags and a list of arguments. The name, which always comes first, is indeed the name of the program we want to run.

How do I get to the Command Prompt? ›

To access a command prompt using the Run command box: Open the Start menu or press the Windows key + R. Type cmd or cmd.exe in the Run command box. Press Enter.

What is Command Prompt and how do you open it? ›

Select the Start Menu (the Windows icon) in the taskbar, or press the Windows key. Type cmd. Select Command Prompt from the list. If you're using the latest version of Windows 11, Command Prompt will open within Terminal.

What is the default Command Prompt? ›

Command Prompt, also known as cmd.exe or cmd, is the default command-line interpreter for the OS/2, eComStation, ArcaOS, Microsoft Windows (Windows NT family and Windows CE family), and ReactOS operating systems. On Windows CE .

What is the first argument of command line? ›

argv[1] is the first command-line argument. The last argument from the command line is argv[argc - 1] , and argv[argc] is always NULL. For information on how to suppress command-line processing, see Customize C++ command-line processing. By convention, argv[0] is the filename of the program.

What is a command line quizlet? ›

What is the command-line interface? (CLI) A simple text based user interface for an OS.

Top Articles
Opportunities and the future of blockchain technology
Help Center
Katie Pavlich Bikini Photos
Gamevault Agent
Hocus Pocus Showtimes Near Harkins Theatres Yuma Palms 14
Free Atm For Emerald Card Near Me
Craigslist Mexico Cancun
Hendersonville (Tennessee) – Travel guide at Wikivoyage
Doby's Funeral Home Obituaries
Vardis Olive Garden (Georgioupolis, Kreta) ✈️ inkl. Flug buchen
Select Truck Greensboro
Things To Do In Atlanta Tomorrow Night
Non Sequitur
How To Cut Eelgrass Grounded
Pac Man Deviantart
Alexander Funeral Home Gallatin Obituaries
Craigslist In Flagstaff
Shasta County Most Wanted 2022
Energy Healing Conference Utah
Testberichte zu E-Bikes & Fahrrädern von PROPHETE.
Aaa Saugus Ma Appointment
Geometry Review Quiz 5 Answer Key
Walgreens Alma School And Dynamite
Bible Gateway passage: Revelation 3 - New Living Translation
Yisd Home Access Center
Home
Shadbase Get Out Of Jail
Gina Wilson Angle Addition Postulate
Celina Powell Lil Meech Video: A Controversial Encounter Shakes Social Media - Video Reddit Trend
Walmart Pharmacy Near Me Open
A Christmas Horse - Alison Senxation
Ou Football Brainiacs
Access a Shared Resource | Computing for Arts + Sciences
Pixel Combat Unblocked
Cvs Sport Physicals
Mercedes W204 Belt Diagram
'Conan Exiles' 3.0 Guide: How To Unlock Spells And Sorcery
Teenbeautyfitness
Where Can I Cash A Huntington National Bank Check
Facebook Marketplace Marrero La
Nobodyhome.tv Reddit
Topos De Bolos Engraçados
Gregory (Five Nights at Freddy's)
Grand Valley State University Library Hours
Holzer Athena Portal
Hampton In And Suites Near Me
Hello – Cornerstone Chapel
Stoughton Commuter Rail Schedule
Bedbathandbeyond Flemington Nj
Free Carnival-themed Google Slides & PowerPoint templates
Otter Bustr
Selly Medaline
Latest Posts
Article information

Author: Golda Nolan II

Last Updated:

Views: 6284

Rating: 4.8 / 5 (78 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Golda Nolan II

Birthday: 1998-05-14

Address: Suite 369 9754 Roberts Pines, West Benitaburgh, NM 69180-7958

Phone: +522993866487

Job: Sales Executive

Hobby: Worldbuilding, Shopping, Quilting, Cooking, Homebrewing, Leather crafting, Pet

Introduction: My name is Golda Nolan II, I am a thoughtful, clever, cute, jolly, brave, powerful, splendid person who loves writing and wants to share my knowledge and understanding with you.