The Beginner’s guide to Linux Bash
If you’re like me then you are new to the world of Linux. So lets enjoy the realm of open-source operating systems! Linux offers unparalleled flexibility and power, but for beginners, its command-line interface can seem like a daunting labyrinth. Fear not, for we’ve crafted a handy cheat sheet to help you navigate this exciting terrain with ease.
Visualise File Trees
Linux commands often involve directories and file paths. Visualise your file system like a tree. The root directory (“/”) is the trunk, and branches lead to subdirectories. To move up one level, use “cd ..,” where “..” signifies the parent directory. Visualising this tree structure can help you navigate effortlessly.
Aliases for Efficiency
Create custom aliases to shorten lengthy or frequently used commands. For instance, if you’re tired of typing “ls -la” to list all files, create an alias like “ll” that maps to the full command. Just remember to save aliases in your shell configuration file (e.g., “.bashrc”).
Mindful Mnemonics with Shell Scripts
Take mnemonics to the next level with shell scripts. Write simple scripts that use descriptive names to encapsulate complex commands. For example, if you often compress files, create a script named “compressmyfiles.sh” that contains the gzip or tar command, making it easy to recall.
Flashcards for Command Recognition
Create digital or physical flashcards with the command on one side and its description on the other. Quiz yourself during spare
moments. Repetition is the key to retention.
https://www.brainscape.com/packs/bash-2296517?origin=genome
Command Line Practice Games
There are fun command-line games and quizzes designed to help you learn Linux commands in an engaging way. One popular option is “Terminus,” a game that challenges your command-line skills in a game-like environment.Try the links below too
https://gitlab.com/slackermedia/bashcrawl
Interactive Tutorials and Learning Platforms
Take advantage of interactive online tutorials and learning platforms tailored for Linux beginners. Websites like Codeademy and Linux Journey offer hands-on courses that teach you Linux commands in an interactive manner.
Cheat Sheets as Quick References
Cheat sheets are our best friends. Print out or bookmark cheat sheets that list essential Linux commands and their purposes. Having a quick reference at your fingertips can save time and reduce frustration. Rember to use whatis, man and apropos too!
Command | Description |
---|---|
hostnamectl | Get system information including the operating system, kernel, and release version. |
date | Display the current system date and time. |
hostname | Display the hostname of the system. |
ifconfig | Display the IP and MAC address of the system. |
w | Display currently logged-in users in the system. |
free -m | Display free and used memory in the system. |
top | Display all running processes. |
ls | List all files and directories in the current working directory. |
ls -al | List all files and directories, including hidden files, with additional information like permissions, size, and owner. |
cd | Change the directory to the home directory. |
cd .. | Change the directory to one level up. |
cat filename | Display the content of the file. |
cat file1 file2 > file3 | Combine two files named file1 and file2 and store the output in a new file, file3. |
tail filename | Display the last 10 lines of a file. |
head filename | Display the first 10 lines of a file. |
mv oldfile newfile | Rename a file. |
rm filename | Delete a file. |
mkdir dirname | Create a directory. |
rm -rf dirname | Remove a directory. |
history | Print a history list of all commands. |
clear | Clear the terminal. |
shutdown -h now | Shut down the system. |
reboot | Restart the system. |
Networking Commands | Description |
---|---|
ip addr show | Or ifconfig – List all IP addresses and network interfaces. |
ip addr add IP-Address dev eth1 | Add a temporary IP address to interface eth1. |
netstat -pnltu | Display all listening ports. |
whois domainname | Display more information about any domain. |
dig domainname | Display DNS information of any domain. |
host domainname | Perform an IP lookup for a domain. |
dig -x IP-Address | Perform a reverse lookup of an IP address. |
dig -x domainname | Perform a reverse lookup on a domain. |
ping host-ip | Check connectivity between two hosts. |
File Permission Commands | Description |
---|---|
ls -l filename | Check the current permission of any file. |
chmod 777 filename | Assign full (read, write, and execute) permission to everyone. |
chmod -R 777 dirname | Assign full permission to the directory and all sub-directories. |
chmod 766 filename | Assign full permission to the owner, and read and write permission to the group and others. |
chmod -x filename | Remove the execution permission of any file. |
chown username filename | Change the ownership of a file. |
chown user:group filename | Change the owner and group ownership of a file. |
chown -R user:group dirname | Change the owner and group ownership of the directory and all sub-directories. |
User and Group Management Commands | Description |
---|---|
w | Display all login users. |
useradd username | Add a new user account. |
userdel -r username | Delete a user account. |
usermod [option] username | Change the user account information, including group, home directory, shell, expiration date. |
usermod -aG groupname username | Add a user to a specific group. |
groupadd groupname | Create a new group. |
groupdel groupname | Remove a group. |
last | Display information of the last login user. |
id | Display UID and GID of the current user. |
Process Management Commands | Description |
---|---|
ps | Display all active processes. |
`ps -ef | grep processname` |
top | Manage and display all processes in real-time. |
pstree | Display processes in a tree-like diagram. |
lsof | List all files opened by running processes. |
kill pid | Kill a specific process using its process ID. |
killall processname | Kill all processes by name. |
bg | Display stopped or background jobs. |
pidof processname | Get the PID of any process. |
Disk Management Commands | Description |
---|---|
fdisk -l | List all disk partitions. |
fdisk /dev/sda | Create a new partition on the /dev/sda device. |
mkfs.ext4 /dev/sda1 | Format the partition named /dev/sda1. |
fsck.ext4 /dev/sda1 | Check and repair a filesystem for any errors. |
mount /dev/sda1 /mnt | Mount any partition to any directory. |
df -h | Display free space of mounted file systems. |
df -i | Display free inodes on the filesystem. |
du -hs | Display the size of your current directory. |
lsblk | Display information about block devices. |
lsusb -tv | Display all USB devices. |
hdparm -tT /dev/sda | Perform a read speed test on disk /dev/sda. |
badblocks -s /dev/sda | Test for unreadable blocks on disk /dev/sda. |
Package Management Commands | Description |
---|---|
apt-get install packagename | Install the package on Debian-based distributions. |
apt-get remove packagename | Remove a package on Debian-based distributions. |
`dpkg -l | grep -i installed` |
dpkg -i packagename.deb | Install a .deb package. |
apt-get update | Update the repository on Debian-based distributions. |
apt-get upgrade packagename | Upgrade a specific package on Debian-based distributions. |
apt-get autoremove | Remove all unwanted packages on Debian-based distributions. |
yum install packagename | Install the package on RPM-based distributions. |
yum remove packagename | Remove a package on RPM-based distributions. |
yum update | Update all system packages to the latest version on RPM-based distributions. |
yum list --installed | List all installed packages on RPM-based distributions. |
yum list --available | List all available packages on RPM-based distributions. |
Compress and Uncompress Commands | Description |
---|---|
tar -cvf filename.tar filename | Compress a file in the Tar archive. |
tar -xvf filename.tar | Uncompress a Tar file. |
tar -tvf filename.tar | List the content of the Tar file. |
tar -xvf filename.tar file1.txt | Untar a single file from a Tar file. |
tar -rvf filename.tar file2.txt | Add a file to the Tar file. |
zip filename.zip filename | Compress a single file to a zip. |
zip filename.zip file1.txt file2.txt file3.txt | Compress multiple files to a zip. |
zip -u filename.zip file4.txt | Add a file to a zip file. |
zip -d filename.zip file4.txt | Delete a file from a zip file. |
unzip -l filename.zip | Display the content of a zip archive file. |
unzip filename.zip | Unzip a file. |
unzip filename.zip -d /dirname | Unzip a file to a specific directory. |
9. YouTube Tutorials and Video Guides
YouTube is a treasure trove of Linux tutorials and guides. Visual learners can watch experts demonstrate commands, making it easier to understand and remember.
10. Join Linux Communities
Join online Linux communities and forums like Stack Exchange or Reddit’s r/linux4noobs. Engaging in discussions and helping others solve problems is an excellent way to reinforce your understanding of Linux commands.
Conclusion
Learning Linux commands may seem like a challenge at first, but with a combination of mnemonics, visualisations, custom aliases, and interactive resources, you can quickly become proficient. The journey to Linux mastery begins with a single command, and before you know it, you’ll be navigating the command-line interface with confidence and innovation.
So, roll up your sleeves, embrace the penguin-powered world of Linux, and let the command-line adventure begin!