Bo2SS

Bo2SS

6 Obtaining System Information

Course Content#

uptime System Uptime and Average Load#

  • Image
  • Used to monitor how long the system has been running, how many users are logged in, and the running status (load)

  • Learn to use --help to view command help

  • Image

w User List and Running Tasks#

  • Image
  • Image
  • When the system is slow, you can check the commands currently being executed by the processes.

who Display Current Logged-in User Information#

  • Image
  • A bit like a simplified version of w

  • When the --help information is too much, learn to use tldr

  • -q View all logged-in users and their count

  • -H Display header

whoami, who am i Current Effective/Real Username#

  • Image
  • sudo -i starts the default shell with superuser privileges

  • who i am = who am i

  • who am i actually belongs to the who command, am i is a parameter

  • Image

last Recent Login Information of Users#

Application: Find the three users who logged in most frequently recently.

  • Image
  • Clean empty lines【"^$"】, split by spaces and take the first column, sort in dictionary order [i.e., ASCII order], count, and sort in descending numerical order.

  • cut -c 10-15: cut by character, take the 10th to 15th characters of a certain column.

【Extension】Word Frequency Statistics (a.log contains the content of man pages for ls, man, stdio, scanf)

  • Image
  • tr character replacement command

    • -c reverse replacement
    • -s compress consecutive duplicate characters

uname System Information#

  • uname -a very complete system information [use this command first when getting hands-on with the machine]

date Display or Set System Time and Date#

  • Image
  • You can customize string formats; try different cases yourself.

  • [PS] NTP—Network Time Protocol, synchronizes time through time zones.

    • Image
    • From Wikipedia, the distributed structure is similar to DNS, but it is a one-way connection.
    • Applications: Banking systems, online shopping.
    • Time server configuration can be found in /etc/ntp.conf.
    • Time zones can be viewed in /usr/share/zoneinfo.
      • Image
      • To modify the time zone, you can use the ln -sf [force overwrite soft link] command to link /etc/localtime to the time zone.
      • Example: sudo ln -sf /usr/share/zoneinfo/Asia/City /etc/localtime

Additional Knowledge Points#

  • cal Display Calendar
  • echo -e can make the backslash \ effective
    • For example, echo -e "\033[32m123\033[0m456" outputs color, similar to printf.
  • $[] only performs integer calculations.

Points to Consider#

Tips#

  • Abbreviations may represent
    • -h: help, human, header (w -h)
    • -p: pretty
  • Spaces in shell scripts are sensitive.
  • Variables defined in the shell exist in the process; they disappear when you exit the shell [or disconnect from SSH].
  • wget can download document data.

Course Notes#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.