linux

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.</p>

pwd

cd

Changes the current directory to . To go back to the previous directory, use cd -.</p> ``` 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 </p>

Creates a new directory.

``` mkdir new_folder ```

touch </p>

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

``` touch file.txt ```

cp </p>

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

``` cp file1.txt file2.txt ```

mv </p>

Moves or renames files and directories.

``` mv file1.txt /home/user/docs/ ```

rm </p>

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 </p>

Displays the contents of a file.

``` cat file.txt ```

less </p>

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

``` less file.txt ```

head </p>

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

``` head file.txt ```

tail </p>

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

``` tail file.txt ```

grep </p>

Searches for a pattern inside a file.

``` grep "search_text" file.txt ```

04: File Permissions

chmod </p>

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

``` chmod 755 script.sh ```

chown : </p>

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 </p>

Terminates a process by its process ID (PID).

``` kill 1234 ```

killall </p>

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 </p>

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 ```

yum (Red Hat-based)

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

``` sudo yum install ```

dnf (Fedora-based)

A newer package manager for Fedora and CentOS.

``` sudo dnf install ```

09: Searching for Files

find -name </p>

Searches for files within a directory hierarchy.

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

locate </p>

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 </p>

Adds a new user.

``` sudo useradd newuser ```

passwd </p>

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 =</p>

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

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

echo $</p>

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](https://i.pinimg.com/736x/fc/8f/66/fc8f6679f94fe93fc6fff400827f4173.jpg)