Linux Commands Basics
Beginner Commands
pwd (Print Working Directory): Ever feel lost in your computer's folders? This is your digital GPS. It tells you exactly where you are.
$pwd
ls (List): Shows you all the files and directories in your current location. Use
ls -l
for a detailed view and ls -a
to see hidden files. It's like having x-ray vision for your folders.
$ls -la
cd (Change Directory): Your very own teleporter.
cd my_folder
takes you into a folder, and cd ..
moves you one level up.
$cd documents/project_alpha
*Why did the Linux user break up with the Windows user? He felt too controlled.*
mkdir (Make Directory): The command to build new homes for your files. Less work than building a real house, I promise.
$mkdir project_beta
touch: Creates a new, empty file. Perfect for when you have a brilliant idea but nothing to write it on yet. It's the digital equivalent of finding a clean napkin.
$touch new_ideas.txt
cp (Copy): Copies files. Because the best way to prevent losing your work is to have a clone army of it.
$cp report.txt report_backup.txt
*I've got a great sudo
joke. But I can't tell you unless you're a root user.*
mv (Move): Moves or renames files. It's like a moving company and a renaming service all in one.
$mv draft.txt final.txt
rm (Remove): Deletes files. USE WITH CAUTION! There's no recycle bin here. This command separates the pros from the... well, from the people who just lost all their work.
$rm oops.txt
cat (Concatenate): Displays the content of a file right in your terminal. Great for a quick peek. It's a cat of all trades!
$cat new_ideas.txt
Intermediate Commands
grep (Global Regular Expression Print): Your personal search detective. Finds any line with a specific word or pattern inside a file.
$grep "secret" diary.txt
find: A more powerful detective than
grep
. It can find files based on name, size, modification date, and more. Finds a needle in a digital haystack.
$find . -name "*.txt"
chmod (Change Mode): Lets you change who can read, write, or execute a file. It's like being the bouncer for your files.
$chmod 755 script.sh
*How many programmers does it take to change a light bulb? None, that's a hardware problem.*
sudo (Superuser Do): The magic word. It lets you run commands as the all-powerful root user. It's the "pretty please with a cherry on top" of the command line.
$sudo apt-get update
df (Disk Free): Shows you how much disk space is left. Useful for when your computer starts complaining it's full.
$df -h
du (Disk Usage): Shows how much space a specific file or folder is taking up. Helps you find the digital hoarders on your system.
$du -sh /var/log
*My dog is named "grep". When he gets lost, I can just type find / -name "grep"
*
head & tail: Lets you see the beginning (
head
) or end (tail
) of a file without opening the whole thing. Perfect for checking logs or just being impatient.
$tail -n 20 error.log
diff: Compares two files and shows you exactly what's different. The ultimate "spot the difference" game for developers.
$diff file1.txt file2.txt
Read more commands here: Linux Command Page Index.