0% found this document useful (0 votes)
3 views

linux

aaaa

Uploaded by

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

linux

aaaa

Uploaded by

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

1.

Pada desktop Linux, klik kanan di mana saja dan pilih Buka
Terminal di Sini dari menu konteks untuk membuka jendela
Terminal.

Di jendela terminal baru, perhatikan prompt:


cybrary@linux:~/Desktop$. Banyak informasi yang
disampaikan di sini. Pertama, Anda adalah pengguna
cybrary pada host bernama linux. ~ berarti "home," yang,
bagi pengguna cybrary, adalah /home/cybrary. /Desktop
berarti lokasi Anda saat ini dalam sistem berkas adalah
direktori Desktop di bawah /home/cybrary. $ berarti Anda
adalah pengguna non-root.

Catatan: Tidak semua terminal Linux yang Anda gunakan


akan memiliki prompt untuk memberi tahu Anda siapa dan
di mana Anda berada. Pada langkah berikutnya, Anda akan
mempelajari beberapa perintah untuk memvalidasi
informasi yang diberikan oleh prompt tersebut.
2. Pada prompt, ketik whoami dan tekan Enter untuk
menampilkan nama pengguna saat ini.

3. Pada prompt, ketik nama host dan tekan Enter untuk


menampilkan nama mesin.

4. Pada prompt, ketik pwd dan tekan Enter untuk


menampilkan direktori saat ini.

Perintah pwd adalah singkatan dari print working directory.


Ingat bahwa ~ adalah kependekan dari "home" dan "home"
untuk pengguna cybrary adalah /home/cybrary. Jadi
~/Desktop = /home/cybrary/Desktop.
5. Pada prompt, ketik id dan tekan Enter untuk menampilkan
ID pengguna dan grup untuk akun Anda.

Akun pengguna standar di Linux dimulai pada id 1000.


Pengguna cybrary adalah id 1001, yang berarti akun
tersebut adalah akun pengguna standar. Setiap pengguna
juga akan menjadi anggota grup yang diberi nama sesuai
nama pengguna. Sekarang setelah kita memastikan siapa
kita dan di mana kita berada, mari kita jelajahi sistem
berkas Linux.

6. Pada prompt, ketik cd .. (perhatikan spasi antara cd dan ..)


dan tekan Enter. Perintah cd berarti

change directory, dan .. berarti naik satu direktori. Dengan


menjalankan perintah ini, kita berpindah dari
/home/cybrary/Desktop ke /home/cybrary. Anda dapat
menggunakan perintah pwd untuk mengonfirmasi hal ini.

7. Pada prompt, ketik ls dan tekan Enter untuk menampilkan


daftar semua file dan direktori di direktori saat ini
(/home/cybrary).

8. Pada prompt, ketik ls -l dan tekan Enter untuk menampilkan


daftar direktori yang panjang.

Notice that with the -l option, you can see important


information about the directories and files in /home/cybrary.
In the output, the "d" means that the object is a directory.
Next are three sets of permissions. Permissions are read (r),
write (w), and execute (x). A dash (-) means that a given
permission is not set. For example, r-x grants read and
execute permission but not write. The first set of three
applies to a file or folder owner, the next set applies to the
group, and the last set applies to everyone else. Thus, for
the /home/cybrary/Desktop directory, user cybrary has
permission to read, write and execute, group cybrary has
permission to read and execute, and everyone else has
permission to read and execute.

9. At the prompt, type ls -la and press Enter.


The -a option shows all files, including hidden files. Notice
the files that start with a dot (.) These are hidden files.
Typically these files are used to manage terminal settings,
collect command history, and other shell-related settings.
They are hidden to prevent users from making accidental
changes to these important files and to keep the directory
listing clean.

10. At the prompt, type cd ../.. and press Enter to go


up two directories.

Notice the prompt changes to cybrary@linux:/$. The "/"


means root directory. This is the top (root) of the Linux file
system. Everything in Linux lives under the root directory.
You can type cd ../../../../.. and press Enter, but you cannot
go any higher than the root of the file system.

11. At the prompt, type ls and press Enter to see the


typical file structure for Linux.

12. At the prompt, type cd ~ and press Enter to return


home (/home/cybrary).
Alternatively, you can type cd /home/cybrary and press
Enter.

13. At the prompt, type mkdir labwork and press Enter to


create a new directory called labwork within the cybrary
home directory.

The mkdir command stands for make directory. You can


confirm the directory was created with ls.

14. At the prompt, use the cd command to navigate to


the labwork directory.

15. At the prompt, type touch file1.txt file2.txt


file3.txt and press Enter to create three empty files in the
labwork directory. Use the ls command to confirm.

16. At the prompt, type echo "This is file 1" >>


file1.txt and press Enter to append the quoted text into the
file1.txt file.
The “>>” output redirector tells Linux to append the echoed
text to the file.

17. At the prompt, type cat file1.txt and press Enter to


print the contents of file1.txt to the screen.

The cat command stands for con cat enate.

18. At the prompt, type file file1.txt and press Enter to


confirm that file1.txt is an ASCII text file.

The file command displays a file's type, even if a file has no


extension or is intentionally mislabeled (e.g., file1.exe).

Note: Linux does not require the .txt extension on text files.
Adding .txt is a courtesy to other users on the system.

19. At the prompt, use the echo command to


append This is file 2 to file2.txt and This is file 3 to
file3.txt, then use the cat command to confirm.
20. At the prompt, use the mkdir command to create
three new directories in the labworks directory: red, blue,
and green. It is possible to make all three directories at
once. Use ls to confirm your work.

In the next steps, you will practice the commands to copy


and move files.

21. At the prompt, type cp file1.txt blue/ and press Enter


to copy file1.txt to the blue directory.

22. At the prompt, type ls -R and press Enter to display all


files and folders under the labwork directory.

Notice that file1.txt exists in both labwork and blue (because


it was copied, rather than moved).
23. At the prompt, type rm -i file1.txt and press Enter to
remove file1.txt.

When prompted, type y and press Enter to confirm.

Note: Without the -i option, rm would have removed the file


without confirmation. This is very dangerous as the Linux CLI
does not have a recycle bin like Windows. The rm command
does not honor the GUI recycle bin even if you use a Linux
GUI desktop. If you delete a file by accident, you will need to
restore that file from a backup.

24. At the prompt, type ls -R and press Enter to confirm


that file1.txt is now removed from the labworks folder.

25. At the prompt, type mv file2.txt green and press


Enter to move the file2.txt file to the green directory.
Execute ls -R to confirm that file2.txt has been moved.
Unlike the cp command, the mv command does not leave a
copy of the file behind.

The mv command is also used the rename files.

26. At the prompt, type mv file3.txt


happypumpkin.moo and press Enter to rename file3.txt.

Execute ls -R to confirm that file3.txt is gone, and in its


place is happypumpkin.moo.

27. At the prompt, use the cat command to prove that the
contents of happypumpkin.moo are the same as file3.txt.

Note: Again, Linux does not care what file you name or
what file extension you use.
28. At the prompt, type mv happypumpkin.moo
red/file3.txt and press Enter to move and rename the
happypumpkin.moo file. Execute ls -R to confirm.

When you use the cat command to output the file's output
to the terminal, the entire file content gets printed all at
once, which is not always ideal. Linux provides two tools for
reading large files: more and less. The more command is
the original reading tool. The more command allows you to
page through a file, one page at a time. The less command
is a play on words as less is a newer tool, and less allows
you to scroll up and down. In essence, "less" is "more".

29. At the prompt, type base64 /dev/urandom | head -c


1M > abigfile.txt and press Enter to create a large file.

This command generates 1MB of random text that is base


64 encoded. Execute ls -la to confirm the creation of
abifile.txt.

30. At the prompt, type more abigfile.txt and press Enter


to open abigfile.txt in more.
You can use the space bar to page through the file, but
because this file is massive, it would take a long time to
page through all of abigfile.txt. Instead, press q to quit
more.

31. At the prompt, type less abigfile.txt and press Enter


to open abigfile.txt in less.

Use the space bar to page down, b to page up, the down
arrow to go down one line at a time, and the up arrow to
go up one line at a time. When done moving around in less,
press q to quit less.

Knowing how to locate files is essential when using Linux.


As luck would have it, Linux provides the find command just
for this purpose.

32. At the prompt, type find / -name "more"


2>/dev/null and press Enter to look for all directories and
files called "more" starting at the root directory (/).
Note: The 2>/dev/null command line argument tells Linux
to redirect (>) any errors (2) to a black hole (/dev/null). This
command suppresses error messages and makes the output
more useful. Feel free to try the find command without error
suppression to see what that looks like.

33. At the prompt, type find . -name "*.txt" and press


Enter to find all files with a .txt extension in the current
directory and all subdirectories.

Terkadang kita perlu menemukan berkas yang berisi kata


atau frasa tertentu. Alat grep Linux dirancang untuk hal
tersebut.

34. Pada prompt, ketik grep -r "This" dan tekan Enter


untuk menemukan semua file yang berisi teks "This". Alat
grep akan menunjukkan lokasi file dan menampilkan baris
tempat teks tersebut ditemukan.
Terakhir, mari kita lihat beberapa teknik penguraian berkas
dasar. Di direktori /cybrary/home, terdapat berkas yang
belum diurutkan. Kita akan melihat cara mengurutkan dan
menghitung isi berkas ini. Kita juga akan melihat cara
menggabungkan perintah Linux sederhana untuk
menghasilkan hasil yang diinginkan.

35. Pada prompt, jalankan perintah untuk kembali ke


direktori /home/cybrary .

36. Pada prompt, ketik cat unsorted dan tekan Enter


untuk melihat isi berkas "unsorted". Anda akan melihat
daftar kata tanpa urutan tertentu. Anda mungkin
memperhatikan bahwa beberapa kata berulang.
37. Pada prompt, ketik cat unsorted | sort dan tekan
Enter untuk mencetak daftar kata yang diurutkan
berdasarkan abjad dalam file "unsorted" ke layar.
Karakter | disebut pipe . Karakter ini memberi tahu Linux
untuk mengambil output cat dan
menjadikannya input untuk perintah sort.

38. Pada prompt, ketik cat unsorted | sort | uniq dan


tekan Enter untuk mengurutkan daftar dan menghapus
duplikat.
Dalam contoh ini, output perintah cat disalurkan ke sort, lalu
output tersebut disalurkan ke uniq.

Catatan: Perintah uniq harus digunakan dengan


perintah sort , seperti yang ditunjukkan.

39. Pada prompt, ketik cat unsorted | wc untuk


menghitung kata, baris, dan karakter file.

Perintah wc adalah singkatan dari word count. Outputnya


memberi tahu kita bahwa ada 17 kata , 17 baris teks,
dan jumlah karakter total 123.
40. Pada prompt, ketik cat unsorted | wc -w commands
untuk melihat jumlah kata saja.

41. Pada prompt, ketik cat unsorted | sort | uniq | wc -


w dan tekan Enter untuk menghitung kata unik dalam file
"unsorted".

42. Pada prompt, ketik cd Desktop dan tekan Enter untuk


menavigasi ke desktop.

43. Pada prompt, ketik ./flag.sh dan tekan Enter untuk


menjalankan skrip yang akan memeriksa pekerjaan
Anda. Anda akan memerlukan 8 poin untuk menampilkan
tanda yang diperlukan untuk menjawab pertanyaan terakhir
pada tab Tugas.

Ringkasan
Di lab ini, Anda mempelajari cara menavigasi sistem berkas Linux
dan menemukan berkas serta folder. Anda mempelajari cara
membuat berkas dan direktori serta menambahkan teks ke
berkas. Anda juga mempelajari beberapa penguraian berkas
dasar. Jawab pertanyaan di tab Tugas, lalu lanjutkan ke latihan
tantangan, tempat Anda akan menerapkan keterampilan baru
Anda.

You might also like