Admas University
Computer Science Department
Network and System Administration
Lab session
Focus on basic Linuxcommands
By: Shewakena
G.
Outline:
Material
focus on essential Linux
commands:
User Account Management
Creating and Accessing Files and
Folders
Process Management
Memory Management
User Account Management in Linux
Creating a New User:
sudo useradd username e.g sudo useradd Abel
Set a password for the new user:
Sudo passwd Abel
Displaying current account:
who
users
Displaying all system user Acc:
compgen –u
Lock a user account:
sudo usermod -L username
Unlock a user account:
sudo usermod -U username
Change the user ID (UID):
sudo usermod -u 1001 username
Delete a user account:
sudo userdel username
Creating and Accessing Files and Folders
Creating Folders (Directories)
Create a new folder:
mkdir foldername e.g mkdir Abc
Create nested directories (parent + child
folders together):
mkdir -p parentfolder/childfolder e.g mkdir –p admas/cs
Displaying created folders:
Ls or ls -R
To diplay nested directories:
First install tree using: sudo apt install tree or sudo snap
install tree
tree
Con…
Creating Files:
Create an empty file
Touch filename.txt e.g touch labsession.txt
Create a file and add content immediately:
echo "Hello World" > labsession1.txt
Create a file inside an existing folder:
Touch foldername/filename.txt e.g touch
Admas/file1.txt
Create a file and add content immediately to
existing folder:
echo "Hello World" > admas/file2.txt
Con…
Accessing Files and Folders
View the contents of a file:
Cat filename.txt e.g labsession1.txt
View files page by page:
less filename.txt or
more filename.txt
List files and folders in the current directory:
Ls
List with more details: ls –l
Navigate into a folder:
cd foldername e.g cd admas , cd cs
Go back to the previous directory:
cd ..
Go directly to your home directory:
cd ~
View current working directory:
pwd
Con…
Other Useful File/Folder Commands
Copy a file:
cp sourcefile.txt destinationfile.txt e.g cp labssesion.txt
Abc/labssesion.txt
Copy a folder and its contents:
cp -r sourcefolder/ destinationfolder/
Move (rename) a file:
mv oldname.txt newname.txt e.g mv Alex Abc
Move a file into another folder:
mv filename.txt foldername/
Delete a file:
rm filename.txt
Delete an empty folder:
rmdir foldername
Delete a folder with contents:
rm -r foldername
Mounting and Unmounting in
Linux
Mounting: means attaching a filesystem (like a USB
drive, CD, hard disk partition, etc.) to a folder (called a
mount point) so you can access its files.
Unmounting: is detaching it safely. Reverse of mounting.
Mount a USB drive:
Step 1: Find the device name:
sudo fdisk –l
Step 2: Create a mount point
sudo mkdir /mnt/usb
Mount it:
sudo mount /dev/sdb1 /mnt/usb //Now you can access your USB files at
/mnt/usb.
Unmount a device
Unmount the USB
sudo umount /mnt/usb or sudo umount /dev/sdb1 // now, Safely detaches the
filesystem.
Process Management
Monitoring and controlling processes ensures
system stability and performance.
View Running Processes:
ps aux //Displays detailed information about all running
processes.
Real-Time Process Monitoring:
Top //Provides a dynamic, real-time view of running processes.
Terminate a Process by PID:
kill PID //Sends a signal to terminate the process with the specified
PID.
Terminate Processes by Name:
killall process_name //Terminates all processes matching the given
name.
Change Process Priority:
renice -n 10 -p PID //Adjusts the priority of a running process.
Memory Management
Monitoring memory usage helps in optimizing
system performance.
Display Memory Usage:
free –h //Shows total, used, and free memory in a human-
readable format.
Virtual Memory Statistics:
vmstat 1 //Reports information about processes, memory, paging, block IO,
traps, and CPU activity.
Detailed Memory Info:
cat /proc/meminfo //Displays detailed information about system
memory.
Interactive Process Viewer (if installed):
Htop //An interactive process viewer with a user-friendly interface.
First install htop. Using
Sudo snap install htop then install htop app using
Sudo apt install htop
END