Linux Intermediate: Cheat Sheet
Linux Intermediate: Cheat Sheet
Linux Intermediate: Cheat Sheet
Linux Intermediate
This cheat sheet introduces you to more Linux commands that every developer/sysadmin should know.
MORE
ls -ll | more
Up arrow and Down arrow let you scroll through the output.
SED
sed is used among other things to apply substitution, nd or replace les content.
sed 's/blue/red/' colors.txt # changes the first occurrence in each line containing the blue word to red
sed 's/blue/red/2' colors.txt # changes the second occurrence in each line containing the blue word to red
sed 's/blue/red/g' colors.txt # changes all the occurrences containing the blue word to red
sed '1,3 s/blue/red/g' colors.txt # changes all the occurrences from line number 1 to 3 containing the blue word to red
AWK
awk '{print $1,$4}' colors.txt # split each line in columns (whitespace as separator) and prints column 1 and 4
awk 'NR==3, NR==6 {print NR,$0}' colors.txt # prints from line 3 to 6 prefixed with the line number (NR)
awk 'NR > 1 {print}' colors.txt # prints from line 2 to end of file
TOP
top command shows the Linux processes providing a dynamic real-time view of the system.
top
FIND
find command is used to search and locate les or directories that meet certain conditions.
find /home -name users.txt # finds users.txt file under /home and deep
find /home -iname users.txt # finds users.txt file ignoring case under /home and deep
find . -type f -name "*.java" # finds all Java files from current dir and deep
find /home -user asotobu # finds all files that belong to asotobu
find /home -group developer # finds all files that belong to the developer group
find / -amin -10 # finds all files accessed in the last 10 minutes
PWD
/home/asotobu/git
DF
df gets a summary of available and used disk space usage of the le system.
df
DU
DIFF
This command displays the di erences in the les by comparing the les line by line.
Symbols are:
a for add
c for change
d for delete
2,3d1
< mv
< comm
4a3,4
> diff
> comm
2,3d1 means from line 2 to 3 in le 1 needs to be delated to match line 1 of the second le.
4a2,3 means that line 4 in le 1 need to add lines 3 and 4 from the second le.
diff -c first.txt second.txt
ALIAS
Aliases are custom shortcuts to Linux commands. Some aliases are provided by out-of-the-box:
alias
l='ls -lah'
la='ls -lAh'
ll='ls -lh'
ls='ls -G'
lsa='ls -lah'
md='mkdir -p'
PING
ping checks network connectivity issues by sending one or more ICMP Echo Request packages to a speci ed destination IP.
ping google.com
TRACEROUTE
traceroute elicits a response from the router at each hop from your computer to the destination.
traceroute google.com
NSLOOKUP
Non-authoritative answer:
Name: google.com
Address: 216.58.211.238
HOSTNAME
localhost.localdomain
10.0.2.15
HISTORY
history command shows all of the last commands that have been recently used.
history
9982 pwd
9983 cd ..
9984 cd tmp9
9985 vi first.txt
9986 vi second.txt
9987 diff first.txt second.txt
9988 diff -c first.txt second.txt
9989 ping google.com
9990 uname -a
9991 traceroute
9992 traceroute google.com
9993 ll
9994 alias
9995 finger
9996 groups
9997 nslookup google.com
9998 sestatus
9999 hostname -d
10000 hostname -A
10001 code .
You can run any of the commands by appending exclamation (!) to the number of the command (i.e !9982 runs pwd).
UNAME
uname displays basic information about the operating system and hardware.
uname
Linux
uname -a
Linux localhost.localdomain 5.8.15-301.fc33.x86_64 # SMP Thu Oct 15 16:58:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
SESTATUS
FINGER
GROUPS
groups prints the names of the primary and any supplementary groups of a username or of the current process.
groups
osboxes wheel
root : root
USERADD
sudo useradd -g users -G wheel,developers alex # creates the user with primary and secondary groups
sudo useradd -s /usr/bin/zsh alex # creates the user with specific shell
sudo useradd -e 2019-01-22 alex # creates atheuser with the expiration date
GROUPADD
sudo groupadd -K GID_MIN=500 -K GID_MAX=700 mygroup # creates the group overriding /etc/login.defs values
USERDEL