# SysAdmin Commands

{% hint style="info" %}
User identification and who is who in Linux world
{% endhint %}

<table><thead><tr><th width="159">คำสั่ง</th><th>คำอธิบาย</th></tr></thead><tbody><tr><td>hostname</td><td>แสดงชื่อเครื่อง</td></tr><tr><td>whoami</td><td>ชื่อ username ที่ login เข้าระบบ ณ ขณะนี้</td></tr><tr><td>w</td><td>แสดงรายชื่อ user ที่กำลังเข้าใช้ในระบบ ระยะเวลาที่เข้าสู่ระบบ .</td></tr><tr><td>last</td><td>แสดงรายชื่อ user ที่เข้าสู่ระบบที่ผ่านมา </td></tr><tr><td>last root</td><td>แสดงข้อมูลว่า root user เข้าสู่ระบบล่าสุด </td></tr><tr><td>lastb</td><td>แสดงรายชื่อ user ที่พยายามเข้าสู่ระบบ แต่ไม่สำเร็จ</td></tr></tbody></table>

### ตรวจสอบรายละเอียด Hardware ของเครื่อง

```shell-session
// report exact memory configuration, firmware version, mainboard configuration, 
CPU version and speed, cache configuration, bus speed, etc.
$ sudo lshw | less 
$ sudo lshw -html > myhardware.html 
$ sudo lshw -xml > myhardware.xml 


$ sudo dmidecode -q | less # To display BIOS information
$ sudo slusb -tv # To see USB info


$ sudo smartctl -A /dev/sda | grep Power_On_Hours # How long has this disk (system) been powered on in total
$ sudo hdparm -tT /dev/sda # Do a read speed test on disk sda
$ sudo badblocks -s /dev/sda # Test for unreadable blocks on disk sda
```

### การอ่านสถานะของทรัพยากรระบบจากไดเรกทอรี /proc

ไดเรกทอรี /proc เปรียบเสมือนหน้าต่างของลีนุกซ์คอร์เนล (Kernel Windows) ซึ่งเป็นไดเรกทอรีพิเศษที่เป็นระบบไฟล์เสมือน (virtual filesystem) ที่สามารถเข้าถึงสถานะการทำงานของอุปกรณ์ในระดับฮาร์ดแวร์ของเครื่อง และสถานะข้อมูลต่างๆของระบบโดยค่าทั้งหมดจะถูกเก็บอยู่ในหน่วยความจำ&#x20;

เมื่อใช้คำสั่ง ls /proc  จะพบกลุ่มของไฟล์จำนวนมาก รวมทั้งไดเรกทอรีที่เป็นตัวเลข ซึ่งไดเรกทอรีเหล่านี้คือสถานที่เก็บข้อมูลของระบบที่กำลังทำงานอยู่และถูกจะอ้างอิงจากหมายเลขโปรเซสนั่นเอง นอกจากนั้นแล้วในไดเรกทอรี /proc ยังมีไฟล์พิเศษที่แทนฮาร์แวร์ต่างๆในระบบ ได้แก่

<table><thead><tr><th width="243">ไฟล์</th><th>คำอธิบาย</th></tr></thead><tbody><tr><td>/proc/modules</td><td>dynamically loaded modules</td></tr><tr><td>/proc/devices</td><td>registered character and block major numbers</td></tr><tr><td>/proc/iomem</td><td>on-system physical RAM and bus device addresses</td></tr><tr><td>/proc/ioports </td><td>on-system I/O port addresses (especially for x86 systems)</td></tr><tr><td>/proc/interrupts</td><td>registered interrupt request numbers</td></tr><tr><td>/proc/softirqs</td><td>registered soft IRQs</td></tr><tr><td>/proc/kallsyms</td><td>running kernel symbols, including from loaded modules</td></tr><tr><td>/proc/partitions</td><td>currently connected block devices and their partitions</td></tr><tr><td>/proc/filesystems</td><td>currently active filesystem drivers</td></tr><tr><td>/proc/swaps</td><td>currently active swaps</td></tr><tr><td>/proc/cpuinfo</td><td>information about the CPU(s) on the system</td></tr><tr><td>/proc/meminfo</td><td>information about the memory on the system, viz., RAM, swap</td></tr></tbody></table>

```shell-session
$ cat /proc/cpuinfo # Find CPU model/speed information
$ grep -c processor /proc/cpuinfo # Count processor (including cores)
$ cat /proc/meminfo # Find Memory details
```

### โปรแกรมเสริมการดูทรัพยากรสำคัญภายในเครื่อง

```shell-session
$ sudo apt install htop bashtop glances

$ htop
$ bashtop
$ glances
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aic-eec.com/computer-operation-systems/zero-to-linux-hero/anatomy-of-linux-system/linux-os-command-line-part-i/sysadmin-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
