Linux

Linux is a free, open source, and Unix-like operating system built around the Linux Kernel first created by Linus Torvalds in 1991.It has since evolved into a powerful and versatile family of operating systems used worldwide. Linux is known for its stability, security, and customization capabilities. The operating system is built on the principles of free and open-source software, allowing users to access and modify the source code. Since it is free, and anyone can modify it and make their own distributions, it is extremely popular. Just like unix it also has similar notions of a kernel, shell, and utilities. There are various flavors of Linux such as Debian, OpenSUSE, Red Hat etc.

Here are a few basic commands:

Command Description Example
ls List directory contents ls
cd Change the current directory cd /path/to/directory
pwd Print the current working directory pwd
cp Copy files or directories cp file.txt destination/
mv Move or rename files or directories mv old_name new_name
rm Remove files or directories rm file.txt
mkdir Create a new directory mkdir new_directory
rmdir Remove an empty directory rmdir empty_directory
cat Concatenate and display the content of files cat file.txt
more Display content one screen at a time more file.txt
less Display content with advanced features less file.txt
head Display the first few lines of a file head -n 5 file.txt
tail Display the last few lines of a file tail -n 10 file.txt
touch Create an empty file or update the access and modification time of a file touch new_file.txt
chmod Change file permissions chmod 755 file.sh
chown Change file owner and group chown user:group file.txt
ps Display information about running processes ps aux
top Display and update information about the top CPU processes top
kill Send a signal to a process kill -9 process_id
df Display disk space usage df -h
du Display file and directory space usage du -h
free Display amount of free and used memory in the system free -h
uname Display system information uname -a
date Display the current date and time date
cal Display a calendar for the current month or year cal
echo Display text or a variable echo "Hello, Linux!"
grep Search for a pattern in a file or stream grep pattern file.txt
find Search for files and directories in a directory hierarchy find /path/to/search -name "filename"
locate Find the location of files and directories locate filename
wget Download files from the internet wget URL
curl Transfer data from or to a server curl URL
tar Archives and extracts files from a tape or disk archive tar -cvf archive.tar files/
gzip Compress files using gzip compression gzip file.txt
gunzip Decompress files compressed with gzip gunzip file.txt.gz
ssh Connect to a remote server using SSH ssh user@hostname
scp Copy files between a local and remote machine using SSH scp file.txt user@remote:/path/to/destination/
rsync Sync files and directories between two locations rsync -avz source/ destination/
whoami Display the username of the current user whoami
passwd Change user password passwd
su Switch user or become superuser su username
sudo Execute a command as the superuser or another user sudo command
useradd Add a new user account useradd newuser
userdel Delete a user account userdel username
usermod Modify a user account usermod -aG groupname username
passwd Change user password passwd username
groups Display the groups a user belongs to groups username
id Display user and group information id username
history Display command history history
man Display the manual for a command man command
info Display information about a command info command
lsblk List block devices, including disks and partitions lsblk
lsusb List USB devices connected to the system lsusb
Commands for debian or debian based distributions that use APT (Advanced Package Tool)
# Install packages with Apt (Advanced Package Tool)
# Download the package lists from the repositories and update them to get information on the newest versions of packages and their dependencies. It will do this for all repositories and PPAs
sudo apt-get update
sudo apt-get -o Acquire::ForceIPv4=true update

# Do apt-get update but also fix missing packages
sudo apt-get update --fix-missing
sudo apt-get -o Acquire::ForceIPv4=true update --fix-missing

# Fetch new versions of packages existing on the machine if APT knows about these new versions, It will not install or remove packages
sudo apt-get upgrade

# Do a dist upgrade (not recommended)  [ will do apt-get upgrade, but also try to intelligently handle the dependencies, so it might remove some obsolete packages or add new one)
sudo apt-get dist-upgrade

# To list all the packages installed
dpkg --list

# To know what version of a package is installed
# apt-cache policy [name of the package]
apt-cache policy vi

# To install a package
# sudo apt-get install [name of the package]
sudo apt-get install vim
sudo apt-get -o Acquire::ForceIPv4=true install vim

# To install a specific version of a package
# sudo apt-get install package=version

# To remove a package (not any of its configuration files or data files, or any of its dependencies)
# sudo apt-get remove packagename

# To remove a package (with its configuration files, data files, but not its dependencies)
# sudo apt-get purge packagename or apt-get --purge packagename

# To remove remove all dependencies that are no longer required
# sudo apt-get autoremove

# To remove a package purge all of its dependencies and configuration files
# sudo apt-get --purge autoremove packagename
sudo apt-get --purge autoremove nano

# Turning a shell script into binary
sudo apt-get install shc
shc -f script.sh