Cheat Sheet for Common Linux Commands
Are you new to Linux? Are you struggling to understand the basics of the command line? Look no further! In this article, we'll be providing you with a cheat sheet filled with common Linux commands that will help you get started on your Linux journey.
What is Linux?
Linux is a free and open-source operating system that is commonly used in servers, supercomputers, and many other devices. It was first released on September 17, 1991, by a Finnish computer scientist, Linus Torvalds.
Why Use Linux?
Linux has many advantages, including the following:
- It is free and open-source.
- It is highly customizable.
- It is more secure than other operating systems.
- It is supported by a vast community of developers and users.
Command Line Basics
Before we dive into the commands, we need to understand some basic concepts of the command line.
Terminal
A terminal is a program that allows you to interact with the command line. In Linux, you can open a terminal by pressing Ctrl+Alt+T
.
Prompt
The prompt is the text displayed in the terminal that indicates it is waiting for a command. The default prompt in Linux is the $
symbol.
Commands
Commands are instructions given to the system through the terminal. They are executed by pressing the Enter
key.
Arguments
Arguments are additional information provided to a command to modify its behavior. They are separated from the command by a space.
Options
Options are additional flags added to a command to modify its behavior further. They are preceded by a single or double hyphen.
Cheat Sheet
Now that we have covered the basics, let's dive into the commands:
Navigation Commands
cd
The cd
command is used to change the current working directory. Usage: cd [directory]
Examples:
cd ~ # Go to home directory
cd /path/to/dir # Go to a directory by absolute path
cd dir # Go to a directory by relative path
cd ../dir # Go back one directory
ls
The ls
command is used to list the contents of a directory. Usage: ls [options] [path]
Examples:
ls # List contents of current directory
ls -l # List contents in long format
ls -a # List all contents, including hidden files
ls dir/ # List contents of a directory
File and Directory Commands
mkdir
The mkdir
command is used to create a new directory. Usage: mkdir [directory]
Example: mkdir new_dir
touch
The touch
command is used to create a new file or update the timestamp of an existing file. Usage: touch [file]
Example: touch file.txt
cp
The cp
command is used to copy files or directories to a new location. Usage: cp [source] [destination]
Examples:
cp file.txt new_dir/ # Copy file to a directory
cp -r dir/ new_dir/ # Copy directory to a new location
cp -r dir/ new_dir/new_dir2/ # Copy directory and its contents recursively
mv
The mv
command is used to move files or directories to a new location or rename them. Usage: mv [source] [destination]
Examples:
mv file.txt new_dir/ # Move file to a directory
mv file.txt new_file.txt # Rename file
mv dir/ new_dir/ # Move directory to a new location
mv dir/ new_dir/new_dir2/ # Move directory and its contents recursively
rm
The rm
command is used to remove files or directories. Usage: rm [options] [path]
Examples:
rm file.txt # Remove a file
rm -r dir/ # Remove a directory and its contents recursively
rm -rf dir/ # Remove a directory and its contents recursively, forcefully
System Information Commands
uname
The uname
command is used to display the system information. Usage: uname [options]
Examples:
uname # Display the operating system name
uname -a # Display all system information
top
The top
command is used to display real-time information about running processes. Usage: top
Example: top
df
The df
command is used to display disk usage statistics. Usage: df [options] [path]
Examples:
df # Display disk usage for all partitions
df -h # Display disk usage in human-readable format
df /dev/sda1 # Display disk usage for a specific partition
User and Permission Commands
whoami
The whoami
command is used to display the current username. Usage: whoami
Example: whoami
passwd
The passwd
command is used to change the password of a user. Usage: passwd [user]
Example: passwd
chmod
The chmod
command is used to change the permissions of a file or directory. Usage: chmod [permissions] [path]
Example: chmod 755 file.txt
Package Management Commands
apt
The apt
command is used to manage packages on Debian-based systems. Usage: apt [options] [command] [package]
Examples:
sudo apt update # Update the package lists
sudo apt upgrade # Upgrade installed packages
sudo apt install git # Install a package
sudo apt remove git # Remove a package
sudo apt autoremove # Remove dependencies of uninstalled packages
yum
The yum
command is used to manage packages on Red Hat-based systems. Usage: yum [options] [command] [package]
Examples:
sudo yum update # Update the package lists
sudo yum upgrade # Upgrade installed packages
sudo yum install git # Install a package
sudo yum remove git # Remove a package
sudo yum autoremove # Remove dependencies of uninstalled packages
Conclusion
In conclusion, by mastering these common Linux commands, you are on your way to becoming a Linux command line wizard. We hope that this cheat sheet has been helpful and that you find it useful in your Linux journey! Happy command lining!
Editor Recommended Sites
AI and Tech NewsBest Online AI Courses
Classic Writing Analysis
Tears of the Kingdom Roleplay
Multi Cloud Ops: Multi cloud operations, IAC, git ops, and CI/CD across clouds
Crypto Rank - Top Ranking crypto alt coins measured on a rate of change basis: Find the best coins for this next alt season
Graph Reasoning and Inference: Graph reasoning using taxonomies and ontologies for realtime inference and data processing
LLM Book: Large language model book. GPT-4, gpt-4, chatGPT, bard / palm best practice
Learn Prompt Engineering: Prompt Engineering using large language models, chatGPT, GPT-4, tutorials and guides