Bash Commands You Should Know!

Feb 14, 2021

Handy Linux Terminal commands and tricks you should know!

Contents:
Text Handling
Networking
Storage
Tricks
Other

Text Handling

head -5

Output the first 5 lines of text

cat

cat file.txt
Display the contents of a file

tail -5

Output the last 5 lines of text

wc

Wordcount Utility
Output: Line | Words | Characters

grep

Handy search utility for searching plain-text data

$ ps aux | grep ssh - This will search all running processes for ones that contain 'ssh'

Networking

ip addr

Display network interfaces
*The replacement for ifconfig

cat /proc/net/arp

Display local network devices | Just arp will work on most distros

netstat -pnltu

View open TCP/UDP Ports | Flag Options

sudo may be needed to view program names.

curl ifconfig.me

Find out your External IP using ifconfig.me

netstat -natp

View current network connections

Storage

df -h

View disk usage | -h (Human readable)

du -sh *

View the size of all directories

Tricks

!!

Repeat last command

sudo !!

Repeat last command using sudo

!$

Passing Arguments from Previous Command
---bash-trick

$HOME

Enviromental Variable for your home directory

Other

cal

Display the current month, with the day highlighted

ps aux

View all running processes | Kill process with kill <PID>

Parameter Expansion With {a,b}

Instead of $ mv README.txt README.md use mv README.{txt,md}

$ echo pre{1,2,3}fix
Output: pre1fix pre2fix pre3fix

More Info

oldnew

$ ssh [email protected]

Replace ubuntu in the last command with bob
$ ^ubuntu^bob
ssh [email protected]

Have another? Send it over!

Tags