Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Linux Cheat Sheet

File Commands Directory Aliases File Permission Commands


Command Description Alias Directory Command Description
cat <file> Print file contents . Current directory chmod <mode> <file> Change file permissions
touch <file> Create file (or update timestamp) .. Parent directory Add execute permission for the
chmod u+x <file>
owner
cp <src> <dst> Copy a file ~ Home directory
Set file permissions to 644
mv <src> <dst> Move / rename a file chmod 644 <file> (read/write for owner, read for
rm <file> Remove file Link Commands group and everyone else)

head <file> Print first 10 lines of file Command Description Add write permission for the
chmod -R g+w <dir>
group recursively to a directory
tail <file> Print last 10 lines of file ln -s <target> <link> Create symbolic link
chown <owner> <file> Change file owner
Print last 10 lines and any new ln <target> <link> Create hard link
tail -f <file> Change directory owner
lines added to file readlink -f <file> Print absolute path of file chown -R <owner> <dir>
recursively
chown <owner>:<group>
Directory Commands Search Commands <file>
Change file owner and group

Command Description Command Description chgrp <group> <file> Change file group
ls List files in the current directory grep <pattern> <file...> Search for pattern in file(s)
ls <dir> List files in <dir> Search for pattern recursively in a File Permission Bits
grep -r <pattern> <dir>
ls -l List files with details directory Bit Description
ls -a List all files (including hidden) Search for pattern case- 4 Read (r)
grep -i <pattern> <file>
insensitively
ls -al List all files with details 2 Write (w)
Search for lines not matching
grep -v <pattern> <file>
Print the current/working pattern 1 Execute (x)
pwd
directory
grep -n <pattern> <file> Search and print line numbers
Change current directory to First digit represents the owner, the second digit represents the
cd <dir> Find files in <dir> with name group, and the third digit represents everyone else.
<dir> find <dir> -name <name>*
starting with <name>
cd .. Go up one directory For example, 640 means read/write for owner, read for group, and no
Find files in <dir> of type
find <dir> -type <type> permissions for everyone else.
mkdir <dir> Create directory <type>
Create directory and any missing
mkdir -p <dir>
parent directories File Permission User Types
Superuser Commands
cp -r <src> <dst> Copy a directory and its contents User Type Description
Command Description
mv <src> <dst> Move / rename a directory u Owner
sudo <cmd> Run command as superuser (root)
rmdir <dir> Remove an empty directory g Group
su Switch to superuser (root)
Remove a directory and its o Everyone else
rm -r <dir> su <user> Switch to user <user>
contents a All

© Nic Wortel, Software Consultant & Trainer - Last updated on October 16, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets
System Information Commands Secure Shell (SSH) Commands IO Redirection
Command Description Command Description Command Description
df Show file system disk usage ssh-keygen Generate SSH key pair Replace contents of file with
<cmd> > <file>
output
df -h Show disk usage in MB/GB/TB ssh-add <key> Add SSH key to SSH agent
<cmd> >> <file> Append output to file
du Show disk usage per directory ssh-add -l List SSH keys in SSH agent
<cmd> < <file> Redirect input from file
du -h Show disk usage in MB/GB/TB Copy SSH key to <host> for
ssh-copy-id <user>@<host>
<user> <cmd> 2> <file> Redirect stderr to file
free Show memory usage
Connect to <host> as current <cmd> &> <file> Redirect stdout and stderr to file
free -h Show memory usage in MB/GB/TB ssh <host>
user
uptime Show uptime ssh <user>@<host> Connect to <host> as <user>
Pipe Commands
whoami Show current user Copy local file <src> to <dest>
scp <src> <host>:<dest> Command Description
uname Show system information on <host>
<cmd1> | <cmd2> Pipe stdout to next cmd
uname -a Show all system information Copy file <src> from <host> to
scp <host>:<src> <dest>
local <dest> <cmd1> |& <cmd2> Pipe stderr to next cmd

Shutdown/Reboot Commands
APT Commands (Debian/Ubuntu) Bash Shortcuts
Command Description
Command Description Shortcut Description
Power off the system after 1
shutdown apt install <pkg> Install package Ctrl + C Stop current command
minute
shutdown now Power off the system immediately apt remove <pkg> Remove package Ctrl + A Go to beginning of line

shutdown 16:30 Power off the system at 16:30 apt purge <pkg> Remove package and config files Ctrl + E Go to end of line

shutdown -c Cancel a scheduled shutdown apt update Update package list Ctrl + K Cut current line

reboot Reboot system apt upgrade Upgrade packages Ctrl + L Clear screen

poweroff Power off system apt search <term> Search for package


Directory Structure
Process Commands Other Commands Directory Description

Command Description Command Description / Root

ps List processes echo <msg> Print message to stdout /bin Binary or executable programs

ps -ef List all processes man <cmd> Display manual page for <cmd> /etc System configuration files

top Display processes in real time Display history of given /home User home directories
history
commands
kill <pid> Kill process /opt Optional or third-party software
which <cmd> Find path to executable <cmd>
pkill <name> Kill process with name /tmp Temporary files
Locate binary, source, and
whereis <cmd> /usr User programs
killall <name> Kill all processes with name manual page for <cmd>
/var Variable data
/var/log Log files

© Nic Wortel, Software Consultant & Trainer - Last updated on October 16, 2023 - Find more cheat sheets at https://nicwortel.nl/cheat-sheets

You might also like