Navigating the Linux terminal can seem like traversing a labyrinth for beginners. But, fear not! As an experienced Linux user and a Raspberry Pi enthusiast, I’ve spent countless hours tinkering with commands, some of which have become my steadfast allies in the digital realm.
Today, I’ll share 50 Linux commands that will transform you from a novice to a proficient user, especially on the delightful little powerhouse known as the Raspberry Pi.
50 Essential Linux Commands for Beginners
Navigating the file system
pwd
(Print Working Directory): Shows your current directory. Simple yet indispensable.bash$ pwd /home/pi
ls
(List): Displays files and directories in your current directory. Spice it up with-l
for detailed listings,-a
to include hidden files, and-h
for human-readable sizes.bash$ ls -lah total 28K drwxr-xr-x 2 pi pi 4.0K Jan 1 10:00 . drwxr-xr-x 3 pi pi 4.0K Dec 31 09:30 .. -rw-r--r-- 1 pi pi 220 Feb 25 2020 .bash_logout -rw-r--r-- 1 pi pi 3.7K Feb 25 2020 .bashrc
cd
(Change Directory): Move around the file system like a pro.cd ..
takes you one level up, whilecd
brings you back home.bash$ cd /var/log $ pwd /var/log
mkdir
(Make Directory): Create new directories to keep your projects organized.bash$ mkdir projects
rmdir
(Remove Directory): Deletes empty directories. I rarely use this asrm -r
is my go-to for stubborn non-empty ones.bash$ rmdir unused_folder
touch
: Create a new file or update the timestamp of an existing one. My lazy self loves it for quickly creating files.bash$ touch newfile.txt
rm
(Remove): Deletes files or directories. Use with caution;rm -rf
is powerful but can be your worst nightmare if misused.bash$ rm oldfile.txt
cp
(Copy): Duplicate files or directories. The-r
option is a lifesaver for copying directories.bash$ cp source.txt destination.txt
mv
(Move): Move or rename files. I often misuse it to quickly rename files.bash$ mv oldname.txt newname.txt
cat
(Concatenate): Display file contents. I find it less useful for long files; that’s whereless
ormore
comes in handy.bash$ cat file.txt Hello, Raspberry Pi!
File inspection
less
: View content of a file one page at a time. My go-to for reading long log files.bash$ less /var/log/syslog
head
: Show the first few lines of a file. Perfect for getting a quick peek.bash$ head -n 5 largefile.txt
tail
: Opposite ofhead
, it shows the last few lines. Usetail -f
to live-watch files like logs.bash$ tail -n 5 largefile.txt
grep
(Global Regular Expression Print): Search within files. It’s like a treasure hunt for text.bash$ grep "error" /var/log/syslog
find
: Locate files and directories. It’s a bit complex but incredibly powerful once mastered.bash$ find / -name "python*"
diff
: Compare file contents. I don’t use it much, but it’s a godsend for finding subtle differences.bash$ diff file1.txt file2.txt
file
: Determine file type. Handy for mysterious files without extensions.bash$ file mysteryfile
System monitoring and management
top
: Display active processes. It’s mesmerizing to watch but can be overwhelming.bash$ top
ps
(Process Status): List running processes. Useps aux
for a comprehensive list.bash$ ps aux
df
(Disk Free): Show available disk space. Use-h
to make sense of the numbers.bash$ df -h
du
(Disk Usage): Check the size of directory contents. Great for finding space hogs.bash$ du -sh /home/pi
free
: Display memory usage. Simple yet crucial for monitoring.bash$ free -h
kill
: Terminate processes. Use with care; it’s like flipping the off switch on a process.bash$ kill -9 1234
htop
: An interactive process viewer. It’stop
on steroids and much more user-friendly.uptime
: Show how long the system has been running. A quick way to check system stability.bash$ uptime
Networking commands
ping
: Check the connection to a server. It’s my first step in troubleshooting network issues.bash$ ping google.com
ifconfig
/ip addr
: Display network interfaces and IP addresses. I preferip addr
for its modern touch.bash$ ip addr
netstat
: Show network connections, routing tables, and interface statistics. A bit old-school but useful.bash$ netstat -tuln
wget
: Download files from the web. It’s like a command-line web browser.bash$ wget http://example.com/file.zip
curl
: Interact with URLs. More versatile thanwget
but with a steeper learning curve.bash$ curl -O http://example.com/file.zip
File permissions and ownership
chmod
(Change Mode): Modify file or directory permissions. Essential for managing access rights.bash$ chmod 755 script.sh
chown
(Change Owner): Change the owner and group of a file. Usesudo
to wield this power.bash$ sudo chown pi:pi file.txt
umask
: Set the default creation permissions for new files. Rarely used, but good to know.bash$ umask 022
Package management (Debian/Raspberry Pi OS)
apt-get update
: Update the list of available packages. Always do this before installing new software.bash$ sudo apt-get update
apt-get upgrade
: Upgrade all installed packages to their latest versions.bash$ sudo apt-get upgrade
apt-get install
: Install new software packages. Where the magic of Linux really happens.bash$ sudo apt-get install nginx
dpkg
: Debian package manager. Usedpkg -l
to list installed packages.bash$ dpkg -l | grep nginx
apt-get remove
: Remove installed packages. Don’t forget aboutpurge
to remove config files as well.bash$ sudo apt-get remove nginx
Archiving and compression
tar
: Archive files. The-czvf
and-xzvf
flags are my go-to for compressing and decompressing.bash$ tar -czvf archive.tar.gz /path/to/directory
gzip
/gunzip
: Compress or decompress files. I usegzip
for quick compression tasks.bash$ gzip file.txt
Text editing
nano
: A beginner-friendly text editor. It’s my first recommendation for newcomers.bash$ nano file.txt
vi
/vim
: Advanced text editors.vim
has a steep learning curve but is incredibly powerful once mastered.
Miscellaneous commands
echo
: Display a line of text. Great for scripting and simple output.bash$ echo "Hello, world!"
alias
: Create shortcuts for commands. I havell
aliased tols -lah
for convenience.bash$ alias ll='ls -lah'
history
: Display your command history. A lifesaver when you forget that complex command you just typed.bash$ history
which
: Locate a command. Shows the path to the binary executed.bash$ which python3
man
(Manual): Display the manual pages for a command. The first place to look when in doubt.bash$ man ls
ssh
(Secure Shell): Log into a remote machine. Essential for managing Raspberry Pis headlessly.bash$ ssh pi@raspberrypi.local
scp
(Secure Copy): Copy files over the network. Works likecp
but for remote systems.bash$ scp file.txt pi@raspberrypi.local:/home/pi/
cron
: Schedule commands to run at specific times. It’s like setting an alarm clock for your scripts.bash$ crontab -e
Wrapping up
Embarking on your Linux journey with a Raspberry Pi is like unlocking a treasure chest of learning opportunities. While some commands, like rm -rf
, can unleash chaos if misused, others, like ls
and cd
, will become your daily bread and butter. My personal favorites? grep
for its sheer power in searching and htop
for its visually appealing way of displaying system processes. I encourage you to play around with these commands, explore their options, and discover your own favorites. Remember, mastery comes with practice, and with these 50 commands, you’re well on your way to becoming a Linux maestro on your Raspberry Pi. Happy tinkering!