Live URL: https://aminbiography.github.io/linux/
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 ~
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
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
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
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
df
Displays disk space usage of file systems.
df -h
du
Shows disk usage for files and directories.
du -sh /path/to/directory
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
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>
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
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
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
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
man
Displays the manual page for a command.
man ls
--help
Provides a brief help message for a command.
ls --help
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
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