Skip to main content
Taught by Tech Leads

Master pipelines, cloud & AI to become an operational Data Engineer.

DataScientist.fr
Image de The Ultimate Guide to Command Line Commands for Beginners
Docker
Kubernetes
DevOps

The Ultimate Guide to Command Line Commands for Beginners

Photo de Romain DE LA SOUCHÈRE

Tech Lead, CTO AXI Technologies

Published on 23 septembre 2024 · 7 min of reading

The ultimate guide to command line commands for beginners

The command line is a powerful tool that allows users to interact directly with the operating system. For beginners, it may seem intimidating at first, but with a little practice, you will discover that it is a fast and efficient way to accomplish many tasks. In this article, we will explore the basic commands that every user should know, how to use them, and practical examples to help you master this essential tool.

Why learn the command line?

Learning to use the command line may seem archaic in the age of graphical interfaces, but it offers several advantages. It allows for easier automation of repetitive tasks, finer management of files and processes, and it is often the only option available when working with remote servers or systems without a graphical interface.

What you will learn

By following this guide, you will:
  • Learn the basic commands to navigate and manage your files.
  • Understand how to redirect input and output to optimize your workflows.
  • Customize your work environment with variables and aliases.
  • Edit files directly from the command line.
Each section is designed to be practical and easy to follow, with examples you can try on your own machine. By the end of this article, you will have a good understanding of the basic commands and be ready to explore more advanced commands on your own.

Basic commands for navigating and managing files

To start using the command line, it is essential to know a few basic commands for navigating the file system and managing your files and folders. Here are some of the most commonly used commands:

Navigating the file system

  • pwd : Displays the path of the current directory. This is a useful command to always know where you are.
shell
  • ls : Lists the contents of the current directory. Use ls -l to display detailed information about each file and folder.
shell
  • cd : Changes the directory. You can use cd .. to go up one level, or specify a path to go directly to a particular directory.
shell

File and folder management

  • mkdir : Creates a new directory.
shell
  • touch : Creates a new empty file.
shell
  • rm : Deletes a file. Use rm -r to delete a directory and its contents.
shell
  • cp : Copies a file or directory. Use cp -r to recursively copy a directory and its contents.
shell
  • mv : Moves or renames a file or directory.
shell

Mastering redirection commands

Redirection is a powerful feature of the command line that allows you to control the input and output of commands. This can greatly improve your efficiency by allowing you to easily manipulate data streams.

Redirecting standard output

  • > : Redirects standard output to a file. If the specified file already exists, its content will be overwritten.
shell
  • >> : Appends standard output to the end of an existing file without deleting its content.
shell

Redirecting standard input

  • < : Uses the content of a file as input for a command.
shell

Redirecting errors

  • 2> : Redirects standard error output to a file.
shell
  • 2>&1 : Combines standard output and standard error into a single file.
shell

Pipes

Pipes (|) are used to connect the output of one command to the input of another command, allowing for the creation of more complex command chains.
shell
In this example, ls -l lists the files and directories, and grep "^d" filters to only display directories.

Practical examples

  • Find and count specific lines in a file:
shell
  • List files, sort them by size, and display them page by page:
shell

Customize your environment with variables and aliases

Customizing your command line environment can make your work more efficient and better suited to your needs. Two of the most powerful ways to achieve this are by using environment variables and aliases.

Environment variables

Environment variables are key-value pairs that influence the behavior of processes and programs running. You can define, modify, and use them to customize your environment.
  • Define an environment variable : Use the export command to create a new environment variable.
shell
  • List environment variables : Use the printenv command to display all active environment variables.
shell
  • Use environment variables : Variables can be used in scripts and commands to make your work more flexible.
shell

Aliases

Aliases are shortcuts for frequently used commands or sequences of commands. They can save you time and prevent you from having to type long commands repeatedly.
  • Create an alias : Use the alias command to define a new shortcut.
shell
  • Remove an alias : Use the unalias command to remove an existing alias.
shell
  • Make aliases persistent : To make your aliases available in every session, add them to your ~/.bashrc or ~/.zshrc file.
shell

Edit files directly from the command line

Editing files directly from the command line is an essential skill for any advanced user. There are several text editors available in the command line, each with its own advantages and use cases. Here are some of the most popular:

Nano

Nano is a simple and easy-to-use text editor, ideal for beginners.
  • Open a file : Use the nano command followed by the file name.
shell
  • Navigate and edit : Use the arrow keys to navigate and type text to edit.
  • Save and exit : Press Ctrl + O to save and Ctrl + X to exit.

Vim

Vim is a more advanced text editor, offering many powerful features. It has a steeper learning curve but is very efficient for experienced users.
  • Open a file : Use the vim command followed by the file name.
shell
  • Edit modes : Vim has several modes, including command mode and insert mode. Press i to enter insert mode and edit text.
  • Save and exit : In command mode, type :w to save and :q to exit.

Practical examples

  • Quickly edit a configuration file:
shell
  • Use Vim for advanced modifications:
shell
By mastering these text editors, you will be able to edit configuration files, scripts, and other documents directly from your terminal, saving you valuable time.

Conclusion

By mastering the basic commands of the command line, you now have a powerful tool to navigate and efficiently manage your file system. You have learned to use essential commands such as pwd, ls, and cd to orient yourself, as well as mkdir, touch, rm, cp, and mv to manage your files and folders.

Redirection and customization

You have also discovered how to use redirection to optimize your workflows, controlling the input and output of commands using >, >>, <, and 2>. Pipes allow you to combine commands to perform more complex operations. Customizing your environment with environment variables and aliases gives you increased flexibility, making your command line experience more efficient and tailored to your needs.

Editing files from the command line

Finally, the ability to edit files directly from the command line with editors like Nano and Vim gives you complete control over your scripts and configuration files without needing to leave your terminal.
By integrating these skills into your daily routine, you will be able to work faster and more productively. The command line may seem intimidating at first, but with practice, it will become an indispensable tool in your computer development toolkit. Continue to explore and experiment with new commands and features to get the most out of this powerful tool.

Share with

Photo de Romain DE LA SOUCHÈRE

Romain DE LA SOUCHÈRE

Tech Lead, CTO AXI Technologies

Expert Data Engineering et Cloud, Romain affiche plus de 11 ans d'expérience, dont plusieurs années comme Lead Developer sur des solutions Smart Building haute performance. Il y a conçu et mis en production des moteurs de traitement capables d'absorber des centaines de milliers de données de capteurs par minute, ainsi que des bases clusterisées gérant plus de 10 millions de données dynamiques. Certifié Microsoft Azure DevOps Engineer Expert, il maîtrise aussi bien le développement back-end (Python, C#) que le DevOps (Docker, Kubernetes, Terraform) et les agents LLM. Formateur en Python, cloud, DevOps et IA générative appliquée, il forme avec une obsession : Amener chaque apprenant à concevoir et déployer des architectures réellement scalables en production.

» Learn More

Associated trainings

All our trainings
Image de la formation Prepare for the PL-300 Certification
Prepare for the PL-300 Certification
24 hours
Beginner
Guarantee
Image de la formation Prepare for the AZ-900 Certification
Prepare for the AZ-900 Certification
10 hours
Beginner
Guarantee
Image de la formation Prepare for the DP-700 Certification
Prepare for the DP-700 Certification
24 hours
Beginner
Guarantee
Image de la formation Prepare for the DP-900 Certification
Prepare for the DP-900 Certification
10 hours
Beginner
Guarantee