Basic Linux Commands:
ls: List files and directories in the current directory.
pwd: Print the working directory (current directory).
cd: Change the current directory.
touch: Create an empty file.
mkdir: Create a new directory.
rm: Remove files or directories.
cp: Copy files or directories.
mv: Move or rename files or directories.
cat: Display the contents of a file.
less or more: View text files one page at a time.
head and tail: Display the beginning or end of a file.
grep: Search for patterns in text using regular expressions.
find: Search for files and directories in a specified location.
chmod: Change file permissions.
chown: Change file ownership.
ps: List running processes.
kill: Terminate processes.
top or htop: Monitor system processes and resource usage.
df: Display disk space usage.
du: Estimate file and directory space usage.
free: Display system memory usage.
uptime: Show system uptime and load averages.
date: Display or set the system date and time.
Advanced Linux Commands:
tar: Archive and compress files.
zip and unzip: Create and extract compressed zip files.
dd: Copy and convert files or data blocks.
rsync: Synchronize files and directories between systems.
ssh: Securely access remote servers.
scp: Securely copy files between systems over SSH.
wget and curl: Download files from the internet.
cron: Schedule tasks to run at specific times.
sed: Stream editor for text manipulation.
awk: Text processing tool for data extraction and reporting.
grep with regular expressions: Advanced text pattern matching.
iptables: Configure firewall rules (use nftables for newer systems).
systemctl: Manage system services (systemd-based systems).
journalctl: Query and view system logs (systemd-based systems).
useradd, passwd, userdel: Manage user accounts.
groupadd, groupdel: Manage user groups.
sudo: Execute commands with superuser privileges.
tar with compression options: Create compressed archives (e.g., tar.gz, tar.bz2).
lsof: List open files and processes.
strace: Trace system calls and signals.
nc (Netcat): Networking utility for reading/writing data across networks.
ss and netstat: Display network socket statistics.
ddrescue: Recover data from damaged disks.
lvm: Logical Volume Manager for managing disks and volumes.
awk and sed scripting: Create powerful scripts for text processing.
rsync with SSH: Efficiently transfer files securely between systems.
find with -exec option: Execute commands on found files/directories.
These are just some examples of basic and advanced Linux commands. Linux provides a vast array of tools and utilities to perform a wide range of tasks, and the commands you use will depend on your specific needs and the distribution of Linux you are using. You can explore these commands further by using their respective manual pages (e.g., man ls, man grep) or online documentation for more in-depth information and options.
Simple File Backup Script:
This script creates a backup of a specified directory by copying its contents to a backup directory with a timestamp.
#!/bin/bash
# Define source and backup directories
source_dir="/path/to/source"
backup_dir="/path/to/backup"
# Create a timestamp for the backup folder
timestamp=$(date +%Y%m%d%H%M%S)
backup_folder="$backup_dir/backup_$timestamp"
# Create the backup directory
mkdir -p "$backup_folder"
# Copy the contents of the source directory to the backup directory
cp -r "$source_dir"/* "$backup_folder"
echo "Backup completed to $backup_folder"
Simple System Information Script:
This script gathers some basic system information and displays it to the user.
#!/bin/bash
# Get system information
hostname=$(hostname)
kernel=$(uname -r)
cpu_info=$(lscpu | grep "Model name")
memory=$(free -h | awk '/Mem/ {print $2}')
# Display system information
echo "Hostname: $hostname"
echo "Kernel Version: $kernel"
echo "CPU Model: $cpu_info"
echo "Memory: $memory"
Log File Monitoring Script:
This script continuously monitors a log file and displays new log entries as they are added.
#!/bin/bash
# Specify the log file to monitor
log_file="/var/log/syslog"
# Start monitoring the log file
tail -f "$log_file"
Top comments (0)