- Selesai Lab 20
- Pergi ke EC2 Console
- Select instance anda
- Click Connect > Session Manager > Connect
- Switch to bash:
bash
touch - Cipta fail atau update timestamp fail
cd /var/www/site1/htmlls -l index.htmlsudo touch index.htmlls -l index.htmlecho - output konten kepada terminal
echo "Hello DevOps"Redirector > - Tulis konten dalam fail
cd ~
echo "This is line 1" > test.txtcat test.txtecho "This is NEW line 1" > test.txtcat test.txtNota: > akan buang konten lama dan tulis konten baru.
Redirector >> - Tambah konten kepada file
echo "This is line 2" >> test.txt
echo "This is line 3" >> test.txtcat test.txtNota: >> akan tambah konten baru tanpa buang konten sebelumnya.
cd ~
echo "red" >> colors.txt
echo "green" >> colors.txt
echo "blue" >> colors.txtcat - concatenate konten
cat colors.txtgrep - Cari teks dalam fail
grep "red" colors.txtgrep "blue" colors.txtgrep "Version" /var/www/site1/html/index.html-i - case-insensitive
cat /var/www/site1/html/index.html | grep -i "version"grep "title" /var/www/site1/html/index.htmlPipe | - Send output dari satu command ke command lain
cat colors.txt | grep "red"Nota: | ambil output dari command kiri, hantar ke command kanan.
# View file and search
cat /var/www/site1/html/index.html | grep "Version"# Test website and check version
curl localhost | grep "Version"tee - Tulis konten ke dalam fail dan tunjukkan serta merta di terminal
echo "Test with redirector" > redirect.txt
cat redirect.txtecho "Test with tee" | tee tee.txtNota: tee berguna bila nak save output DAN tengok sekali.
cd /var/www/site1/html
# akan gagal
sudo echo "test" > test-fail.txt
# akan lulus
echo "test" | sudo tee test-success.txt > /dev/null
# Verify
ls -l test-success.txtcp - Menyalin fail menjadi fail berbeza
cd /var/www/site1/htmlsudo cp index.html index-backup.htmlls -l index*sudo cp index.html index-$(date +%Y%m%d).htmlls -lsudo mkdir -p /var/www/backupssudo cp index.html /var/www/backups/ls -l /var/www/backups/mv - Mengalihkan file kepada nama baru
sudo touch old-name.htmlsudo mv old-name.html new-name.htmlls -l *name*.htmlsudo mkdir -p archivesudo mv index-backup.html archive/ls -l archive/find - cari fail
cd /var/www/site1/htmlfind . -name "index.html"find . -name "*.html"find /var/www/site1/html -type ffind /var/www -type d| Symbol | Nama | Fungsi | Contoh |
|---|---|---|---|
> |
Redirect (overwrite) | Write to file, replace old content | echo "text" > file.txt |
>> |
Redirect (append) | Add to file, keep old content | echo "text" >> file.txt |
| |
Pipe | Send output to next command | cat file | grep "word" |
| Command | Fungsi | Contoh |
|---|---|---|
touch file |
Create empty file or update timestamp | touch test.txt |
echo "text" > file |
Create file with text | echo "hello" > test.txt |
echo "text" >> file |
Update file with text | echo "hello 2" >> test.txt |
tee file |
Write and display | echo "text" | tee file.txt |
| Command | Fungsi | Contoh |
|---|---|---|
cat file |
Display file content | cat index.html |
cat file | grep |
Search in file | cat index.html | grep Version |
| Command | Fungsi | Contoh |
|---|---|---|
cp file backup |
Copy file | cp index.html backup.html |
mv old new |
Rename file | mv old.html new.html |
mv file dir/ |
Move file | mv file.txt backup/ |
| Command | Fungsi | Contoh |
|---|---|---|
grep "text" file |
Search text in file | grep "Version" index.html |
find . -name "file" |
Find file by name | find . -name "*.html" |
find . -type f |
Find files only | find /var/www -type f |