0% found this document useful (0 votes)
17 views5 pages

Linux Fundamental

Uploaded by

magabiro26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Linux Fundamental

Uploaded by

magabiro26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Directory Overview

Directory Description
/ The root directory. All files and directories in Linux are located under this
directory.
/bin Essential binary executables for all users (e.g., ls, cat, cp).
/boot Files required to boot the system (e.g., kernel, GRUB configuration).
/dev Device files (e.g., /dev/sda1 for a hard drive, /dev/null).
/etc Configuration files for system-wide settings (e.g., network, users,
services).
/home User-specific directories for personal files (e.g., /home/username).
/lib Essential libraries required by binaries in /bin and /sbin.
/media Temporary mount points for removable devices like USB drives.
/mnt Temporary mount point for manually mounting file systems.
/opt Optional software and third-party applications.
/proc Virtual directory containing system and process information (e.g., CPU,
memory stats).
/root The home directory for the root user (administrator).
/run Temporary runtime data (e.g., process IDs, sockets).
/sbin System administration binaries (e.g., fsck, reboot, ifconfig).
/srv Data for services provided by the system (e.g., web server files).
/sys Virtual directory for system hardware information.
/tmp Temporary files, often cleaned on reboot.
/usr User applications and utilities (e.g., /usr/bin, /usr/lib).
/var Variable files like logs, cache, and spool directories

Interacting with the file system;;


Navigating Directories:

Use cd to change directories.


pwd prints the current working directory.
Combine with ls to list files and directories.

Managing Files and Directories:


Create files with touch or echo.
echo "Text" > file.txt
echo "More text" >> file.txt
Create directories with mkdir.
Delete files using rm and directories with rm -r or rmdir

Reading and Modifying Files:


cat displays the content of a file.
echo or >> appends data to a file.
nano or vi are editors for modifying file content.

Advanced Interactions:
Use find and grep for locating files and content, respectively.
Combine with wildcards (*, ?) for more dynamic operations.
Manipulate permissions with chmod and ownership with chown
Searching through files;;
find /path/to/search -name "filename"
-type f
-type d
find / -type f -name "*flag*" 2>/dev/null

searching withing files;;


grep "search-term" file.txt
-i case insensetive
-r recursive search through directories
grep -r "*password*" / 2>/dev/null

Introduction to shell operator


Use || to execute the second command if the first fails
mkdir /protected_dir || echo "Failed to create directory"

Background execution
long_task.sh &

Command substitution
use $()
echo "Today is $(date)"

User Management Commands;;


Add a new user:
sudo useradd username
Set or change user passwd
sudo passwd username
user delete
sudo userdel username
sudo userdel -r username // This deletes upto users home directory
Group management;;
Add a new group
sudo groupadd groupname
adding a user to a group
sudo usermod -aG groupname username
Listing user groups
groups username

Viewing and Modifying User Information:

View user account information:


id username

Modify user details:


sudo usermod -l newname oldname

Lock or unlock a user account:


sudo usermod -L username # Lock
sudo usermod -U username # Unlock

Listing and Monitoring Users:


View currently logged-in users:
who

See active user sessions:


w

Check last login information:


last

Finding Files Based on Permissions


Files with misconfigured or weak permissions are a common source of security
vulnerabilities. Use these commands to find files with specific permissions:

Find World-Writable Files:


find / -type f -perm -o+w 2>/dev/null
o stands for "others" (users who are not the owner or part of the
file's group).
+w means the file has write permission.

Find Files Owned by a Specific User:


find / -user username 2>/dev/null

Find Files with SUID or SGID Bits Set:


SUID (Set User ID) files:
find / -type f -perm /4000 2>/dev/null

SGID (Set Group ID) files:


find / -type f -perm /2000 2>/dev/null

Find Files Not Owned by Any User:


find / -nouser 2>/dev/null

Find Files with Specific Permissions:


Find files with 755 permissions:
find / -type f -perm 755 2>/dev/null

Other Useful Commands


Here are additional commands that are essential for system management,
troubleshooting, and automation:

System Information:
Display system information:

uname -a

Show disk usage:

df -h

Show memory usage:

free -h

Process Management:

List running processes:

ps aux
Find a specific process:

ps aux | grep processname

Kill a process by ID:

kill -9 PID

Networking:

Display active network connections:

netstat -tuln

Check connectivity:

ping -c 4 hostname

Display network interfaces:

ip addr

Archiving and Compression:

Create a tar archive:

tar -cvf archive.tar file1 file2

Extract a tar archive:

tar -xvf archive.tar

Compress with gzip:

gzip file

Decompress a gzip file:

gunzip file.gz

Package Management:

Install a package:

sudo apt install package_name # Debian-based systems

Remove a package:

sudo apt remove package_name

Update package lists:

sudo apt update

Upgrade installed packages:

sudo apt upgrade


File Permissions:

Change file permissions:

chmod 644 file

Change file ownership:

chown user:group file

File Content Operations:

View a file in pages:

less file

View the first or last lines of a file:

head file
tail file

TRYHACKME ROOMS;;
Linux fundamentals 1 and 2
https://overthewire.org

You might also like