Linux For Beginners
Introduction to Linux
Linux is an operating system similar to the famous Windows OS we are all used to. A computer is made up of Software, Hardware and Peripheral units as we were taught in introductory class to computer science. Operating System is a type of software (Any non-physical component of the computer is referred to as software). The Operating System manages and controls the computer's resources and facilitates the interaction between humans and the computer. The computer is uselss without an operating system.
Why Linux
Linux is free and open source operating system and powers a wide range of devices, from smartphones, laptops, servers and supercomputers. Linux is highly customizable and secure which has made it to keep growing in popularity among developers, programmers, DEVOPs, MLOPs, Cybersecurity and power users globally.
- Open-source
- Secure
- Stable
- Flexible
- Huge Community
- Highly customizable
Linux File System
The computer file system has a tree structure, navigating from a branch, node or leave to another is called walking the tree. You will need to navigate the tree structure to manage and use files and resources stored on the system. The image below shows the Linux file system.
- /home: User-specific files and configurations.
- /etc: System-wide configuration files.
- /var: Variable data like logs.
- /bin and /sbin: Essential and administrative binaries.
Linux Distributions
A.k.a "distros" are customized versions of Linux OS for different end-user or target market. Popular distros include:
- Ubuntu: A very popular user friendly distribution.
- Fedora: Innovative and cutting-edge features
- Debian: Stable software repository
Linux Commands
We split the basic commands into 2 parts: File Navigation and File Manipulation
File Navigation
- ls: List files in or contents of a directory
- cd: Changes the current drectory
- pwd: Prints the current working directory.
File Manipulation
Linux provides powerful commands for file creation, editting and management:
- touch: creates empty files.
- cp: Copy files from source to destination. A copy is retained in source.
- mv: Moves file from source to destination. No copy is retained in source.
Student Practice Exercises
- List the contents of the current directory:
ls
- List contents of current working directory including hidden contents.
ls -a
-
Practise:
- Navigate to your home directory and list all its contents.
- Use
ls -l
to display detailed information about each file in the directory
-
Change directory to a specific location
I. Create a new directory called school
mkdir school
II. Go into the new directory
cd school
III. Navigate to /tmp
directory and back to your home directory
- create nested directories i.e one or more directories inside another directory.
mkdir -p school/classes
- create an empty file.
touch artclass.txt
I. create a file named notes.txt
in the school/classes directory
II. create three files at once: teachers.txt
, students.txt
, subjects.txt
- copy a file
cp notes.txt copy_of_notes.txt
- copy a directory recursively
cp -r school/ school_copy/
- Rename a file
mv old_name.txt new_name.txt
I. move a file to another directory:
mv notes.txt /home/backup/
- Delete a file
rm notes.txt
- Delete a directory and its contents recursively
rm -r classes/
- Remove an empty directory.
rmdir school/
- show command history
history
- run a specific command from history
!5
- print a text
echo "I love linux."
- write text to a file
echo "I mean it, I really love Linux." > love_linux.txt
- read content of a file:
cat students.txt
- Combine files
cat students.txt classes.txt subjects.txt > combined.txt
More Practice
- Navigate to your home directory.
- Create a directory called linux_practice.
- Inside linux_practice, create two subdirectories: data and scripts.
- Create three files inside data: file1.txt, file2.txt, and file3.txt.
- Copy all files from data to scripts.
- Rename file3.txt in scripts to file3_backup.txt.
- Delete the data directory along with its contents.
- View your command history to confirm all the steps you performed.