0% found this document useful (0 votes)
5 views12 pages

Linux GPT 2

This document is an updated summary of Linux commands and topics for HadyHashim, focusing on file system navigation, file management, permissions, package installation, user/group management, process management, services, SSH, and networking. It includes detailed command options and practical examples tailored for a beginner using Ubuntu. The guide aims to provide a comprehensive understanding of essential Linux commands and their applications.

Uploaded by

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

Linux GPT 2

This document is an updated summary of Linux commands and topics for HadyHashim, focusing on file system navigation, file management, permissions, package installation, user/group management, process management, services, SSH, and networking. It includes detailed command options and practical examples tailored for a beginner using Ubuntu. The guide aims to provide a comprehensive understanding of essential Linux commands and their applications.

Uploaded by

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

Linux Commands Summary for

HadyHashim (Updated)
Grok 3, xAI
May 16, 2025

Abstract
This updated document summarizes all Linux commands and topics discussed
with HadyHashim, covering file system navigation, file management, permissions,
package installation, user/group management, process management, services, SSH,
networking, file systems, and server analysis. It includes detailed explanations
of command options (e.g., -i, -R, -aG) and solutions to specific questions (e.g.,
permissions on /media/hadyhashim, copying files, .deb installation, and usermod
-aG).

Introduction
This guide is tailored for HadyHashim, a beginner learning Linux on Ubuntu. It covers
all discussed commands and concepts, with practical examples tested in the context of
the user hadyhashim. This version includes new topics (process management, services,
SSH, networking, file systems, server analysis) and detailed explanations of command
options.

1 Linux File System Hierarchy


The Linux file system is a tree starting at /. Key directories:

• /home/hadyhashim: User’s home directory.

• /etc: System configuration files.

• /bin, /usr/bin: Executable programs (e.g., ls, cp).

• /tmp: Temporary files.

• /media: External drives (e.g., /media/hadyhashim/New_Volume_2).

Paths:

• Absolute: Starts from / (e.g., /home/hadyhashim/test.txt).

• Relative: Relative to current directory (e.g., test.txt).

1
2 Navigation and File Management Commands
• pwd: Prints current directory.
pwd # Output : /home/ hadyhashim

• cd: Changes directory.


cd Documents # Go to /home/ hadyhashim / Documents
cd .. # Go up one level
cd /tmp # Go to /tmp
cd ~ # Go to /home/ hadyhashim

• ls: Lists files/directories.

– -l: Detailed list (permissions, owner, size).


– -a: Show hidden files (e.g., .bashrc).
– -d: List directory itself, not contents.

ls # List files
ls -l # Detailed list
ls -a # Show hidden files
ls -la # Combine detailed and hidden
ls -ld . # Show current directory details

• touch: Creates an empty file.


touch test.txt # Create test.txt

• mkdir: Creates a directory.


mkdir my_folder # Create my_folder

• cp: Copies files/directories.

– -r: Recursive (for directories).

cp test.txt my_folder / # Copy test.txt to


my_folder
cp test.txt .. # Copy to parent directory
cp test.txt /tmp # Copy to /tmp
cp -r my_folder .. # Copy directory
recursively

• mv: Moves or renames files/directories.


mv test.txt new_test .txt # Rename
mv new_test .txt my_folder / # Move to my_folder

• rm: Deletes files/directories.

2
– -r: Recursive (for directories).
– -f: Force deletion without prompt.

rm test.txt # Delete file


rm -r my_folder # Delete directory recursively
rm -rf my_folder # Force delete directory

• ln: Creates links.

– -s: Symbolic link.

ln -s my_folder /test.txt link_to_test # Create symbolic


link

• tree: Displays directory tree.

– -L: Limit depth (e.g., -L 2 for depth 2).

tree # Show full tree


tree -L 2 # Limit to depth 2
tree Documents -L 3 # Limit to depth 3 in Documents

Install: sudo apt install tree

3 Searching with grep


grep searches for text in files or command outputs.
• Basic search:
grep "Linux " test.txt # Find " Linux " in test.txt

• Options:

– -i: Ignore case (e.g., Linux matches linux).


– -r: Recursive search in directory.
– -v: Show lines not matching.
– -n: Show line numbers.
– -c: Count matching lines.
– -l: Show only filenames with matches.

grep -i " linux " test.txt # Case - insensitive


grep -r " Linux " . # Recursive in current
directory
grep -v " Linux " test.txt # Non - matching lines
grep -n " Linux " test.txt # Show line numbers
grep -c " Linux " test.txt # Count matches
grep -l " Linux " *. txt # Show matching files

3
• Example:
echo -e " Ubuntu \ nDebian \ nArch " > sample .txt
grep -n " Ubuntu " sample .txt # Output : 1: Ubuntu
grep -c " Ubuntu " sample .txt # Output : 1
grep -v " Ubuntu " sample .txt # Output : Debian , Arch

4 Package Management
• apt: Manages packages on Ubuntu.

– update: Updates package list.


– install: Installs a package.
– remove: Removes a package.
– search: Searches for packages.
– -f: Fixes broken dependencies.

sudo apt update # Update package list


sudo apt install htop # Install htop
sudo apt remove htop # Remove htop
apt search htop # Search for htop
sudo apt install -f # Fix dependencies

• curl: Downloads files from the internet.

– -O: Saves file with original name.

curl -O https :// example .com/file.txt # Download file.


txt
curl -O https :// dl. google .com/ linux / direct /google -chrome
- stable_current_amd64 .deb

• wget: Alternative to curl for downloading.


wget https :// dl. google .com/ linux / direct /google -chrome -
stable_current_amd64 .deb

• Installing .deb files:


cd ~/ Downloads
sudo apt install ./ example .deb # Install .deb file
sudo apt install -f # Fix dependencies

Alternative with dpkg:

– -i: Install package.

sudo dpkg -i example .deb


sudo apt install -f

4
Example (Google Chrome):
curl -O https :// dl. google .com/ linux / direct /google -chrome
- stable_current_amd64 .deb
sudo apt install ./ google -chrome - stable_current_amd64 .
deb
google - chrome

5 Permissions Management
• chmod: Changes file/directory permissions.

– -R: Recursive (applies to directories and contents).

chmod u+rwx test.txt # Give owner full permissions


chmod 755 test.txt # Owner : rwx , others : r-x
chmod -R u+w / media / hadyhashim # Add write recursively

• chown: Changes file/directory owner or group.

– -R: Recursive.

sudo chown hadyhashim : hadyhashim test.txt # Change


owner and group
sudo chown -R hadyhashim : hadyhashim / media / hadyhashim #
Recursive

• setfacl: Sets Access Control Lists (ACL).

– -R: Recursive.
– -m: Modify ACL (e.g., u:hadyhashim:rwx).
– -d: Set default ACL for new files/directories.
– -x: Remove ACL entry.

sudo setfacl -R -m u: hadyhashim :rwx / media / hadyhashim #


Give hadyhashim full access
sudo setfacl -R -d -m u: hadyhashim :rwx / media / hadyhashim
# Default ACL
sudo setfacl -x u: hadyhashim / media / hadyhashim # Remove
hadyhashim 's ACL

• getfacl: Displays ACL.


getfacl / media / hadyhashim
# Output example :
# user :: rwx
# user: hadyhashim :rwx
# group ::r-x
# other ::r-x

5
Example (Fixing permissions on /media/hadyhashim):
ls -ld /media / hadyhashim # Check permissions (e.g., drwxr -xr -x root
root)
sudo setfacl -R -m u: hadyhashim :rwx / media / hadyhashim
touch / media/ hadyhashim / test_file .txt # Test write access

6 User and Group Management


• adduser: Adds a new user with interactive setup.
sudo adduser testuser # Create testuser with password
and home directory

• groupadd: Creates a new group.


sudo groupadd testgroup

• usermod: Modifies user settings.

– -a: Append (add to group without removing existing groups).


– -G: Specify secondary groups.

sudo usermod -aG testgroup hadyhashim # Add hadyhashim


to testgroup

• getent: Retrieves system database entries.


getent passwd hadyhashim # Show hadyhashim details
getent group sudo # Show sudo group members

• groups: Lists user’s groups.


groups hadyhashim # Output : hadyhashim sudo users
testgroup

7 System and Command Utilities


• man: Displays manual pages.
man ls # Show ls manual
man grep # Show grep manual

• su: Switches to another user.

– -: Start a login shell.

su - # Switch to root ( requires root password )


su testuser # Switch to testuser

6
• sudo: Executes commands with root privileges.
sudo apt update # Run apt update as root
sudo ls /root # List root directory

8 Process Management
• ps: Lists running processes.

– aux: Show all processes (user, PID, CPU, memory).

ps aux # List all processes


ps aux | grep firefox # Find firefox processes

• top: Real-time process monitoring.


top # Press q to quit

• htop: Enhanced top (requires installation).


sudo apt install htop
htop # Press q to quit

• kill: Terminates a process by PID.

– -9: Force kill (SIGKILL).

kill 1234 # Terminate process with PID 1234


kill -9 1234 # Force terminate

• killall: Terminates processes by name.


killall firefox # Terminate all firefox processes

Example:
ps aux | grep bash # Find bash processes
htop # Monitor processes
killall gedit # Terminate gedit

9 Service and Daemon Control


• systemctl: Manages system services.

– status: Show service status.


– start: Start service.
– stop: Stop service.
– enable: Enable service at boot.

7
– list-units: List active units.

systemctl status ssh # Check SSH service


sudo systemctl start ssh # Start SSH
sudo systemctl stop ssh # Stop SSH
sudo systemctl enable ssh # Enable at boot
systemctl list - units --type= service # List services

• service: Alternative for service management.


sudo service ssh status # Check SSH status

10 SSH Configuration and Security


• Install SSH server:
sudo apt install openssh - server

• systemctl for SSH:


systemctl status ssh # Check SSH service
sudo systemctl start ssh # Start SSH

• Configure /etc/ssh/sshd_config:
sudo nano /etc/ssh/ sshd_config
# Change port (e.g., Port 2222)
# Disable root login ( PermitRootLogin no)
sudo systemctl restart ssh # Apply changes

• Firewall with ufw:

– allow: Allow specific port.


– enable: Enable firewall.

sudo apt install ufw


sudo ufw allow 2222/ tcp
sudo ufw enable
ufw status

• Test SSH:
ssh hadyhashim@localhost -p 2222

8
11 Network Management
• ip: Displays network information.

– a: Show IP addresses.
– r: Show routing table.

ip a # Show IP addresses
ip r # Show routing

• nmcli: Manages NetworkManager.

– device status: Show device status.


– con show: Show connections.

nmcli device status # Show devices


nmcli con show # Show connections

• ping: Tests connectivity.

– -c: Limit number of pings.

ping -c 4 google .com # Ping 4 times


ping -c 4 8.8.8.8 # Ping Google 's DNS

• netstat: Shows network statistics (requires net-tools).

– -tuln: Show listening TCP/UDP ports.

sudo apt install net - tools


netstat -tuln # Show open ports

12 File System Access


• df: Shows disk usage.

– -h: Human-readable format (e.g., GB).

df -h # Show disk usage

• du: Shows directory/file sizes.

– -h: Human-readable.
– -s: Summarize total size.

du -h /home/ hadyhashim # Show sizes


du -sh /home/ hadyhashim # Show total size

9
• fdisk: Manages disk partitions (requires sudo).
sudo fdisk -l # List partitions

• mount: Mounts file systems.

– -o: Specify options (e.g., rw,uid=1000).


– -a: Mount all in /etc/fstab.

sudo mount -o rw ,uid =1000 , gid =1000 /dev/sda3 / media /


hadyhashim / New_Volume_2
sudo mount -a # Mount all from /etc/ fstab

13 Mount and /etc/fstab Configuration


Context: HadyHashim uses a manual mount command for an external HDD:
sudo mount -o rw ,uid =1000 , gid =1000 /dev/sda3 / media / hadyhashim /
New_Volume_2

This gives hadyhashim control over New_Volume_2, but /media/hadyhashim remains


owned by root, causing permission issues.
Solution with /etc/fstab:

0. Find the UUID of /dev/sda3:


lsblk -f
# Example output : UUID =1234 - ABCD for /dev/sda3

0. Backup /etc/fstab:
sudo cp /etc/ fstab /etc/ fstab .bak

0. Edit /etc/fstab:
sudo nano /etc/ fstab

Add:
UUID =1234 - ABCD / media / hadyhashim / New_Volume_2 ext4 rw ,
uid =1000 , gid =1000 0 2

(Replace ext4 with ntfs if the filesystem is NTFS.)

0. Test the configuration:


sudo mount -a

0. Reboot and verify:


ls /media / hadyhashim

10
14 Server Analysis and Support
• lscpu: Shows CPU information.
lscpu # Show CPU details

• free: Shows memory usage.

– -h: Human-readable.

free -h # Show memory usage

• journalctl: Shows system logs.

– -u: Filter by service (e.g., ssh).


– -b: Show logs since last boot.

journalctl -u ssh # Show SSH logs


journalctl -b # Show logs since boot

• Getting Support:

– Check man pages: man command.


– Search Ubuntu forums: https://askubuntu.com.
– Use --help: command --help.

15 Questions and Issues Raised


0. Understanding Linux File System Hierarchy:

• Asked for explanation of the file system and file specification.


• Covered: /home, /etc, /bin, absolute vs. relative paths.

0. Basic File Commands:

• Requested commands for creating, copying, moving, deleting, renaming, and


linking.
• Covered: touch, mkdir, cp, mv, rm, ln.

0. Listing Directories:

• Asked for ls and tree with depth control.


• Covered: ls -l, ls -a, tree -L 2.

0. Searching with grep:

• Requested details on grep.


• Covered: grep -i, -r, -v, -n, -c, -l.

11
0. Package Installation:

• Asked about installing programs and .deb files, and apt, curl.
• Covered: apt update, apt install, curl -O, wget, apt install ./example.deb.

0. Permissions on /media/hadyhashim:

• Faced ”Permission denied” when creating directories.


• Wanted hadyhashim and root to have full control without changing ownership
or giving access to others.
• Solution: setfacl -R -m u:hadyhashim:rwx /media/hadyhashim.

0. Checking hadyhashim Permissions:

• Asked to verify permissions.


• Covered: id hadyhashim, ls -ld, getfacl.

0. Copying Files to Parent Directories:

• Asked how to copy a file to a parent directory (one or two levels up).
• Covered: cp file.txt .., cp file.txt ../...

0. Mount and /etc/fstab:

• Noted manual mount command and interest in /etc/fstab.


• Explained automating mounting with /etc/fstab using UUID.

0. Additional Commands:

• Requested details on getfacl, getent, grep, man, user/group management,


chown, su, and assumed sudo for ”consultants/control”.
• Covered all with options (e.g., usermod -aG).

0. usermod -aG Details:

• Asked for explanation of -aG in usermod.


• Covered: -a (append to groups), -G (specify secondary groups).

16 Conclusion
This updated summary covers all commands, topics, and questions discussed with Hady-
Hashim, including detailed explanations of command options. For further learning, ex-
plore shell scripting or advanced networking. To automate HDD mounting, edit /etc/fstab
as described.

12

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy