0% found this document useful (0 votes)
8 views16 pages

Linux +

Wonderful linux

Uploaded by

yousefmoustafacj
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)
8 views16 pages

Linux +

Wonderful linux

Uploaded by

yousefmoustafacj
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

Linux +

Lecture 4 - Linux commands


🔹 Command:
sudo su or su-root
exit
whoami
ls
pwd
cd
cd ..
cat
clear or ctrl + L
ctrl+c

🧩 How to use:
cd xyz
cat xyz.txt

✅ What I’ve Learned


In this lecture, I learned some Linux terminal commands.

I learned how to switch to the root user using sudo su


I can return to the normal user with exit .
I use whoami to check the current username.
I use ls to list files and folders.
I check my current location with pwd .
I can move into folders with cd and go back with cd .. .
I use cat to view file content.
I clear the terminal using clear or Ctrl + L .
I cancel running actions using Ctrl + C .
Lecture 5 - Linux commands
🔹 Command:
nano
rm
mkdir
rmdir or rm -r
mv
cp
echo

🧩 How to use:
nano :

1. Run the command:


nano xyz.txt
2. Type your content inside the file.
3. To save the file:
Press Ctrl + O → (this writes the content to the file)
Press Enter → (to confirm the filename)
4. To exit nano:
Press Ctrl + X

rm xyz.txt
mkdir xyz
rmdir xyz or rm -r xyz
mv xyz.txt And mv xyz.txt xxx.txt
cp xyz.txt xyz
echo :
write ---> echo "hi" > xyz.txt (Delete old )
append ---> echo "hi" >> xyz.txt (Add to what already written)

✅ What I’ve Learned


I use nano to open and edit text files.
I use rm to delete files.
I use mkdir to create a new folder.
I use rmdir or rm -r to delete folders.
I use mv to move files or rename them.
I use cp to copy files or place them inside a folder.
I use echo to print text or write into a file.

Lecture 6 - Linux commands


🔹 Command:
ifconfig
df -h
free
ps aux
apt
snap
dpkg
ls -lah
chmod
grep
wc

🧩 How to use:
ps aux :
To stop a running process, I can use the kill command followed by the PID of the process
(kill 696).
Download a tool from the internet:

1. apt install xyz


2. snap install xyz
3. dpkg -i xyz.deb ---> command is used to install a .deb package file

ls -lsh :
Accessing the file permissions:
-Execute ---> 1
Execute the file as a program
-Write ---> 2
Writing inside the file
-Read ---> 4
Reading the file
chmod :
chmod 777 xyz
chmod +r xyz
chmod -r xyz
grep :
cat xyz | grep "hi"
wc :
cat xyz | wc

✅ What I’ve Learned


I use ifconfig to check network information like IP addresses.
I use df -h to view hard disk space usage in a human-readable format.
I use free to check memory (RAM) usage.
I use ps aux to see all running processes on the system.
I use apt to install, update, or remove software packages.
I use snap to install and manage snap packages.
I use dpkg to manage .deb packages manually.
I use ls -lah to list files with detailed info including size, permissions, and hidden files.

Lecture 9 - Bash Scripting


🔹 Command:
bash
echo $x
for loop

🧩 How to use:
bash :

1. Create a file with .sh extension.


2. the first line should be: #!/bin/bash (this tells the system to use Bash).
3. Write your commands in the file and save it.
4. bash xyz.sh
echo $x :
a) Use it inside a bash file:
echo $0 :
Print file name
echo $1 :
Print the first word
echo $2 :
Print the second word
or
b) Put it in a variable:
xyz="$0 $1 $2"
echo $xyz
for loop :
Example: for x in {100..150}; do echo $x ; done
The variable name x can be any name or letter (like i , num , value ...).
I can change the range to start and end at any numbers, for example: {1..5} ,
{10..20} , etc.
for x in cat xyz.txt ; do echo $x ; done
This prints each word in the file xyz.txt one by one.
Example: for x in $(cat xyz.txt); do echo $x ; done
This prints each word in the file xyz.txt one by one.

✅ What I’ve Learned


I learned how to write simple scripts using bash .
I learned how to print values or variables using echo $x .
I learned how to use for loop to repeat commands on numbers or file content.

Lecture 10 - Bash Scripting (SED)


🔹 Command:
sed

🧩 How to use:
sed's/x/y/' < xyz.txt
sed's/x/y/ ; s/z/x/' < xyz.txt
sed 's/x/y/ < xyz.txt > yxz.txt'
sed 's/x/y/g' xyz.txt
sed -i 's/x/y/' < xyz.txt
sed'/x/d' xyz.txt
Example
echo "helllo kali" | sed 's/hello/hi/'
echo "helllo kali" | sed 's/hello/hi/ ; s/kali/root/'
Output
hi kali
hi root

✅ What I’ve Learned


I learned how to use sed to search and replace text inside files.
I practiced replacing one word with another, replacing multiple words, saving output to a
new file, replacing all matches using g , editing files directly with -i , and deleting lines
using a pattern.

Lecture 11 - Bash Scripting (user input)


🔹 Command:
XYZ= " -lah "
ls $XYZ

read :
read -p
read -s
read XYZ < /X/X.txt

X= ls -lah
echo "$X"

$(date +%s)

🧩 How to use:
read :
echo "please add your password"
read XYZ
echo "Your password is : $XYZ"

OR

read -p "please add your password: " XYZ


echo $XYZ

read -s :
silent input with
read -sp "please add your password: " XYZ
echo $XYZ

$(date +%s) :
start=$(date +%s)

sleep 5

end $(date +%s)


echo $((end - start))

To measure the speed of the tools


X=(date +%s)
pwd
ifconfig
ls
Z=(date +%s)

echo $((Z - X))

✅ What I’ve Learned


I learned how to pass options to commands using variables like XYZ="-lah" and then run
ls $XYZ .
I learned how to read user input using read , and how to prompt the user inline using read
-p .
I learned how to read passwords silently using read -s or read -sp .
I learned how to read a value directly from a file using read < /path/file.txt .
I learned how to store the output of a command inside a variable using backticks or $(...) ,
like X=$(ls -lah) .
I learned how to use $(date +%s) to get the current timestamp in seconds.
Lecture 12 - Bash scripting (if Condition)
🔹 Command:
if [ ]
then

else

fi

🧩 How to use:
value="10"
if [ $value -eq "10" ]
then

echo "Yes"

else
echo "No"
fi

OR

read -p "please add your Name" NAME

if [ $NAME = "Anas" ]
then

echo "hi Anas"

elif [ $NAME = "Huy" ]


then

echo "hi Huy"

else
echo "you are not admin"
fi

Lecture 13 - Bash Scripting (function)


🔹 Command:
function

return

🧩 How to use:
function :

function X {

echo "hello world"


}
X

return :

function calc {

if [ $# -lt 1 ]
then
echo "the number one"
return 1

else
echo "the number one or more"
return 0
fi
}
calc 5
Lecture 14 - Linux & Bash
🔹 Command:
using Documentation :

man

apropos

whatis

info

File commands :

nl

more

less

tail

head

Create file :

vi, vim

touch

compress and decompress :

zip

unzip

🧩 How to use:
using Documentation :

man ls

apropos ls

whatis ls
info ls

File commands :

nl xyz.txt or nl xyz.txt | grep x

more xyz.txt

less xyz.txt

tail xyz.txt or tail -f 10 xyz.txt

head xyz.txt

Create file :

vi, vim xyz.txt :


Type i to enter Insert mode, then type your content inside the file.

To save the file:


Press Esc → (to exit Insert mode)
Type :w → (this writes/saves the file)
Press Enter

To exit vim:
Press Esc →
Type :q →
Press Enter

To save and exit at the same time:


Press Esc →
Type :wq →
Press Enter

touch xyz.txt

compress and decompress :

zip xyz.zip x.txt y.txt

unzip xyz.zip

Lecture 15 - locate & find grep


🔹 Command:
locate

find

sudo updatedb

🧩 How to use:
locate :

locate xyz.txt
locate /home xyz.txt
locate /home xyz.deb

find :

find / -name xyz.txt


find / -empty
find / -perm 777
find / -type d -name 'xyz'
find / -type f -name 'xyz.txt'
find / -exec drep -l "X" {} \;
find / -size +B

Lecture 16 - Linux Regex


🔹 Command:
http://

\w

[0-9]

\s

\W

\D

\S
.

\?

\!

\.

\$

[0-9]{2}

\s{3}

🧩 How to use:
http:// :
cat xyz.txt | grep -E "http\:\/\/" OR
cat xyz.txt | grep -E "https?\:\/\/"

\w => to match letter or number :


cat xyz.txt | grep -E "\w"

[0-9] => to match only number :

\s => to match spaces :

\W => to match anything except numbers or letters :

\D => to match anything except numbers :

\S => to match anything except spaces :

. => to match anything :

^ => start with => ^x :

$ => end with :

? => match ? :

! => match ! :

. => match . :
$ => match $ :

[0-9]{2} => match 2 digits :

\s{3} => match 3 spaces :

Lecture 17 - Linux User & Groups


🔹 Command:
Essential files for users and groups :

/etc/passwd

/etc/group

/etc/shadow

/etc/gshadow

/home/{username}

/etc/skel => contains default files home for new users

/etc/login.defs

/etc/sudoer

Adding, Deleting user account :

add new user :


useradd -m -s /bin/bash -G sudo john

change the password :


passwd {username}

delete user :
userdel -r john

Lecture 18 - Linux User & Groups


🔹 Command:
modify user :

change the user home directory :


usermod -d /new/directory {user}

change the username of specific user :


usermod -l newusername {user}

change the groups ( remove the last group ) :


usermod -G group1 {user}

add user to new group without deleting last groups :


usermod -aG newgroup {user}

listing user information :

id {username}

to lock user account (Prevent him from login) :


passwd -l {username}

unlock account {permit him to login} :


passwd -u {username}

Managing groups :

add new group with id :

groupadd {groupname}
groupadd {groupname} -g {GID}

delete group :
groupdel {groupname}

rename group name :


groupmod {old_name} -n {new_Group_name}

change the gid of the group :


groupmod -g 2000 {groupname}

Adding a User to a Group :


usermod -aG groupname username

remove user from group :


sudo gpasswd -d username groupname
to know the groups that username in it
groups username

to get more information about group :


getent group groupname

to change the primary group for username :


usermod -g {newgroup} {username}

to put password for the group :


gpasswd {groupname}

Lecture 19 - Shdaow $ passwd


🔹 Command:
cat /etc/passwd | cut -d ":" -f 1 OR cut -d ":" -f 1 /etc/passwd
Both commands display all usernames from the /etc/passwd file.

passwd -e username
to force user to change his password in the first time.

/etc/skel directory (default configuration files for new users)


if you need to add new file added to every new user then
nano /etc/skel/xyz.txt
useradd -m -s /bin/bash -G sudo Anas

Locking an account :

passwd -l username
usermod -s /bin/false username => change shell dir

Unlocak an account :

passwd -u username
usermod -s /bin/sh
usermod -s /bin/bash
usermod -s /bin/zsh

You might also like