Bashintermediate30 snippets

Linux Terminal: Vital Commands

Lose the fear of the black screen. Navigate folders, manage files and control the server without touching the mouse. Survival basics.

Sections6
1

File Management

5 snippets

Fundamental commands for navigating and manipulating files and directories on Linux.

List Detailed Files

Lists all files including hidden ones with permission, size, and date details

Quando usar: When you need to view all files with detailed information, including hidden files (starting with .)

bash
ls -lah

Copy Files Recursively

Copies directories and their content recursively, preserving attributes

Quando usar: For backing up entire directories or duplicating folder structures

bash
cp -r /origem /destino

Move or Rename Files

Moves files/directories or renames if destination is in the same directory

Quando usar: To organize files or rename them directly via the terminal

bash
mv arquivo.txt /novo/caminho/
mv arquivo_antigo.txt arquivo_novo.txt

Find Files by Name

Locates files in the system recursively using glob patterns

Quando usar: When you need to locate specific files in large directory structures

bash
find /caminho -name "*.log"
find . -type f -name "config*"

Create nested directories

Creates multiple levels of directories at once

Quando usar: To quickly create complex folder structures without needing to create each level manually

bash
mkdir -p /projeto/src/components/ui
2

Permissions and Ownership

4 snippets

File and directory access control using chmod, chown, and umask.

Change Permissions Numerically

Sets permissions using octal notation (rwx = 7, rw- = 6, r-x = 5)

Quando usar: 755 for executables (rwxr-xr-x), 644 for data files (rw-r--r--)

bash
chmod 755 script.sh
chmod 644 arquivo.txt

Change Permissions Symbolically

Modifies permissions using symbolic notation (u=user, g=group, o=others)

Quando usar: When you want to modify specific permissions without changing others

bash
chmod u+x script.sh
chmod go-w arquivo.txt

Change Owner Recursively

Changes the owner and group of files/directories recursively

Quando usar: To correct permissions after deployment or web server configuration

bash
chown -R usuario:grupo /var/www/html

View Octal Permissions

Displays file permissions in numeric format

Quando usar: To quickly check the numeric value of current permissions

bash
stat -c '%a %n' arquivo.txt
3

Process Management

5 snippets

Monitoring, controlling, and manipulating running processes on the system.

List User Processes

Displays all processes of the current user with CPU and memory details

Quando usar: To identify PIDs of specific processes or diagnose resource usage

bash
ps aux | grep usuario
ps -ef | grep nginx

Monitor Processes in Real-time

Interactive interface with real-time process updates

Quando usar: For continuous monitoring of CPU, memory, and identifying problematic processes

bash
top
htop

Kill Process by PID

Terminates process using different signal levels

Quando usar: kill for graceful termination, kill -9 to force immediate termination

bash
kill 1234
kill -9 1234
kill -SIGTERM 1234

Kill Process by Name

Terminates all processes matching the name

Quando usar: When you know the process name but not the PID

bash
pkill nginx
killall node

Run process in background

Starts process in the background, freeing up the terminal

Quando usar: To run long scripts without blocking the terminal (nohup keeps it running after logout)

bash
npm run dev &
nohup python3 script.py &
4

Network and Connectivity

5 snippets

Tools for network diagnostics, file transfer, and connectivity testing.

Test Connectivity

Sends ICMP packets to check if the host is reachable

Quando usar: To check network connectivity and latency (-c limits the number of packets)

bash
ping -c 4 google.com
ping 192.168.1.1

Download Files

Downloads files from the web via HTTP/HTTPS

Quando usar: wget for simple downloads, curl for APIs and more complex requests

bash
wget https://example.com/file.zip
curl -O https://example.com/file.tar.gz

View Ports in Use

Lists all open TCP/UDP ports and associated processes

Quando usar: To identify port conflicts or check if a service is listening

bash
netstat -tulpn
ss -tulpn

Secure Transfer (SCP)

Copies files between machines via SSH

Quando usar: To securely transfer files between servers (use -r for directories)

bash
scp arquivo.txt user@servidor:/path/
scp -r /pasta user@servidor:/destino

Check External IP

Discovers the machine's public IP address

Quando usar: To know your public IP when working remotely or configuring firewalls

bash
curl ifconfig.me
wget -qO- ifconfig.me
5

Package Management

5 snippets

Installing, updating, and removing software using package managers (APT/YUM).

Update Package List (Debian/Ubuntu)

Synchronizes the list of available packages with repositories

Quando usar: Always before installing new packages to ensure updated versions

bash
sudo apt update

Install Package (Debian/Ubuntu)

Downloads and installs package with all dependencies

Quando usar: To install software via official repositories (-y automatically confirms)

bash
sudo apt install nginx -y

Update System (Debian/Ubuntu)

Updates all installed packages to newer versions

Quando usar: Regular system maintenance for security patches and improvements

bash
sudo apt update && sudo apt upgrade -y

Remove Package (Debian/Ubuntu)

Uninstalls package, keeping configuration files

Quando usar: remove keeps configs, purge removes everything (useful for clean reinstallation)

bash
sudo apt remove pacote
sudo apt purge pacote

Search packages (Debian/Ubuntu)

Searches for available packages in repositories

Quando usar: To find the exact package name before installing

bash
apt search python3
apt-cache search nodejs
6

System Information

6 snippets

Commands for getting hardware, OS, and resource usage information.

Disk Usage

Displays used and available space on all mounted partitions

Quando usar: To check for sufficient disk space (-h displays in human-readable format)

bash
df -h

Directory Size

Calculates total size of directories and files

Quando usar: To identify which directories are consuming the most space

bash
du -sh /var/log
du -h --max-depth=1 /home

Memory Usage

Shows RAM and swap usage in human-readable format

Quando usar: To diagnose memory issues or check if swap is being used

bash
free -h

CPU Information

Displays processor details (model, cores, frequency)

Quando usar: To check hardware specifications before optimizations

bash
lscpu
cat /proc/cpuinfo

System uptime

Shows how long the system has been running and average load

Quando usar: To check server stability and load average

bash
uptime

System version

Identifies Linux distribution and kernel version

Quando usar: To document environment or check software compatibility

bash
uname -a
cat /etc/os-release

Get the latest articles delivered to your inbox.

Follow Us: