Unix / Linux - Quick Guide
Welcome, aspiring programmers! As an experienced computer science teacher, I'm thrilled to guide you through the fascinating world of Unix and Linux. Don't worry if you're new to programming – we'll start from the basics and build our way up. Let's embark on this exciting journey together!
1. What is Unix?
Unix is an operating system that was developed in the 1960s and has since become the foundation for many modern operating systems, including Linux. It's known for its stability, flexibility, and powerful command-line interface.
1.1 Unix Architecture
Unix follows a layered architecture, consisting of:
- The kernel (core of the system)
- The shell (interface between user and kernel)
- Utilities and applications
Think of Unix like a three-layer cake: the kernel is the base, the shell is the frosting, and the utilities are the delicious toppings!
2. Getting Started with Unix/Linux
2.1 The Command Line Interface (CLI)
Unix/Linux systems primarily use a command-line interface. Don't be intimidated – it's like learning a new language, and soon you'll be fluent!
To start, open your terminal. You'll see something like this:
username@hostname:~$
This is your command prompt, waiting for your instructions!
2.2 Basic Commands
Let's start with some simple commands:
Command | Description | Example |
---|---|---|
pwd |
Print Working Directory | pwd |
ls |
List files and directories | ls |
cd |
Change Directory | cd Documents |
mkdir |
Make Directory | mkdir MyFolder |
touch |
Create an empty file | touch myfile.txt |
Let's try them out!
$ pwd
/home/username
$ ls
Documents Downloads Music Pictures
$ mkdir MyProject
$ cd MyProject
$ touch hello.txt
$ ls
hello.txt
Each command does a specific job. pwd
shows where you are, ls
lists what's around you, mkdir
creates a new folder, cd
moves you to a different location, and touch
creates a new file.
3. File Management
3.1 Creating and Editing Files
Let's create a simple text file using the nano
editor:
$ nano hello.txt
This opens the nano editor. Type some text:
Hello, Unix world!
This is my first file.
Press Ctrl+X, then Y, then Enter to save and exit.
3.2 Displaying File Content
To view the content of your file:
$ cat hello.txt
Hello, Unix world!
This is my first file.
The cat
command displays the entire file content.
3.3 Copying, Moving, and Deleting Files
Here's a quick reference table:
Command | Description | Example |
---|---|---|
cp |
Copy files or directories | cp hello.txt hello_copy.txt |
mv |
Move or rename files | mv hello.txt greetings.txt |
rm |
Remove files or directories | rm hello_copy.txt |
Let's try these:
$ cp hello.txt hello_backup.txt
$ ls
hello.txt hello_backup.txt
$ mv hello.txt greetings.txt
$ ls
greetings.txt hello_backup.txt
$ rm hello_backup.txt
$ ls
greetings.txt
Remember, with great power comes great responsibility. Be careful with the rm
command – there's no recycle bin in the command line!
4. Directory Management
4.1 Navigating Directories
We've already seen cd
for changing directories. Here are some navigation tips:
-
cd ..
moves up one directory -
cd ~
takes you to your home directory -
cd /
goes to the root directory
$ pwd
/home/username/MyProject
$ cd ..
$ pwd
/home/username
$ cd ~
$ pwd
/home/username
$ cd /
$ pwd
/
4.2 Creating and Removing Directories
We've seen mkdir
for creating directories. To remove them, use rmdir
:
$ mkdir TestDir
$ ls
TestDir MyProject
$ rmdir TestDir
$ ls
MyProject
Note: rmdir
only works on empty directories. For non-empty directories, you'd use rm -r
, but be very careful with this!
5. File Permissions
Unix/Linux systems have a robust permissions system. Each file and directory has permissions for the owner, group, and others.
5.1 Understanding Permissions
Use ls -l
to see detailed file information, including permissions:
$ ls -l
-rw-rw-r-- 1 username username 35 Jun 15 10:30 greetings.txt
The permissions are represented by -rw-rw-r--
:
- The first character indicates the file type (
-
for regular file,d
for directory) - The next three characters are owner permissions
- The next three are group permissions
- The last three are permissions for others
Each set of three characters represents read (r), write (w), and execute (x) permissions.
5.2 Changing Permissions
Use the chmod
command to change permissions:
$ chmod 644 greetings.txt
$ ls -l greetings.txt
-rw-r--r-- 1 username username 35 Jun 15 10:30 greetings.txt
Here, 644 is an octal representation:
- 6 (110 in binary) means read and write for the owner
- 4 (100 in binary) means read-only for group and others
Conclusion
Congratulations! You've taken your first steps into the world of Unix/Linux. We've covered the basics of navigating the file system, managing files and directories, and understanding permissions. Remember, practice makes perfect – the more you use these commands, the more comfortable you'll become.
In our next lessons, we'll dive deeper into more advanced topics like shell scripting, process management, and network utilities. Until then, keep exploring and don't be afraid to experiment in your Unix/Linux playground!
Credits: Image by storyset