Published: 05-08-2025

Linux Commands

When I come to realize that Windows is not for me, windows is such a bullshit OS, then I focused on Linux. Why linux? Well, its very simple, it allows you to take full control over your machine or computer. Actually its very fast and lightweight. It will also allow you to make changes whatever you want from your computer or machine which means it is customizable as well as secured than other OS. I know MacOS provides you world class UX as well as security. But who can bear those expenses? And for the Windows, its very risky to use while multiple malware attacks and make your machine very slow. Now most important thing is, Linux is fully open source. Its completely free for everyone. It has many tastes and distros. You can choice any of them according to your tastes. Actually Linux is for those people who want full control over their machine, OS as well as everything while MacOS and Windows don't allow you to do that so. They are very limited to provide you such a kind of opportunity. Besides, if you are Mathematics, Computer Science and Logical thoughts enthusiasts, then Linux is for you as I think! Because if you study on CS or Maths, you must have to know to operate Linux! Linux will give you a great power and make you generous since you are become used to in a Open Source softwares and packages. You will feel something to do for general people (its completely my personal opinion btw :")). Windows doesn't run on older archietecture based computer while only Linux can run. Learning Linux allows you to know about Computer Archietecture and how Computer actually works behind. Now, I am going to provide some Linux based bash commands that I learnt up to this day according to their usage in different ways and I made them as categorized-


Hardware Information


neofetch/fastfetch - It allows you to view your hardware and other stuffs at a glance, but before you need to install that first!

date - This will show time and date of your current location.

arch - This will let you know about the type of your processor archietecture.

df -h - It allows you to see how much memories your located files have taken, besides it will also show Size, Used, Avail, Use% and Mounted on.

du -sh * - It summarizes each and every folder or directory's spaces inside current directories.

du -sh - Shows the total space used by the current directory.

free -mh - Tells Mem (Physical RAM) and Swap (Disk-based virtual memory).

lsblk - Refers to block storage devices. These are devices that move data in fixed-size blocks, primarily including hard drives (HDD), Solid State Drives (SSD), partitions, CD/DVD drives, and USB flash drives.

lsusb - Refers to devices connected via the Universal Serial Bus (USB) ports. This includes external peripherals like keyboards, mice, printers, webcams, USB flash drives, and external hard drives.

lspci - Refers to devices connected via the Peripheral Component Interconnect (PCI) bus. This includes most high-speed internal hardware components on the motherboard, such as graphics cards, network interface cards (NICs), sound cards, SATA/NVMe controllers, and USB host controllers.

w - Shows who is logged in and what they are doing.

df -aT - Shows file system type (like ext4, tmpfs, etc.).

df -ha - Includes pseudo, duplicate, and inaccessible file systems.

uptime - Shows how long the system has been running, user count, and load average.

who -b - Shows last boot time.

users - Displays currently logged-in users.

ip a - Shows your IP address and network interfaces.

top - Terminal based program processing viewer with PID.

htop - Interactive system monitor (CPU, Memory, Processes).

history - Shows bash command history.

history -c - Clears history in current shell (not permanent).

history -c && > ~/.bash_history && history -w - Permanently clears bash history.

whoami - Shows your current logged-in username.

passwd (your username) - Change your user password.

ls -la - Lists all files and directories including hidden ones.

package --version - Shows installed package version.

man (command) - Opens manual page for the command.

(command) --help - Shows help and usage of the command.

~ - Represents your home directory path.

sensors - Shows the system and cpu temperature of your machine.

sudo inxi --basic - Tells the entire system information at a glance.

inxi --sensors - Tells the temperature and fan speed in RPM.

uname - According to Wikipedia, uname (short for unix name) is a computer program in Unix and Unix-like computer operating systems that prints the name, version and other details about the current machine and the operating system running on it. According to Oracle, in order to Display General System Information, use the uname command. It displays the operating system name as well as the system node name, operating system release, operating system version, hardware name, and processor type.

uname -a - Shows the full kernel information that you are currently using. Here -a refers to all.

uname -r - Shows the released latest kernel of your system where -r refers to release which mean the latest version of the kernel.

uname -s - Displays the system type of your OS where -s stands for system type.

showrev -a - It displays system and software release information.

hostnamectl - Shows you the production information of your machine.

tree -d -L 1 - This will let you see the directories from your root directory and -L 1 stands for the depth layer of your directories, you may change the value instead of 1 according to your taste in order to to know your directories depth.

system-analyze time - You will be able to know how much time it has been taken to boot your machine and other stuffs.

system-analyze blame - It will inform any issuse that happened in your machine and additional stuffs.

system-analyze critical-chain - command shows you the critical path of services that must start sequentially during the Linux boot process. It answers the question: What is the longest required dependency path that prevents the system from reaching its target (usually graphical.target or multi-user.target) sooner?

sudo dmidecode -t bios - Provides information about the System BIOS/UEFI firmware, including the vendor, version, and release date.

sudo dmidecode -t system - Provides details about the overall computer system, such as the manufacturer, product name, version, and serial number (often the most useful serial number).

sudo dmidecode -t baseboard - Provides information about the main board (motherboard), including the manufacturer, product name, version, and serial number.

sudo dmidecode -t chassis - Provides details about the physical enclosure, such as the manufacturer, type (e.g., Notebook, Desktop), version, and chassis serial number.

sudo dmidecode -t processor - Provides information about the CPU, including its type, family (e.g., Zen), speed, core count, and cache handles.

sudo dmidecode -t memory - Provides information about RAM modules (DRAM), including the number of memory devices, size, speed, and form factor (DIMM, SODIMM).

sudo dmidecode -t cache - Provides detailed information about the system's caches (L1, L2, L3), including their size, type, and speed.

sudo dmidecode -t connector - Provides a list of the physical connectors on the baseboard (e.g., SATA, USB, PCIe slots) and their types.

sudo dmidecode -t slot - Provides information about the system slots available (e.g., PCI, PCIe, AGP), their designation, and their current usage status.

sudo dmidecode -s - You will see many options for you you will pick one of them as an arguement get the serial number of the arguement. E.g., system-serial-number,chassis-type,chassis-serial-number etc.

hardinfo - You will get everything you need to know about your deivce by this free open-source package.

systemctl list-jobs --type=service - This is used to display a list of queued or currently running jobs in the systemd manager that specifically target service units.

systemctl stop httpd - This command immediately stops the httpd service in the current runtime session.

systemctl disable httpd - This command removes the symbolic links that tell systemd to start the httpd service during the system boot process.

sudo snort -A console -q -c /etc/snort/snort.conf -i (YOUR_INTERFACE_NAME) - An IDS can monitor system activities and detect potential security threats. One popular open-source IDS for Linux is Snort. You can get your interface name from ip address looking like wlp0s0, wlp1s0, enp0s3 etc.

speaker-test -t wav -c 8 - You will be able to inform and hear if your sound system (output) is okay or not. This is very useful to checkout sound problem.


Package Management


sudo apt install (package name) – Install packages.

sudo apt update && sudo apt upgrade – Update and upgrade system packages.

package --version – Check installed package version.

man (command) – Open manual for a command.

(command) --help – Show help/usage for a command.


File, Program, Security & Directory Management


ls – List files/folders.

ls -a – List all files, including hidden.

ls -A – List almost all files (excludes “.” and “..”).

ls <folder name> – List contents of a specific folder.

ls -la – Detailed list including hidden files.

pwd – Show current working directory.

mkdir <New folder> – Create new directory.

rm -r <Directory> – Remove a directory recursively.

cp <file> /path/to/destination – Copy file to another directory.

cp text.txt another_text.txt – Duplicate file.

cp text.txt /path/to/destination/another_text.txt – Copy and rename in new directory.

mv my_file.txt <Directory> – Move file to another directory.

mv old_name.txt new_name.txt – Rename file.

mv file1.txt file2.txt /path/to/destination – Move multiple files.

cat filename.txt – Display contents of a file.

wc -w filename.txt – Count words in file.

wc -w < filename.txt – Count words (without showing filename).

cat ~/.bash_history > file.txt - Creates a .txt file containing your bash history at once. You can create similar files anywhere anytime.

bash > filename.txt - This will create a .txt file at once for you and you can use this method where datasets are contained.

sed -i 's/mistaken/correct/g' filename – Replace text in file (in-place).

sed -i 's/mistaken/correct/g' /path/to/filename – Replace text in file (with full path).

more <library name> - Getting pamphlet about any libary's usage.

ls -l | wc -l - This command will tell the total properties inside your current directories as human readable format (decimal).

sudo dpkg -i /path/to/filename.deb - Installing downloaded package files.

sudo apt install -f - Fix missing dependencies.

chmod +x <program> - It executes a program.

chmod 000 <name of a directory> - It locks your folder and only root user can view this folder.

sha256sum <file name> - You can verify SHA256 SUM by running this command for your installed file. It's commonly used to verify .iso file.

ps -aux | grep <program name> - You can view if any program is running or not.

kill -15 <PID> - If you want to stop any program, then firstly view the PID from running top.

ssh - keygen -t rsa - Using ssh keys for staying more secure in your local machine is very important instead of using password authentication. This ssh key generates RSAkeys.

ssh-copy-id username@remote_server - By this way you will be able to copy your key to your remote server.

ls -a | grep keyword - You can findout your specific keyword contained file or stuffs from the existing folder.

fdupes /path/to/your/folder - Search any duplicate files exist inside any specific folder.

fdupes -r /path/to/your/folder - To search recursively for duplicate files within subdirectories.

find . -mindepth 1 -printf '%h %f\n' | sort -t ' ' -k 2,2 | uniq -f 1 --all-repeated=separate | tr ' ' '/' or find . -mindepth 1 -printf '%h %f\n' | sort -t ' ' -k 2,2 | uniq -f 1 --all-repeated=separate | tr ' ' '/' - You can use any of them and get as same result or output as previous command but this one is bit more complicated to memorize.


Text Editing & Programming


vim –Open text editor.

vim (filename.extension) – Create/edit a file.

vim program.c – Create/edit C program.

vim program.cpp – Create/edit C++ program.

vim text.txt – Create/edit text file.

gcc/clangC/C++ compilers.

gcc program.c -o program – Compile C program.

./program – Run compiled program.

gcc program.c -o program && ./program – Compile & run.

time ./program – Measure runtime.

gcc program.c -o program && time ./program – Compile, run & measure time.

bintutils - Binutils is a collection of GNU programming tools for creating and manipulating binary files, such as object files and executables and used for converting assembly language into machine code. [According to Google Search Result]

as - In order to compile assembly language, we need this compiler to execute our code.

as -32 filename.s -o filename.out - The command as -32 filename.s -o filename.out uses the GNU Assembler to translate the assembly code in filename.s into a 32-bit object file named filename.out.

ld -m elf_i386 -s filename.out -o exits used by the GNU Linker to combine compiled object files into a 32-bit ELF executable while stripping the symbol and debugging information to reduce the file size.

as -32 filename.s -o filename.out - Create assembly formated code from C language and make executable by ./filename.s.

objdump - It is a command-line utility that is part of the GNU Binutils (Binary Utilities) suite, primarily used to display various information about object files, executable files, and libraries.

objdump -x filename - It works after compiling C code by displaying a comprehensive, verbose view of the entire structure and contents of the resulting executable file. The -x flag is a shorthand for displaying the file's entire header contents.

gcc -S filename.c - You will be able to create assembly file of your C code by using this command.


Networking & Internet


nameserver 8.8.8.8 - In order to prevent pornographic sites viewing and appearing, you can customize your DNS by going /etc/resolv.conf and editing the file by sudo vim resolv.conf and writing nameserver <dns>. You can add cloudflare dns shield then restart the network manager sudo service network-manager restart or sudo systemctl restart NetworkManager. Additionally you might add specific domain names to prevent those sites viewing from your devie going /etc/hosts and adding the scripts Download "blocked sites" as HTML and paste it to the /etc/hosts. That's how you can protect yourself from adult sites viewing and so on.

nmcli - A command line tool for controlling network manager.

nmcli d - To view the network state.

nmcli r wifi on - For turning on the WiFi.

nmcli d wifi list - Viewing available wifi list.

nmcli d wifi connect <wifi name> password <password> - To connect a network.

lynx/w3m – Terminal web browsers (install required).

lynx www.example.com – Visit a website in terminal.

nmap – Network scanner (install required).

nmap -sn 192.168.0.XXX/24 – Scan devices on local network.

fast - Let you know your internet speed.

wget <link> - Can download something from terminal.

ddgr <keyword> - Search something from your terminal by DuckDuck Go search engine known as most secured engines. sudo apt install ddgr to install.

wikit - A terminal based wikipedia accessor. wikit "<keyword>". Firstly required sudo apt install nodejs npm and then sudo npm install wikit -g.

Ollama - A free, open-source tool that simplifies running large language models (LLMs) like Llama 3 or Mixtral directly on your local computer (Mac, Windows, Linux). Can be installed curl -fsSL https://ollama.com/install.sh | sh and then pull a model like llama3 using ollama pull llama3 or any model. Can be used ollama run llama3 to run from the terminal. To use ollama, you need to use ollama run llama3 everytime. So this will load Ollama model everytime. To make Ollama accessible from terminal everytime, it needs to run some commands to permanently setup so that user can run anytime rather than loading whole model everytime and killing time. Firstly, sudo systemctl daemon-reload tells the systemd manager to reread its configuration, rerun generators, reload all unit files (like service definitions), and rebuild the dependency tree, which is crucial after changing unit files or adding new services to apply those changes without a full system reboot. It's like a refresh button for systemd's understanding of your services and system setup. sudo systemctl enable ollama makes the Ollama application start automatically every time your Linux system boots up, running it as a background service (daemon) so it's always available for serving large language models (LLMs) without needing manual startup or login, unlike just running ollama serve which stops when you log out. It uses systemd, the standard Linux service manager, to control the ollama.service file. Now enable the service sudo systemctl enable ollama. Then restart the Unit status.service sudo systemctl restart ollama. Now view service if enabled or not sudo systemctl status ollama. To check from browser, use ollama serve to get http://localhost:11434 which is basically used for different purpose, this REST API access models via http://localhost:11434. You can send requests to this API from Python scripts or other applications without starting a new ollama run command for each interaction. However,now we're ready to use ollama run llama3 which doesn't require to load the model everytime instead of setting up permanently to the local macine. [Information used here taken from Google Search Results and Ollama Documentation]

nslookup <domain name> - It is a program to query Internet domain name servers interactively.

dig <domain name> - A flexible tool for interrogating DNS name servers.

whois <ip address> - It searches for an object in a RFC 3912 database. This version of the whois client tries to guess the right server to ask for the specified object. If no guess can be made it will connect to whois.networksolutions.com for NIC handles or whois.arin.net for IPv4 addresses and network names.


Media & Documents


mpv file.mp3/mp4 – Play audio/video.

feh image.png – View image.

pdftotext file.pdf file.txt – Convert PDF to text.

mupdf file.pdf – View PDF file.

ffmpeg -i input.webm -vn -acodec libmp3lame -q:a 2 output.mp3 – Once FFmpeg is installed, navigate to the directory where your .webm file is located using the cd command. Then, use the following command to perform the conversion. Find more conversion manual usnig man ffmpeg command.

Downloading (yt-dlp)


yt-dlp "link" – Download video.

yt-dlp -x --audio-format mp3 "link" – Download audio only.

yt-dlp -F "link" – List available formats.

yt-dlp -o "video.mp4" "link" – Set filename.

yt-dlp -o "~/Videos/%(title)s.%(ext)s" "link" – Save to custom path.

yt-dlp -i "playlist-link" – Download playlist.

yt-dlp --write-subs --sub-lang en "link" – Download subtitles.

yt-dlp -c "link" – Resume download.

yt-dlp "link" --list-formats – Show format options.

yt-dlp -f (code) "%(title)s.%(ext)s" "link" – Download specific format.

yt-dlp -f "bv*[height=1080]+ba" -o "%(title)s.%(ext)s" "link" – Download 1080p video + best audio.

yt-dlp -f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best" "link" – Auto-pick best formats.

yt-dlp -f "bestvideo+bestaudio" "link" – Best quality merged.

yt-dlp -c --no-part --no-clean-infojson -o "%(title)s.%(ext)s" "link" – Resume broken download.

yt-dlp -f bestvideo+bestaudio -o "~/Videos/%(title)s.%(ext)s" "link" – Save in specific folder.


Searching


grep -Ri 'text' filename – Search word in file (recursive, case-insensitive).

grep -Ri 'sudo' /home/alex/Documents – Example: search “sudo” in Documents.


Navigation (Directories)


cd – Go to default directory.

cd Documents – Enter Documents folder.

cd - – Go to previous directory.

cd .. – Move up one directory.

cd ../Directory – Move to sibling directory.

cd /path/to/destination – Move to absolute path.

cd ~/ – Go to home directory.


Version control and Git


Accessing

git status - Used to see if the working tree is clean or not.

gh auth login - Login from VsCode to GitHub in order to access and make changes to the repository.

Creating a new repository

echo "# <repository name>" >> README.md - Naming the README file.

git init - Git initialization.

git add README.md - Adding the README file.

git commit -m "first commit" - Creating commit.

git branch -M main - Making changes to the main branch.

git remote add origin https://github.com/username/repository.git - Telling to make changes inside the following repository.

git push -u origin main - Lastly pushing the changes to the main origin.


Pushing an existing repository

git remote add origin https://github.com/username/repository.git - Telling to make changes inside the following repository.

git branch -M main - Making changes to the main branch.

git push -u origin main - Lastly pushing the changes to the main origin.


Another approach

git init - Git initialization.

git add - Telling to wrap up everything

git add . - Telling to finish wrapping everything.

git commit -m "Commit message" - Creating commit.

git push origin main - Pushing changes to the origin.


Any issues for pushing existing repository

git pull origin main - The Standard Way (Merge) and this is the safest way to bring the remote changes into the local branch.

git pull --rebase origin main - The Clean Way (Rebase). If you want to keep a straight project history without "merge commits".

git fetch origin - Downloads the new data, but doesn't change your code. Then

git rebase origin main - Taking the local work and move it on top of the main branch on the origin server. Then it should work git push origin main.

[Information used this section taken from Google Search Results, Gemini and GitHub Documentation]


Fun / Miscellaneous


cmatrix – Matrix-style animation.

sl – ASCII train animation.

source filename.sh – Run bash file in current shell (for shortcuts/aliases).

xeyes - A window will open which is a eye that will be influenced by your mouse point.