Skip to main content

Basic Linux Commands Cheat Sheet

A quick reference guide to essential Linux file management, text editing, and package management commands.


File & Directory Management

CommandDescription
lsList files and directories.
ls -lDisplay files in long listing format.
ls -aShow hidden files.
pwdPrint the current working directory.
cd <directory>Change to a specified directory.
cd ..Move up one directory level.
mkdir <dir>Create a new directory.
rmdir <dir>Remove an empty directory.
rm <file>Delete a file.
rm -r <dir>Delete a directory and its contents.
cp <source> <destination>Copy a file to a new location.
cp -r <source> <destination>Copy a directory recursively.
mv <oldname> <newname>Move or rename a file/directory.
touch <file>Create a new empty file.

File Viewing & Editing

CommandDescription
cat <file>Display the contents of a file.
less <file>View file contents page by page.
head -n <number> <file>Display the first n lines of a file.
tail -n <number> <file>Display the last n lines of a file.

Nano Editor (Simple)

CommandDescription
nano <file>Open a file in Nano editor.
CTRL + XExit Nano.
CTRL + SSave changes.
CTRL + WSearch for a word or phrase.
CTRL + KCut a line.
CTRL + UPaste a line.

Vim Editor (Advanced)

CommandDescription
vim <file>Open a file in Vim editor.
iEnter insert mode to edit text.
ESCExit insert mode.
:wSave the file.
:qQuit Vim.
:wqSave and quit Vim.
:q!Quit without saving changes.

APT Package Management (Ubuntu/Debian)

CommandDescription
sudo apt updateRefresh package lists.
sudo apt upgradeUpgrade all installed packages.
sudo apt install <package>Install a specific package.
sudo apt remove <package>Remove an installed package.
sudo apt purge <package>Remove a package along with its configuration files.
sudo apt search <package>Search for a package in the repository.
sudo apt list --installedList all installed packages.
sudo apt autoremoveRemove unused dependencies.
sudo apt cleanClear cached package files.