Linux Commands
Everyday Linux commands for Ubuntu/Debian and Rocky/Red Hat. Pipes (|), redirects (> and >>), && and * wildcards work with all of them.
Practice these in Terminal Practice
Moving around
-
pwd -
print the current directory
Usage:
pwd -
ls -
list files
Usage:
ls [-a -l -h] [PATH...] -
cd -
change directory
Usage:
cd [DIR] (cd .. = up, cd ~ or cd = home) -
tree -
show folders as a tree
Usage:
tree [-a] [DIR] -
find -
search for files
Usage:
find [DIR] [-name '*.log'] [-type f|d]
Reading files
-
cat -
print file contents
Usage:
cat [-n] FILE... -
head -
show the first lines
Usage:
head [-n COUNT] [FILE] -
tail -
show the last lines
Usage:
tail [-n COUNT] [FILE] -
wc -
count lines, words, bytes
Usage:
wc [-l -w -c] [FILE...]
Working with text
-
grep -
search text for a pattern
Usage:
grep [-i -v -n -c -o -r] PATTERN [FILE...] -
sort -
sort lines
Usage:
sort [-r -n -u] [FILE] -
uniq -
collapse repeated lines
Usage:
uniq [-c] [FILE] (sort first!) -
cut -
pick fields out of each line
Usage:
cut -d' ' -f1,3 [FILE] -
echo -
print text
Usage:
echo [-n] TEXT...
Changing files
-
touch -
create an empty file
Usage:
touch FILE... -
mkdir -
make directories
Usage:
mkdir [-p] DIR... -
cp -
copy files
Usage:
cp [-r] SOURCE... DEST -
mv -
move or rename files
Usage:
mv SOURCE... DEST -
rm -
remove files
Usage:
rm [-r -f] FILE... -
rmdir -
remove empty directories
Usage:
rmdir DIR...
Permissions and users
-
chmod -
change file permissions
Usage:
chmod 755 FILE or chmod u+x FILE -
chown -
change file owner (needs root)
Usage:
chown USER[:GROUP] FILE... -
whoami -
show your user name
Usage:
whoami -
id -
show user and group IDs
Usage:
id -
sudo -
run a command as root
Usage:
sudo COMMAND [ARGS...]
Packages: Ubuntu / Debian
-
apt -
install/list packages (Debian/Ubuntu)
Usage:
apt list --installed | sudo apt install NAME -
dpkg -
list installed packages (Debian/Ubuntu)
Usage:
dpkg -l [NAME]
Packages: Rocky / Red Hat
-
dnf -
install/list packages (Red Hat)
Usage:
dnf list installed [NAME] | sudo dnf install NAME -
yum -
older name for dnf (Red Hat)
Usage:
same as dnf -
rpm -
query installed packages (Red Hat)
Usage:
rpm -qa | rpm -q NAME
The system
-
ps -
list running processes
Usage:
ps [aux] -
df -
show disk space
Usage:
df [-h] -
free -
show memory usage
Usage:
free [-h] -
uptime -
show how long the system has been up
Usage:
uptime -
uname -
show system information
Usage:
uname [-a -r] -
hostname -
show the machine's name
Usage:
hostname -
date -
show the date and time
Usage:
date
Help and history
-
help -
list commands for this question
Usage:
help (help all = every command) -
man -
show help for a command
Usage:
man COMMAND -
which -
show where a command lives
Usage:
which COMMAND... -
history -
show commands you have typed
Usage:
history -
clear -
clear the screen
Usage:
clear (or Ctrl+L)
From localhostmonkey.com/learn/cheat-sheets/linux/