The 10 Most Commonly Used Linux Commands
What Is a Linux Command?
A Linux command is a program or utility that runs on the command line interface (CLI) – a console that interacts with the system via texts and processes. It’s similar to the Command Prompt application in Windows.
Linux commands are executed on Terminal by pressing Enter at the end of the line. You can run commands to perform various tasks, from package installation to user management and file manipulation.
Here’s what a Linux command’s general syntax looks like:
bash CommandName [option(s)] [parameter(s)]
A command may contain an option or a parameter. In some cases, it can still run without them. These are the three most common parts of a command:
CommandName
is the rule that you want to perform.Option
orflag
modifies a command’s operation. To invoke it, use hyphens (-
) or double hyphens (--
).Parameter
orargument
specifies any necessary information for the command.
Keep in mind that all Linux commands are case-sensitive.
Here is the list of basic Linux commands:
sudo
command Short for superuser do,sudo
is one of the most popular basic Linux commands that lets you perform tasks that require administrative or root permissions. When usingsudo
, the system will prompt users to authenticate themselves with a password. Then, the Linux system will log a timestamp as a tracker.
Example:
This command updates your system’s package list using administrative privileges.
pwd
command Use thepwd
command to find the path of your current working directory. Simply enteringpwd
will return something like this:
This command is useful when you want to know where you are in the file system.
cd
command Thecd
command stands for change directory. It allows you to navigate through different directories in the file system.
Example:
This command changes your current working directory to Documents.
To go back to the previous directory, use this command:
To go back to your home directory, use this command:
To go to any directory from anywhere, use an absolute path:
ls
command Thels
command lists all files and directories in your current working directory.
Example:
This command will return something like this:
You can also use some options with this command, such as:
-a
to show all files, including hidden ones.-l
to show detailed information, such as permissions, size, and modification date.-h
to show human-readable file sizes.-t
to sort files by modification time.
Example:
This command will return something like this:
mkdir
command Themkdir
command creates a new directory in your current working directory or a specified path.
Example:
This command creates a new directory named NewFolder in your current working directory.
To create multiple directories at once, use this command:
To create a nested directory structure, use this command:
This command creates a new directory named NewFolder with two subdirectories named Subfolder and Subsubfolder.
touch
command
The touch
command creates a new empty file in your current working directory or a specified path.
Example:
This command creates a new empty file named NewFile.txt in your current working directory.
To create multiple files at once, use this command:
This command creates three new empty files named NewFile1.txt, NewFile2.txt, and NewFile3.txt in your current working directory.
The touch
command can also be used to change the access and modification times of existing files.
Example:
This command updates the access time of ExistingFile.txt to the current time.
cp
command
The cp
command copies files or directories from one location to another.
Example:
This command copies SourceFile.txt from your current working directory to DestinationFolder.
To copy multiple files at once, use this command:
This command copies SourceFile1.txt and SourceFile2.txt from your current working directory to DestinationFolder.
To copy a directory and its contents recursively, use this command:
This command copies SourceFolder and all its subdirectories and files to DestinationFolder.
mv
command
The mv
command moves files or directories from one location to another.
Example:
This command moves SourceFile.txt from your current working directory to DestinationFolder.
To move multiple files at once, use this command:
This command moves SourceFile1.txt and SourceFile2.txt from your current working directory to DestinationFolder.
To move a directory and its contents recursively, use this command:
This command moves SourceFolder and all its subdirectories and files to DestinationFolder.
The mv
command can also be used to rename files or directories.
Example:
This command renames OldName.txt to NewName.txt in your current working directory.
rm
command
The rm
command removes files or directories from your file system.
Example:
This command deletes FileToDelete.txt from your current working directory.
To delete multiple files at once, use this command:
This command deletes FileToDelete1.txt, FileToDelete2.txt, and FileToDelete3.txt from your current working directory.
To delete a directory and its contents recursively, use this command:
This command deletes FolderToDelete and all its subdirectories and files from your file system.
cat
command
The cat
command concatenates files and prints them on the standard output (usually the terminal).
Example:
This command prints the contents of FileToRead.txt on the terminal.
To concatenate multiple files and print them on the standard output, use this command:
Last updated
Was this helpful?