DEV Community

Cover image for Linux Commands Cheat Sheet :)
Madhav Ganesan
Madhav Ganesan

Posted on • Edited on

Linux Commands Cheat Sheet :)

Grep

grep "pattern" filename // search for the particular pattern
grep -n "pattern" filename // show along with page number
grep -e "pattern1" -e "pattern2" filename //Search for multiple patterns
Enter fullscreen mode Exit fullscreen mode

Killall

It is used to stop all processes that match a given name

killall process_name
Enter fullscreen mode Exit fullscreen mode

ps

It is used to list all the active processes in the current terminal

ps
ps aux 
(a - show all processes)
(u - display user)
(x - show processes not attached to the terminal)
Enter fullscreen mode Exit fullscreen mode

Top

This command provides a real-time, interactive view of system processes, including CPU and memory usage.

top
Enter fullscreen mode Exit fullscreen mode

Ping utility

It is a basic tool used to test network connectivity. It helps to check if your computer can reach
another computer over the internet.

Round-trip time:
Time it takes for data to travel from source to the destination and back

When you use the ping command, your computer sends a small data packet called an "ICMP echo request" to the target address. The target then sends back a response called an "ICMP echo reply."

ping [url]
Enter fullscreen mode Exit fullscreen mode

Third party ping applications:
fping

What is the Default Gateway?

It is the IP address of a router or network device that your computer uses to communicate with other devices outside your local network. In other words, it's the address that your computer sends traffic to when it needs to access resources beyond its own subnet.

This means that any network traffic that needs to go beyond your local subnet (e.g., to the internet) will be sent to 172.22.8.1, which is likely the IP address of your router or gateway device.

If your computer wants to access a website, it sends the request to the default gateway (172.22.8.1), which then forwards the request to the internet. The gateway also handles incoming traffic from the internet and directs it back to your computer.

File Transfer Protocol

1) Connect to FTP server
It is used to connect to the FTP server from a terminal or command prompt.

ftp [url]
Enter fullscreen mode Exit fullscreen mode

FTP Client

Ex. FileZilla

Network Mapper (nmap)

It is a network scanning tool used for discovering hosts and services on a computer network. It’s widely used for security auditing, network inventory, and identifying network issues.

nmap -sT target_ip //scan open TCP ports
nmap -sU target_ip //scan open UDP ports 
nmap -A target_ip //agressive scan
Enter fullscreen mode Exit fullscreen mode
// Report
Lists all open ports
PORT    STATE SERVICE
21/tcp  open  ftp
80/tcp  open  http
110/tcp open  pop3
135/tcp open  msrpc
143/tcp open  imap
443/tcp open  https
Enter fullscreen mode Exit fullscreen mode

ifconfig(Similar to ipconfig of windows)

This command gives you the details about network interface cards(NIC)

ifconfig
Enter fullscreen mode Exit fullscreen mode

Symbolic Link (Symlink)

A symbolic link (or symlink) is a type of file that serves as a reference to another file or directory. It's essentially a shortcut or alias that points to the target file or directory.

ln -s [TARGET] [LINK_NAME]
Enter fullscreen mode Exit fullscreen mode

Remove orca

sudo apt remove orca
Enter fullscreen mode Exit fullscreen mode

Directory management

mkdir directory //create a folder
rmdir directory //delete a folder
Enter fullscreen mode Exit fullscreen mode

Package management

apt-get install package-name
apt-get remove package-name
apt-get purge package-name
apt-get update
apt-get upgrade //upgrades all installed packages to the latest versions
Enter fullscreen mode Exit fullscreen mode

Single Dash (-): Used for single-letter options. Example: -h for help.
Double Dash (--): Used for word options. Example: --help for detailed help.

Create a New File:

cat > filename 
Enter fullscreen mode Exit fullscreen mode

Type your content and
Press Ctrl + D to save and exit.

Granting Permissions

Each file and directory must be allocated a particular level of permission
for the different identities using it. The three levels of permission are
listed hereunder:
r - (Read permission) This grants permission only to open and view a file.
w - (Write permission) This allows users to view and edit a file.
x - (Execute permission) This will enable users to execute a file (This does
not guarantee viewing or editing it).

Changing Permissions
We can use the Linux command **chmod **to change the permissions.

rwxrwxrwx
rwx for the owner: 7 (rwx)
rwx for the group: 7 (rwx)
rwx for others: 7 (rwx)
Enter fullscreen mode Exit fullscreen mode

Read (r) = 4 (binary 100)
Write (w) = 2 (binary 010)
Execute (x) = 1 (binary 001)

Stay Connected!
If you enjoyed this post, don’t forget to follow me on social media for more updates and insights:

Twitter: madhavganesan
Instagram: madhavganesan
LinkedIn: madhavganesan

Top comments (2)

Collapse
 
brennan_maxwell_9c674c15e profile image
Brennan Maxwell

Awesome summary of Linux commands! One additional command that I found helpful was the 'df' command for viewing storage status. Thanks for sharing this cheat sheet. :)

Collapse
 
madgan95 profile image
Madhav Ganesan

Sure will add that💯