A Linux command is a set of instructions for carrying out a certain action in Linux. And basic Linux commands are those which are frequently used. In this article, I will illustrate a basic Linux commands cheat sheet to make your journey with the Linux command line easier. Type these commands into the terminal to handle everything from files and directories to processes and more.
Download Basic Linux Commands Cheat Sheet
What is a Linux Command?
A Linux command is a text-based interface that allows you to communicate with the Linux operating system. The commands are inserted into a terminal which is then passed to a shell that tells the operating system what to do. Linux command is a great alternative to Graphical User Interface (GUI) as it is much faster and more efficient. You can perform all tasks with commands that can be done using the GUI.
Basic Linux Commands List
Here I have categorized all the basic commands in Linux. You can also find that some commands are mentioned with their necessary options. For your better understanding, the structure of a Linux command is
Command -options arguments parameters
File and Directory Management
In this category, you will find commands that can be used to copy, make, and remove files; create directories; and navigate through these.
|cp||Copies files and directories|
|pwd||Prints the current working directory|
|cd||Changes current directory|
|cd..||Changes to the parent directory|
|cd –||Changes to the previous directory|
|cd ~||Changes to the home directory|
|ls||Lists contents of the current directory|
|ls -l||Lists the files and directories in the current working directory in long format|
|ls -a||Lists all files and directories including the hidden ones|
|ls -r||Lists files/directories in reverse|
|mkdir||Creates a new directory|
|rmdir||Removes an empty directory|
|mv||Moves or renames a file /directory|
|rm||Removes a file/directory|
|rm -i||Prompts system confirmation before deleting|
|rm -r||Deletes a file/directory recursively|
|rm -d||Deletes empty folders|
Under this section, you can find commands which will assist you in editing your files and show contents in your desired ways.
|touch||Creates an empty file/modify timestamp|
|cat||Concatenates and prints file contents|
|cat -n||Displays the contents of a file along with line numbers|
|tac||Concatenates and prints file contents in reverse order|
|less||Shows contents in a scrollable manner|
|head||Displays the first ten lines of a file|
|tail||Displays the last ten lines of a file|
|grep||Searches for a specified pattern in one or more files|
|nano||Edits and creates files|
|diff||Compares two text files|
|sort||Sorts lines of a text file|
|sort -r||Sorts file reversely|
|sort -u||Removes duplicates and sorts unique values|
Here, you will get to know how you can change the permission of a file or directory.
|chmod||Modifies a file or directory’s read, write, and execute permissions|
|chown||Changes the ownership of a file, directory, or symbolic link to a specified username.|
|chgrp||Changes the group ownership of a file or directory|
This section consists of commands that can be used to control the operating system just by using the command line.
|poweroff||Shuts down the system|
|reboot||Restarts the system|
|shutdown||Shuts down or reboots the system|
System and Process Management
This part includes commands to get information about the system such as space usage and terminate a running process.
|sudo||Allows a user to run a command with the privileges of another user|
|ps||Lists the running processes on a system|
|kill||Terminates running processes on a system|
|killall||Terminates all processes with a specified name|
|df||Displays the amount of disk space used and available on a file system|
|du||Estimates file space usage|
Here, you can find commands that will be needed for package installation.
|apt install [package]||Installs software packages from the Ubuntu package repository|
|apt-get||Performs package management tasks such as installing, upgrading, and removing packages|
Using these commands you can extract and compress files.
|tar||Creates, views, and extracts files from an archive file|
|zip||Creates, views, and extracts files from a compressed archive file|
|unzip||Extracts files from a compressed archive file in the ZIP format|
|gzip||Compresses files or directories to reduce their size|
|bzip2||Compresses files or directories to reduce their size|
If you are searching for a pattern in a file content or want to locate files in your system these basic commands are here to help you.
|grep ‘pattern’ files||Searches for a specified pattern or regular expression in one or more files and display the matching lines|
|grep -r pattern dir||Searches for a specified pattern or regular expression recursively in a directory and its subdirectories, and display the matching lines.|
|locate||Locates files and directories on the system|
|find||Locates files and directories on the system|
|find -empty||Searches for empty files|
Linux has huge commands and options to offer. It’s ok if you can’t memorise all these. Use the built-in documentation command to get help.
|man||Displays the manual page of a command or utility|
You may want to know more about your system or maybe you want to check which user has logged in. Here are some useful commands to do so.
|date||Displays and sets system date and time|
|cal or ncal||Displays the calendar of the current month|
|who||Displays information about currently logged-in user|
|whoami||Displays the user name of the current user logged in|
|uname||Displays information about the current system and operating system|
|hostname||Displays or set the hostname of the current system|
|hostnamectl||Queries or modifies the hostname and related settings of the current system|
|history||Displays a list of previously executed commands in the terminal|
|history -c||Clears the history list of previously executed commands|
|df||Shows information about both total and available space on a file system|
You can easily add or remove a user in your system using the following commands.
|useradd||Creates a new user account on the system|
|userdel||Deletes a user account from the system|
|passwd||Changes a user’s password|
|groupadd||Adds a new group to the system|
|groupdel||Deletes an existing group from the system|
|Id||Displays the user and group IDs associated with the current user|
|su||Switches to another user account|
Finally, we have listed more commands that may help you in your Linux journey.
|echo||Displays a line of text or a variable value on the command line|
|clear||Clears the terminal window|
|wc||Counts the number of lines, words, and characters in a file|
|vim||Texts editor for editing text files|
|ping||Checks the connectivity between two network devices|
|exit||Exits the current shell session|
|htop||Displays the system’s process real-time process activity|
|shred||Securely deletes the files by overwriting multiple times|
|w||Displays information about the currently logged-in users and their activities|
|ps||Displays the running processes|
|whatis||Displays a brief description of a command|
|wget||Downloads files from the internet|
If you are just starting or are still in the learning phase with Linux, these are a few basic commands you will need to know. Furthermore, these commands were comprehensive enough to cover virtually every job performed from the Linux command line.