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 system 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 being executed by the current processes.

who Display Current Login User Information#

  • Image
  • Similar to a simplified version of w.

  • When there is too much information in --help, learn to use tldr.

  • -q View all logged-in users and the number of users.

  • -H Display headers.

whoami, who am i Current Effective/Real Username#

  • Image
  • sudo -i Start the default shell with superuser privileges.

  • who i am = who am i

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

  • Image

last Recently Logged-in Users#

Application: Find the three most frequently logged-in users.

  • Image
  • Clean empty lines [ "^$" ], split by spaces and take the first column, sort in dictionary order [ASCII code], count, and sort in reverse numerical order.

  • cut -c 10-15: Cut by character, take a column corresponding to characters 10-15.

[Extension] Word Frequency Statistics (a.log contains the contents of the ls, man, stdio, scanf sections of the man page)

  • Image
  • tr command for character replacement

    • -c Reverse replacement
    • -s Compress consecutive duplicate characters

uname System Information#

  • uname -a Complete system information [Use this command when first starting on a machine]

date Display or Set System Time and Date#

  • Image
  • Custom string formats can be used, try different cases to see the results.

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

    • Image
    • From Wikipedia, a distributed structure similar to DNS, but it is unidirectional.
    • 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
      • The time zone can be modified using the ln -sf [force overwrite symbolic link] command to link /etc/localtime to the time zone.
      • Example: sudo ln -sf /usr/share/zoneinfo/Asia/City /etc/localtime

Additional Knowledge#

  • cal Display a calendar.
  • echo -e enables the use of backslashes .
    • For example, echo -e "\033[32m123\033[0m456" outputs colored text, similar to printf.
  • $[] is used for integer calculations only.

Points to Consider#

Tips#

  • Abbreviations may represent:
    • -h: help, human, header (w -h)
    • -p: pretty
  • Spaces are sensitive in shell scripts.
  • Variables defined in the shell are only available within the process. They disappear when the shell is exited [or the SSH connection is disconnected].
  • wget can be used to download document data.

Course Notes#

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