Linux Basics for Beginners: Essential Commands and Examples
1. User Management
Managing users is crucial in any Linux system, whether for security or resource allocation.
Create a User
Use the useradd
command to create a new user.
sudo useradd newuser
sudo passwd newuser
Delete a User
Remove a user and their home directory with:
sudo userdel -r newuser
2. Group Management
Groups allow better access control and management of multiple users.
Create a Group
Use the groupadd
command to create a new group.
sudo groupadd developers
Delete a Group
Remove a group using:
sudo groupdel developers
Add a User to a Group
sudo usermod -a developers newuser
3. File and Directory Management
Files and directories are the building blocks of Linux. Knowing how to create and manage them is essential.
Create a File
Use touch
to create a blank file:
touch file.txt
Create a Directory
Create a new directory using mkdir
:
mkdir my_directory
Delete a File
Remove a file with:
rm file.txt
Delete a Directory
Use rmdir
to remove an empty directory or rm -r
for directories with contents:
rmdir my_directory
rm -r my_directory
4. Searching with grep
and awk
Using grep
grep
searches for patterns in files:
grep "pattern" file.txt
Example: Find all lines containing "error" in a log file:
grep "error" /var/log/syslog
Using awk
awk
is a text-processing tool:
awk '/pattern/ { print $0 }' file.txt
Example: Print the second column of a file:
awk '{ print $2 }' file.txt
5. File Permissions Management
File permissions determine who can read, write, or execute a file.
View File Permissions
Use ls -l
to see permissions:
ls -l file.txt
Change Permissions
Use chmod
to modify permissions:
chmod 755 file.txt
Change Ownership
Change the owner or group of a file:
sudo chown user:group file.txt
6. SSH and SCP for Remote Connections
SSH (Secure Shell)
SSH lets you connect securely to a remote server:
ssh -i "example.pem" user@remote_server_ip
SCP (Secure Copy)
Copy files securely between local and remote systems:
scp -i "example.pem" file.txt user@remote_server_ip:/path/to/destination
Sample Workflow
Here’s a sample use case combining these commands:
Create a user and assign them to a group:
sudo useradd john sudo passwd john sudo groupadd engineers sudo usermod -a engineers john
Create a file and set permissions:
touch project.txt chmod 644 project.txt sudo chown john:engineers project.txt
Search a file for errors using
grep
:grep "error" /var/log/syslog
Transfer the file to a remote server:
scp project.txt john@192.168.1.100:/home/john/
Thank you for reading :)
Ramya R
Subscribe to my newsletter
Read articles from Ramya R directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ramya R
Ramya R
Hello, I'm Ramya! 👩💻 I'm a passionate tech enthusiast on a journey to build a thriving career in Cloud Computing and DevOps. 🌩️⚙️ I strongly believe in learning through mistakes and growing together as a community. 🌱 By documenting my tech journey, I aim to track my personal and professional growth while inspiring others to embrace their learning paths. Let’s connect, share, and grow in this ever-evolving world of technology! 🚀