100 Useful Linux Commands with Examples

100 Useful Linux Commands with Examples

I created this guide because I found these commands so useful. Perfect for anyone looking to boost their skills in development, DevOps, or administration. Here, you can see 100 most important Linux commands to help you navigate and manage your system effectively. It covers the most essential Linux commands, complete with examples and descriptions. Whether you're managing files, directories, or system processes, this resource will help you master the command line efficiently. Keep this handy guide as a reference for navigating your Linux environment like a pro!


ls

Description: Lists files and directories in the current directory.

Example: ls -l

cd

Description: Changes the current directory.

Example: cd /home/user

pwd

Description: Displays the current directory path.

Example: pwd

cp

Description: Copies files or directories.

Example: cp file1.txt /home/user

mv

Description: Moves or renames files and directories.

Example: mv file1.txt file2.txt

rm

Description: Deletes files or directories.

Example: rm file1.txt

mkdir

Description: Creates a new directory.

Example: mkdir new_folder

rmdir

Description: Removes an empty directory.

Example: rmdir empty_folder

touch

Description: Creates an empty file or updates the timestamp of an existing file.

Example: touch newfile.txt

cat

Description: Displays the contents of a file.

Example: cat file1.txt

grep

Description: Searches for a specific pattern in a file or output.

Example: grep 'error' logfile.txt

find

Description: Searches for files and directories.

Example: find /home -name '*.txt'

chmod

Description: Changes file permissions.

Example: chmod 755 script.sh

chown

Description: Changes file owner and group.

Example: chown user:user file1.txt

sudo

Description: Executes a command with superuser privileges.

Example: sudo apt-get update

df

Description: Displays disk space usage of file systems.

Example: df -h

du

Description: Displays disk usage of files and directories.

Example: du -sh /home/user

top

Description: Displays running processes and resource usage.

Example: top

ps

Description: Displays a snapshot of current processes.

Example: ps aux

kill

Description: Terminates a process by PID.

Example: kill 1234

tar

Description: Archives files and directories.

Example: tar -czvf archive.tar.gz /path/to/directory

zip

Description: Compresses files.

Example: zip -r archive.zip /path/to/directory

unzip

Description: Extracts files from a ZIP archive.

Example: unzip archive.zip

wget

Description: Downloads files from the internet.

Example: wget https://example.com/file.zip

curl

Description: Transfers data to or from a server.

Example: curl -O https://example.com/file.txt

man

Description: Displays the manual for a command.

Example: man ls

echo

Description: Displays a line of text or variable value.

Example: echo 'Hello, World!'

nano

Description: Opens the nano text editor.

Example: nano filename.txt

vi

Description: Opens the vi text editor.

Example: vi filename.txt

history

Description: Displays the command history.

Example: history

alias

Description: Creates an alias for a command.

Example: alias ll='ls -l'

unalias

Description: Removes an alias.

Example: unalias ll

scp

Description: Securely copies files between hosts.

Example: scp file.txt user@remote:/path

rsync

Description: Syncs files and directories between locations.

Example: rsync -av /source /destination

ssh

Description: Connects to a remote machine securely.

Example: ssh user@remote

exit

Description: Exits the shell or command line.

Example: exit

clear

Description: Clears the terminal screen.

Example: clear

hostname

Description: Displays or sets the system's hostname.

Example: hostnamectl set-hostname new-hostname

ping

Description: Checks connectivity to a host.

Example: ping google.com

ifconfig

Description: Displays or configures network interfaces.

Example: ifconfig eth0

netstat

Description: Displays network connections, routing tables, and more.

Example: netstat -tuln

traceroute

Description: Traces the route packets take to a network host.

Example: traceroute google.com

nslookup

Description: Queries DNS information.

Example: nslookup example.com

dig

Description: Performs DNS lookups.

Example: dig example.com

iptables

Description: Configures network packet filtering rules.

Example: iptables -L

systemctl

Description: Controls the systemd system and service manager.

Example: systemctl status apache2

service

Description: Controls system services.

Example: service apache2 start

shutdown

Description: Shuts down or reboots the system.

Example: shutdown now

reboot

Description: Reboots the system.

Example: reboot

uptime

Description: Displays system uptime.

Example: uptime

uname

Description: Displays system information.

Example: uname -a

df

Description: Shows disk space usage.

Example: df -h

free

Description: Displays memory usage.

Example: free -m

ps

Description: Displays process status.

Example: ps aux

jobs

Description: Lists active jobs.

Example: jobs

bg

Description: Resumes a suspended job in the background.

Example: bg %1

fg

Description: Brings a background job to the foreground.

Example: fg %1

killall

Description: Kills processes by name.

Example: killall firefox

xargs

Description: Builds and executes command lines from standard input.

Example: echo 'file1.txt file2.txt' | xargs rm

awk

Description: Pattern scanning and processing language.

Example: awk '{print $1}' file.txt

sed

Description: Stream editor for filtering and transforming text.

Example: sed 's/old/new/g' file.txt

diff

Description: Compares files line by line.

Example: diff file1.txt file2.txt

sort

Description: Sorts lines of text files.

Example: sort file.txt

uniq

Description: Removes duplicate lines from sorted files.

Example: sort file.txt | uniq

head

Description: Outputs the first part of files.

Example: head -n 10 file.txt

tail

Description: Outputs the last part of files.

Example: tail -n 10 file.txt

wc

Description: Prints newline, word, and byte counts for files.

Example: wc -l file.txt

tee

Description: Reads from standard input and writes to standard output and files.

Example: echo 'data' | tee file.txt

ln

Description: Creates links between files.

Example: ln -s /path/to/file link_name

bc

Description: An arbitrary precision calculator language.

Example: echo '5 + 3' | bc

expr

Description: Evaluates expressions.

Example: expr 5 + 3

test

Description: Tests file types and compares values.

Example: [ -f /path/to/file ] && echo 'File exists'

whoami

Description: Prints the current user name.

Example: whoami

id

Description: Prints user and group information.

Example: id username

chmod

Description: Changes file permissions.

Example: chmod 755 file.txt

chgrp

Description: Changes the group ownership of a file.

Example: chgrp groupname file.txt

useradd

Description: Creates a new user.

Example: sudo useradd newuser

usermod

Description: Modifies a user account.

Example: sudo usermod -aG groupname username

userdel

Description: Deletes a user account.

Example: sudo userdel username

passwd

Description: Updates a user's password.

Example: sudo passwd username

groupadd

Description: Creates a new group.

Example: sudo groupadd newgroup

groupdel

Description: Deletes a group.

Example: sudo groupdel groupname

groupmod

Description: Modifies a group.

Example: sudo groupmod -n newname oldname

hostnamectl

Description: Controls the system hostname.

Example: hostnamectl set-hostname newhostname

timedatectl

Description: Controls the system time and date.

Example: timedatectl set-timezone America/New_York

journalctl

Description: Queries the systemd journal.

Example: journalctl -u ssh

dmesg

Description: Prints the kernel ring buffer.

Example: dmesg | grep error

lsblk

Description: Lists information about block devices.

Example: lsblk

blkid

Description: Locates and prints block device attributes.

Example: blkid /dev/sda1

mount

Description: Mounts a filesystem.

Example: mount /dev/sda1 /mnt

umount

Description: Unmounts a filesystem.

Example: umount /mnt

mkfs

Description: Builds a Linux filesystem.

Example: mkfs.ext4 /dev/sda1

fsck

Description: Checks and repairs a Linux filesystem.

Example: fsck /dev/sda1

parted

Description: Manipulates partition tables.

Example: parted /dev/sda mklabel gpt

fdisk

Description: Manipulates disk partition tables.

Example: fdisk /dev/sda

tune2fs

Description: Adjusts tunable filesystem parameters.

Example: tune2fs -l /dev/sda1

file

Description: Determines file type.

Example: file filename

stat

Description: Displays file or filesystem status.

Example: stat filename

readlink

Description: Prints resolved symbolic links or canonical file names.

Example: readlink -f /path/to/symlink

uptime

Description: Shows system uptime.

Example: uptime

date

Description: Displays or sets the system date and time.

Example: date +%Y-%m-%d

cal

Description: Displays a calendar.

Example: cal 2024

bc

Description: Basic calculator language.

Example: echo 'scale=2; 5/3' | bc

?

Abin Mathew Sabu

IT Security Administrator | CompTia Security+ | Vulnerability Assessment | Incident Reporting & Response | Security Gap Assessment | Cybersecurity Enthusiast

2 个月

I’m going to share this. Very useful

要查看或添加评论,请登录

社区洞察

其他会员也浏览了