TechSchool
Home / Cheat sheets / Linux

Linux cheat sheet

96 one-line examples for Linux. Open it while you code, or print it and keep it near the keyboard. Free, with no signup and no ads.

Files and Folders

CodeWhat it does
lsList files in the current folder.
ls -lList files with details and permissions.
ls -aShow hidden files that start with a dot.
cd /homeChange to the /home folder.
cd ..Go up one folder level.
pwdPrint the full path of the current folder.
mkdir notesCreate a new folder named notes.
cp a.txt b.txtCopy a.txt to b.txt.
mv a.txt b.txtRename a.txt to b.txt.
rm a.txtDelete the file a.txt.
rm -r oldDelete the folder old and its contents.
touch new.txtCreate an empty file named new.txt.

View and Edit Files

CodeWhat it does
cat file.txtPrint the whole file to the screen.
less file.txtOpen a file one page at a time.
head -n 5 log.txtShow the first five lines of a file.
tail -n 5 log.txtShow the last five lines of a file.
tail -f log.txtFollow a file as it grows.
nano file.txtOpen a simple text editor.
vim file.txtOpen the vim text editor.
wc -l file.txtCount the lines in a file.
grep error log.txtFind lines that contain the word error.
grep -i error log.txtFind lines and ignore letter case.
grep -r todo .Search for todo in all files here.
sort file.txtPrint the lines in sorted order.

Permissions

CodeWhat it does
chmod +x run.shMake run.sh executable.
chmod 644 file.txtSet owner write and others read only.
chmod 755 script.shSet owner full access and others read and run.
chown ana file.txtChange the owner of file.txt to ana.
chown ana:dev file.txtChange the owner and group of a file.
umaskShow the default permission mask.
idShow your user and group IDs.
whoamiPrint your current user name.
groupsList the groups you belong to.
sudo commandRun one command as the root user.
sudo -iStart a root shell.
passwdChange your own password.

Processes

CodeWhat it does
ps auxList all running processes.
topShow live process and CPU usage.
htopShow a friendly live process viewer.
kill 1234Stop the process with PID 1234.
kill -9 1234Force stop the process with PID 1234.
pkill firefoxStop all processes named firefox.
jobsList jobs started in this shell.
sleep 60 &Run a command in the background.
fgBring a background job to the front.
Ctrl+CStop the running command.
Ctrl+ZPause the running command.
uptimeShow how long the system has run.

Search and Find

CodeWhat it does
find . -name '*.txt'Find all text files under this folder.
find . -type dFind all folders under this folder.
find . -size +10MFind files larger than ten megabytes.
find . -mtime -1Find files changed in the last day.
locate report.pdfFind a file by name in the index.
which python3Show the path of a command.
whereis lsShow binary and manual paths for ls.
type cdShow what kind of command cd is.
grep -n error log.txtFind lines and show line numbers.
grep -c error log.txtCount lines that contain error.
grep -v error log.txtShow lines that do not contain error.
historyShow your recent commands.

Disk and System

CodeWhat it does
df -hShow free space on all disks.
du -sh folderShow the total size of a folder.
free -hShow memory use in easy units.
lsblkList block devices such as disks.
mountShow mounted file systems.
uname -aShow kernel and system details.
hostnameShow the name of this machine.
dateShow the current date and time.
calShow a calendar for this month.
lscpuShow CPU details.
uptime -pShow system run time in words.
dmesg | tailShow the last kernel messages.

Network

CodeWhat it does
ip addrShow network interfaces and addresses.
ip routeShow the routing table.
ping -c 4 example.comSend four test packets to a host.
curl https://example.comFetch a web page to the screen.
curl -O https://x.com/f.zipDownload a file and keep its name.
wget https://x.com/f.zipDownload a file with wget.
ssh ana@serverOpen a secure shell on a server.
scp a.txt ana@server:Copy a file to a remote server.
ss -tulnShow listening network ports.
host example.comLook up the IP address of a name.
dig example.comQuery DNS records for a name.
traceroute example.comShow the path packets take to a host.

Packages and Help

CodeWhat it does
sudo apt updateRefresh the package list on Debian systems.
sudo apt install gitInstall the git package.
sudo apt remove gitRemove the git package.
sudo apt upgradeInstall newer versions of packages.
sudo dnf install gitInstall git on Fedora systems.
sudo pacman -S gitInstall git on Arch systems.
man lsOpen the manual page for ls.
man -k copySearch manual pages for the word copy.
ls --helpShow a short help text for ls.
help cdShow help for a shell builtin.
tar -czf a.tar.gz dirMake a compressed archive of a folder.
tar -xzf a.tar.gzExtract a compressed archive.
More on TechSchool
See the Linux interview questions Python JavaScript TypeScript HTML CSS React Vue 3 Node.js Java PHP C C++ C# Go SQL MongoDB Redis Git Docker Data Structures