Skip to content

Latest commit

 

History

History
372 lines (257 loc) · 5.97 KB

README.md

File metadata and controls

372 lines (257 loc) · 5.97 KB

Live URL: https://aminbiography.github.io/linux/

kali-linux

Here are some essential Linux commands that every Linux user should know.

01: Navigating the File System

pwd

Prints the current working directory.

pwd

cd

Changes the current directory to . To go back to the previous directory, use cd -.

cd /home/user

ls

Lists the files and directories in the current directory. Use ls -l for detailed information and ls -a to include hidden files.

ls -l

cd ~

Moves to the user's home directory.

cd ~

02: Managing Files and Directories

mkdir

Creates a new directory.

mkdir new_folder

touch

Creates a new empty file or updates the timestamp of an existing file.

touch file.txt

cp

Copies files or directories. Use -r to copy directories recursively.

cp file1.txt file2.txt

mv

Moves or renames files and directories.

mv file1.txt /home/user/docs/

rm

Removes a file. Use -r for directories and -f to force remove without prompt.

rm file.txt
rm -r folder

03: Viewing and Manipulating Files

cat

Displays the contents of a file.

cat file.txt

less

Allows you to view the contents of a file one screen at a time.

less file.txt

head

Displays the first 10 lines of a file (use -n to specify a different number).

head file.txt

tail

Displays the last 10 lines of a file (use -n for a different number).

tail file.txt

grep

Searches for a pattern inside a file.

grep "search_text" file.txt

04: File Permissions

chmod

Changes the permissions of a file or directory. Use r, w, x for read, write, and execute.

chmod 755 script.sh

chown :

Changes the owner and/or group of a file or directory.

chown user:group file.txt

05: Process Management

ps

Displays the current processes running on the system.

ps aux

top

Displays system processes and resource usage in real-time.

top

kill

Terminates a process by its process ID (PID).

kill 1234

killall

Terminates all processes with the given name.

killall firefox

bg

Resumes a paused job in the background.

bg

fg

Brings a background job to the foreground.

fg

06: Disk Usage

df

Displays disk space usage of file systems.

df -h

du

Shows disk usage for files and directories.

du -sh /path/to/directory

07: Networking

ping

Pings a host (IP or domain) to check network connectivity.

ping google.com

ifconfig or ip a

Displays network interfaces and their configurations.

ifconfig

netstat

Displays network connections, routing tables, interface statistics, and more.

netstat -tuln

08: Package Management

apt-get (Debian-based)

Used for package installation, removal, and updates (e.g., on Ubuntu).

sudo apt-get update
sudo apt-get install <package>

yum (Red Hat-based)

Used for package management in Red Hat-based distributions like CentOS.

sudo yum install <package>

dnf (Fedora-based)

A newer package manager for Fedora and CentOS.

sudo dnf install <package>

09: Searching for Files

find -name

Searches for files within a directory hierarchy.

find /home/user -name "file.txt"

locate

Searches for files using a prebuilt index (faster than find).

locate file.txt

10: Archiving and Compression

tar

Archives files. Use -czf to create a compressed archive and -xzf to extract.

tar -czf archive.tar.gz folder
tar -xzf archive.tar.gz

gzip

Compresses files using the gzip algorithm.

gzip file.txt

unzip

Extracts files from a .zip archive.

unzip archive.zip

11: User Management

useradd

Adds a new user.

sudo useradd newuser

passwd

Changes the password for a user.

sudo passwd newuser

whoami

Displays the current logged-in user.

whoami

12: System Information

uname -a

Displays detailed information about the system kernel.

uname -a

uptime

Shows how long the system has been running, along with the load averages.

uptime

free

Displays memory usage.

free -h

13: Help and Manual Pages

man

Displays the manual page for a command.

man ls

--help

Provides a brief help message for a command.

ls --help

14: Environment Variables

export =

Sets environment variables for the current session. This is useful for configuring paths and settings.

export PATH=$PATH:/new/directory/path

echo $

Displays the value of an environment variable.

echo $PATH

15: Viewing and Monitoring System Logs

dmesg

Displays system messages and logs, often used for troubleshooting hardware and kernel-related issues.

dmesg | less

journalctl

Views logs collected by systemd (on systems using systemd). Use -xe for more detailed, real-time logs.

journalctl -xe

kali-linux