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
Navigation
-
cd: Change directory.user@user:~/$ cd myfolderuser@user:~/myfolder$cd ..is used to return to the parent directory.user@user:~/myfolder$ cd ..user@user:~/$ -
ls(ordiron Windows): List files and directories.ls -llists files with more informations. -
pwd(orecho %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 myfoldertouch(ortype nul >on Windows): Create a new empty file.touch file.txtcp: Copy files or directories (usecp -rto copy directories).cp file.txt /path/to/destination/mv: Move or rename files or directories. The syntax ismv source destinationormv oldname newname.mv file.txt /path/to/destination/mv file.txt newfile.txtrm(ordelon Windows): Remove files or directories (userm -rto remove directories).
Working with Text Files
cat(ortypeon Windows): Display the contents of a file.cat file.txtless: Display the contents of a file in a page by page, allowing you to scroll. Use the arrow keys to navigate. Useqto quit.less file.txtnano(ornotepadon Windows): Text editor for editing files.grep(Windows users can usefindstr): Search for specific text in files.grep "text" file.txt
Advanced Commands
-
Pipelines (
|) allow you to chain multiple commands together. The pipeline is written withAltGr + 6on the keyboard.Example: To list all files ending with
.txtin the current directory :ls -l | grep "txt" -
findis a powerful command that allows you to search for files and directories.
The syntax isfind path -name "filename".The point
.represents the current directory.Example: To list all files ending with
.txtin 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