Bash-Abfragen für alles Mögliche

Aus aredn.dg5mgj.de
Zur Navigation springenZur Suche springen

Ein kurzer Griff zum Terminal und schon hat man die Info

Hier liste ich so einige Abfragen auf, welche sicher interessant für Dich sind.

Bitte beachten: Wenn eine Befehlszeile mit "$" beginnt, dann ist dies unter einem normalen User ausführbar,
beginnt die Befehlszeile jedoch mit "#", so sind Superuserrechte erforderlich.
Entweder man wechselt mit $ su - in den Superuser root oder man stellt ein $ sudo voran, womit nach Angabe des eigenen Passwortes der Befehl unter SuperUser-Hoheit ausgeführt wird - sofern man dafür berechtigt ist. Siehe auch: https://wiki.ubuntuusers.de/sudo/

Die ersten Zeichen wie "$" oder "#" bitte nicht mitkopieren, diese stellen den Prompt der Shell dar und sind zu obiger Information hier angegeben.

Eine gesammelte List der Hard- und Software erhält man mit folgender Abfrage

$ inxi -Fxxxrz --usb;lspci -nnk;lsusb -tv;xinput --list;dkms status;cat /proc/cmdline;mokutil --sb-state

Hardware Gehäuse und Bios

Das Tool dmidecode kann die Tabelle im SMBIOS auswerten und anzeigen. Hier einige Beispiele für Abfragen
Installation falls noch nicht vorhanden mit: $ sudo apt-get install dmidecode

Befehl Beschreibung der ausgegebenen Informationen
$ sudo dmidecode Alle verfügbaren Informationen ausgeben
$ sudo dmidecode -s system-manufacturer Hersteller des Systems
$ sudo dmidecode -s system-product-name Produktname des Systems
$ sudo dmidecode -s system-version Modell Nr. des Systems
$ sudo dmidecode -s bios-version Verwendete BIOS-Version
$ sudo dmidecode -s baseboard-manufacturer Hersteller des Mainboards
$ sudo dmidecode -s baseboard-product-name Produktname des Mainboards
$ sudo dmidecode -s baseboard-version Versionsnummer des Mainboards
$ sudo dmidecode -t 1 SMBIOS-Tabelle 1 ausgeben (System Information)

Welche Tabellen es gibt, kann man mit folgendem Einzeiler anzeigen:

$ sudo dmidecode | grep -A1 "^Handle" | tr "\n" "\t" | sed -e 's/--\t/\n/g'
Handle 0x0000, DMI type 0, 24 bytes	BIOS Information	
Handle 0x0001, DMI type 1, 27 bytes	System Information	
Handle 0x0002, DMI type 2, 16 bytes	Base Board Information	
Handle 0x0003, DMI type 3, 23 bytes	Chassis Information	
Handle 0x0004, DMI type 4, 42 bytes	Processor Information	
Handle 0x0005, DMI type 5, 20 bytes	Memory Controller Information	
Handle 0x0006, DMI type 6, 12 bytes	Memory Module Information	
Handle 0x0007, DMI type 6, 12 bytes	Memory Module Information	
Handle 0x0008, DMI type 7, 19 bytes	Cache Information	
Handle 0x0009, DMI type 7, 19 bytes	Cache Information	
Handle 0x000A, DMI type 7, 19 bytes	Cache Information	
Handle 0x000B, DMI type 7, 19 bytes	Cache Information	
Handle 0x000C, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x000D, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x000E, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x000F, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0010, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0011, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0012, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0013, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0014, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0015, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0016, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0017, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0018, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x0019, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x001A, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x001B, DMI type 8, 9 bytes	Port Connector Information	
Handle 0x001C, DMI type 9, 17 bytes	System Slot Information	
Handle 0x001D, DMI type 9, 17 bytes	System Slot Information	
Handle 0x001E, DMI type 9, 17 bytes	System Slot Information	
Handle 0x001F, DMI type 9, 17 bytes	System Slot Information	
Handle 0x0020, DMI type 9, 17 bytes	System Slot Information	
Handle 0x0021, DMI type 9, 17 bytes	System Slot Information	
Handle 0x0022, DMI type 9, 17 bytes	System Slot Information	
Handle 0x0023, DMI type 9, 17 bytes	System Slot Information	
Handle 0x0024, DMI type 11, 5 bytes	OEM Strings	
Handle 0x0025, DMI type 12, 5 bytes	System Configuration Options	
Handle 0x0026, DMI type 13, 22 bytes	BIOS Language Information	
Handle 0x0027, DMI type 15, 29 bytes	System Event Log	
Handle 0x0028, DMI type 16, 23 bytes	Physical Memory Array	
Handle 0x0029, DMI type 17, 34 bytes	Memory Device	
Handle 0x002A, DMI type 17, 34 bytes	Memory Device	
Handle 0x002B, DMI type 18, 23 bytes	32-bit Memory Error Information	
Handle 0x002C, DMI type 18, 23 bytes	32-bit Memory Error Information	
Handle 0x002D, DMI type 19, 31 bytes	Memory Array Mapped Address	
Handle 0x002E, DMI type 20, 35 bytes	Memory Device Mapped Address	
Handle 0x002F, DMI type 21, 7 bytes	Built-in Pointing Device	
Handle 0x0030, DMI type 22, 26 bytes	Portable Battery	
Handle 0x0031, DMI type 26, 22 bytes	Voltage Probe	
Handle 0x0032, DMI type 27, 15 bytes	Cooling Device	
Handle 0x0033, DMI type 32, 20 bytes	System Boot Information	
Handle 0x0034, DMI type 39, 22 bytes	System Power Supply	
Handle 0x0035, DMI type 40, 18 bytes	Additional Information 1	
Handle 0x0036, DMI type 41, 11 bytes	Onboard Device	
Handle 0x0037, DMI type 128, 8 bytes	OEM-specific Type	
Handle 0x0038, DMI type 129, 8 bytes	OEM-specific Type	
Handle 0x0039, DMI type 130, 20 bytes	OEM-specific Type	
Handle 0x003A, DMI type 136, 6 bytes	OEM-specific Type	
Handle 0x003B, DMI type 127, 4 bytes	End Of Table	

Achtung: Diese Ausgaben sind für jedes System unterschiedlich!


Ausgabe der ersten 7 Tabelleninhalte (0-6) mit folgendem Einzeiler

$ for Cnt in {0..6}; do sudo dmidecode -t $Cnt; done

Mit den Parametern in den geschweiften Klammern kann man den Nummernkreis einstellen

Zustand der Batterie

Dies ist natürlich nur bei Laptops oder Tabletts interessant

$ inxi -B
Battery:
  ID-1: BAT0 charge: 35.4 Wh (100.0%) condition: 35.4/62.2 Wh (57.0%)

In diesem Beispiel hat der 9 Jahre alte Akku statt der anfänglichen Kapazität von 62Wh nur noch 35Wh (57%)
Das Alter kann man am Akku selbst auf einem Aufdruck ablesen.

Memory

Welche Memoryausstattung hat mein Rechner und welches Swap wird benutzt?

$ free -h
               gesamt       benutzt     frei      gemns.  Puffer/Cache verfügbar
Speicher:       15Gi       2,3Gi       9,9Gi       509Mi       3,3Gi        12Gi
Auslager:       23Gi          0B        23Gi

Der Parameter -h lässt die Werte in lesbarer Form (--human) anzeigen


$ swapon -s
Filename				Type		Size		Used		Priority
/dev/sda1                              partition	25165820	0		-2

Der Parameter -s (--summary) zeigt diese Auswertung an

Informationen in tabelarischer Form bekommt man mit:

$ less /proc/meminfo

Damit kann man auch gezielt Werte mit grep herausgreifen.

CPU

Was läuft denn für eine CPU und wie viele Kerne und Threds hat diese

$ sed -n '/model name/p' /proc/cpuinfo | sort -u 
model name	: Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz

Es werden alle "Modellnamen aus der Liste geholt und dann mit sort vereinzelt.


Genauere Informationen zum ersten Prozessorkern

$ sed -n '1,/^$/p' /proc/cpuinfo
processor	: 0
vendor_id	: GenuineIntel
cpu family	: 6
model		: 60
model name	: Intel(R) Core(TM) i7-4710MQ CPU @ 2.50GHz
stepping	: 3
microcode	: 0x28
cpu MHz		: 800.000
cache size	: 6144 KB
physical id	: 0
siblings	: 8
core id		: 0
cpu cores	: 4
apicid		: 0
initial apicid	: 0
fpu		: yes
fpu_exception	: yes
cpuid level	: 13
wp		: yes
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fm  cx16 xtpr pdcm pcid sse4_1 sse4_2 movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti ssbd ibrs ibpb stibp  tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid xsaveopt dtherm ida arat pln pts md_clear flush_l1d
vmx flags	: vnmi preemption_timer invvpid ept_x_only ept_ad ept_1gb flexpriority tsc_offset vtpr mtf vapic ept vpid unrestricted_guest ple
bugs		: cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf mds swapgs itlb_multihit srbds mmio_unknown
bogomips	: 4988.44
clflush size	: 64
cache_alignment	: 64
address sizes	: 39 bits physical, 48 bits virtual
power management:

Alle Informationen zu allen Prozessorkernen bekommt man mit less /proc/cpuinfo

Festplatte und SSD

Welche Festplatten sind vorhanden und welche Partitionen sind darauf

$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 953,9G  0 disk 
├─sda1   8:1    0    24G  0 part [SWAP]
├─sda2   8:2    0   128M  0 part /boot/efi
├─sda3   8:3    0    52G  0 part 
├─sda4   8:4    0    52G  0 part 
├─sda5   8:5    0   128G  0 part /
└─sda6   8:6    0 697,7G  0 part /home
sdb      8:16   0   1,8T  0 disk 
└─sdb1   8:17   0   1,8T  0 part /data
sr0     11:0    1  1024M  0 rom  


Welchen Label und UUID haben diese Partitionen

$ blkid
/dev/sdb1: LABEL="daten" UUID="6eb24451-0ec5-4a0c-bb57-5ea515cf01a4" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5144b5ca-8634-4dc0-846a-cb291a09e41a"
/dev/sda4: LABEL="home-alt" UUID="53286760-5dcc-41c5-b29e-de5576491656" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="home-alt" PARTUUID="13ef0d09-126c-4d1c-af8a-9133b96689f4"
/dev/sda2: LABEL_FATBOOT="EFI" LABEL="EFI" UUID="2547-1779" BLOCK_SIZE="512" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="ba4c278c-13a1-48b9-b801-0e81176a8c6e"
/dev/sda5: UUID="78b49306-74c5-4e07-a19b-cc92bb153736" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="root" PARTUUID="548eccf0-7d6c-464a-988a-0b435eb1a26e"
/dev/sda3: UUID="63e7caac-d7bc-447b-a6a0-ec7365524d9c" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="root-alt" PARTUUID="5cb81689-d726-4990-9fdd-51d777be9198"
/dev/sda1: UUID="bf1d7fde-24ca-4e27-bf94-4261e85dd6b2" TYPE="swap" PARTUUID="781d2d5d-a8b7-4dd8-930c-f593ebfd401f"
/dev/sda6: UUID="23090bf2-b747-4048-9b03-544ddbab9eb2" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="home" PARTUUID="251a8385-451c-4915-be64-42b2777a35ba"

Welche Typ von Festplatte ist verbaut und wie sind die Daten organisiert

$ sudo fdisk -l -u /dev/sdb
Festplatte /dev/sdb: 1,82 TiB, 2000398934016 Bytes, 3907029168 Sektoren
Festplattenmodell: ST2000LX001-1RG1
Einheiten: Sektoren von 1 * 512 = 512 Bytes
Sektorgröße (logisch/physikalisch): 512 Bytes / 4096 Bytes
E/A-Größe (minimal/optimal): 4096 Bytes / 4096 Bytes
Festplattenbezeichnungstyp: gpt
Festplattenbezeichner: 51C572DD-2585-4665-B097-9A83540278C1

Gerät      Anfang       Ende   Sektoren Größe Typ
/dev/sdb1    2048 3907028991 3907026944  1,8T Linux-Dateisystem

und weitere Informationen zur Hardware

$ sudo smartctl -i -d scsi /dev/sdb
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.0-112-generic] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

User Capacity:        2.000.398.934.016 bytes [2,00 TB]
Logical block size:   512 bytes
Physical block size:  4096 bytes
LU is fully provisioned
Rotation Rate:        5400 rpm
Form Factor:          2.5 inches
Logical Unit id:      0x5000c500a955e4e0
Serial number:        WDZ4FEWZ
Device type:          disk
Local Time is:        Tue Jun 11 17:05:40 2024 CEST
SMART support is:     Unavailable - device lacks SMART capability.

hier noch einmal die gezielte Abfrage einer Partition

$ blkid /dev/sdb1
/dev/sdb1: LABEL="daten" UUID="6eb24451-0ec5-4a0c-bb57-5ea515cf01a4" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="5144b5ca-8634-4dc0-846a-cb291a09e41a"


Wie geht es denn einer bestimmten Festplatte

$ sudo smartctl -A /dev/sdb
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.15.0-112-generic] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   079   064   006    Pre-fail  Always       -       72944751
  3 Spin_Up_Time            0x0003   099   099   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   077   077   020    Old_age   Always       -       23958
  5 Reallocated_Sector_Ct   0x0033   100   100   036    Pre-fail  Always       -       2
  7 Seek_Error_Rate         0x000f   083   060   045    Pre-fail  Always       -       4483255039
  9 Power_On_Hours          0x0032   070   070   000    Old_age   Always       -       26663 (227 39 0)
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   092   092   020    Old_age   Always       -       8660
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   100   100   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   100   099   000    Old_age   Always       -       13
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   071   037   040    Old_age   Always   In_the_past 29 (0 130 31 28 0)
191 G-Sense_Error_Rate      0x0032   100   100   000    Old_age   Always       -       45
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       75
193 Load_Cycle_Count        0x0032   087   087   000    Old_age   Always       -       26975
194 Temperature_Celsius     0x0022   029   063   000    Old_age   Always       -       29 (0 15 0 0 0)
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       19670h+56m+08.684s
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       56645851929
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       72661152743
254 Free_Fall_Sensor        0x0032   100   100   000    Old_age   Always       -       0

Inhalt auf Festplatten

Welche Pfade sind denn auf meiner Festplatte (begrenzte Anzeige)

$ tree -dlL 2 /home
/home
├── Backup
│   ├── TuxedoI7_2023-02-21
│   └── TuxedoI7_2023-03-07
├── lost+found  [error opening dir]
├── rudi
│   ├── Bilder
│   ├── Dokumente
│   ├── Downloads
│   ├── EXPORTS
│   ├── logfiles -> /data/logfiles
│   ├── Musik
│   ├── Öffentlich
│   ├── PlayOnLinux's virtual drives -> /home/rudi/.PlayOnLinux//wineprefix/
│   ├── Schreibtisch
│   ├── Videos
│   ├── Vorlagen
│   └── Warpinator
└── timeshift
    ├── snapshots
    ├── snapshots-boot
    ├── snapshots-daily
    ├── snapshots-hourly
    ├── snapshots-monthly
    ├── snapshots-ondemand
    └── snapshots-weekly

25 directories

Angaben zu den benutzten Optionen (-dlL)

  • Mit der Option "d" werden nur Directorys angezeigt
  • Die Option "l" zeigt die Verlinkung an und folgt dieser
  • Mit der dem Parameter "L" und der Zahlenangabe wird die Anzeigegröße gewählt

Prozesse suchen und anzeigen

Auslastung des Rechners mit Filtermöglichkeiten

$ htop

... zeigt wie top die vorhandenen Prozesse an, bietet aber bessere Auswahlmöglichkeiten
installieren mit $ sudo apt-get install htop


aktive Jobs aus der crontab anzeigen

$ crontab -l | grep -v '^#'

Bei dieser Anzeige werden alle Kommentare ausgeblendet


Prozesse des crond anzeigen - laufende crontab-Jobs

$ pstree -pa `pgrep cron`
cron,950 -f -P

Aktuell kein laufender Cron-Job. Ansonsten wird der komplette Prozessbaum angezeigt.

Netzwerkabfragen

Sensoren im Rechner

Wie lange läuft der Rechner schon

Wie lange ein Rechner läuft oder wann dieser gebootet wurde geben diese beiden Abfragen preis

$ uptime
 17:38:04 up 25 days, 23:57,  1 user,  load average: 0,33, 0,15, 0,06
$ who -b
       Systemstart  2025-09-11 07:15

Wobei diese Abfrage nur auf Systemen mit Realtimeclock vernünftige Ergebnisse liefern

$ who -b

Systemstart 1970-01-01 01:00 Hier liefert uptime -s das richtige Ergebnis:

$ uptime -s
2024-05-16 17:40:47

Fortsetzung folgt