{"id":403,"date":"2015-11-16T14:28:16","date_gmt":"2015-11-16T14:28:16","guid":{"rendered":"http:\/\/onlinelab.info\/?p=403"},"modified":"2015-11-16T14:28:16","modified_gmt":"2015-11-16T14:28:16","slug":"collecting-ubuntu-linux-system-information","status":"publish","type":"post","link":"https:\/\/www.asianux.org.vn\/index.php\/2015\/11\/16\/collecting-ubuntu-linux-system-information\/","title":{"rendered":"Collecting Ubuntu Linux System Information"},"content":{"rendered":"<h2>Find the system host name<\/h2>\n<p>Display the system&#8217;s host name:<br \/>\n<code>$ <strong>hostname<\/strong><br \/>\n$ <strong>cat \/etc\/hostname<\/strong><br \/>\n<em>server1<\/em><\/code><br \/>\nDisplay the system&#8217;s DNS domain name:<br \/>\n<code>$ <strong>dnsdomainname<\/strong><br \/>\n<em>cyberciti.biz<\/em><\/code><br \/>\nDisplay the system&#8217;s Fully Qualified Domain Name (FQDN):<br \/>\n<code>$ <strong>hostname -f<\/strong><br \/>\n<em>server1.cyberciti.biz<\/em><\/code><\/p>\n<h2>Find the system serial number, manufacturer of the system and model name<\/h2>\n<p><code>$ sudo dmidecode -s system-serial-number<br \/>\n$ sudo dmidecode -s system-manufacturer<br \/>\n$ sudo dmidecode -s system-product-name<br \/>\n$ sudo dmidecode | more<\/code><br \/>\nOR use the lshw command:<br \/>\n<code># lshw | more<br \/>\n$ sudo lshw -short<\/code><\/p>\n<h3>Display information about installed hardware<\/h3>\n<p><code>$ sudo lsdev<\/code><\/p>\n<h2>Find the system CPU info<\/h2>\n<p><code>$ cat \/proc\/cpuinfo<\/code><br \/>\nOR<br \/>\n<code>$ lscpu<\/code><\/p>\n<h3>Display CPU (processors) related statistics<\/h3>\n<p><code>$ sudo mpstat<br \/>\n$ sudo mpstat 1<br \/>\n$ sudo mpstat -A<\/code><\/p>\n<h2>Find the system main memory (RAM) info<\/h2>\n<p>Show statistics about memory usage on the system including total installed and used RAM:<br \/>\n<code>$ less \/proc\/meminfo<\/code><br \/>\nShow amount of free and used memory in the system:<\/p>\n<pre class=\"bash\">free\n## Display the amount of memory in megabytes ##\nfree -m\n\u00a0\n## Display the amount of memory in gigabytes ##\nfree -g\n\u00a0\n## Display the amount of memory in terabytes ##\nfree --tera\n\u00a0\n## Display human readable output ##\nfree -h<\/pre>\n<h3>Show the system swap space usage<\/h3>\n<p><code>$ swapon -s<br \/>\n$ cat \/proc\/swaps<br \/>\n$ cat \/proc\/meminfo<br \/>\n$ top<br \/>\n$ vmstat<br \/>\n$ for file in \/proc\/*\/status ; do awk '\/VmSwap|Name\/{printf $2 \" \" $3}END{ print \"\"}' $file; done | sort -k 2 -n -r | less<br \/>\n$ smem<\/code><\/p>\n<h3>Show the system virtual memory statistics<\/h3>\n<p><code>$ sudo vmstat<br \/>\n$ sudo vmstat 1<br \/>\n$ sudo vmstat 2<\/code><\/p>\n<h2>Find the Ubuntu Linux distribution version and related information<\/h2>\n<p><code>$ lsb_release -a<\/code><\/p>\n<h2>Find the system kernel version number<\/h2>\n<p><code>$ uname -r<\/code><br \/>\nOR<br \/>\n<code>$ uname -a<\/code><\/p>\n<h2>Find the system kernel parameters<\/h2>\n<p><code>$ cat \/proc\/cmdline<br \/>\n$ sysctl -a | more<\/code><\/p>\n<h2>Find the system kernel architecture (32 bit or 64 bit)<\/h2>\n<p><code>$ uname -m<br \/>\n$ getconf LONG_BIT<br \/>\n$ arch<\/code><\/p>\n<h2>Find the system disk information<\/h2>\n<p>Show all installed disks and size:<br \/>\n<code># fdisk -l | grep '^Disk \/dev'<\/code><\/p>\n<h3>List all partitions of \/dev\/sda disk:<\/h3>\n<p>To read a disk label for \/dev\/sda:<br \/>\n<code># fdisk -l \/dev\/sda<\/code><br \/>\nTo label a disk:<br \/>\n<code>$ sudo fdisk \/dev\/sda<br \/>\n$ sudo e2label \/dev\/sda1<br \/>\n$ sudo cfdisk \/dev\/sda<\/code><\/p>\n<h3>Show block device attributes:<\/h3>\n<p><code># blkid<\/code><\/p>\n<h3>List all block devices:<\/h3>\n<p><code># lsblk<\/code><\/p>\n<h3>Display file system disk space usage:<\/h3>\n<p><code>$ df<br \/>\n$ df -H<br \/>\n$ df -HT<\/code><\/p>\n<h3>Estimate file space usage:<\/h3>\n<p><code>$ du<br \/>\n$ du \/home<\/code><\/p>\n<h3>Display mounted file system:<\/h3>\n<p><code>$ cat \/proc\/mount<br \/>\n$ mount<\/code><\/p>\n<h3>Display SCSI devices (or hosts) and their attributes on Linux:<\/h3>\n<p><code>$ lsscsi<\/code><\/p>\n<h3>Display I\/O statistics<\/h3>\n<p><code>$ sudo iostat<br \/>\n$ sudo iostat 2<\/code><\/p>\n<h2>Find the system PCI devices information<\/h2>\n<p><code>$ lspci<br \/>\n$ lspci -vt<br \/>\n$ lspci | grep -i 'something'<br \/>\n$ lspci -vvvn| less<\/code><\/p>\n<h2>Find the system USB devices information<\/h2>\n<p><code>$ lsusb<br \/>\n$ lsusb -vt<\/code><\/p>\n<h2>Find the system Wireless devices information<\/h2>\n<p><code>$ iwconfig<br \/>\n$ watch -n 1 cat \/proc\/net\/wireless<br \/>\n$ wavemon<\/code><\/p>\n<h2>Find the system VGA\/Graphics devices information<\/h2>\n<p><code>$ lspci | grep -i vga<br \/>\n$ lspci -vvnn | grep VGA<\/code><br \/>\nOR<br \/>\n<code>$ sudo lshw -class display<\/code><\/p>\n<h3>Find the system NVIDIA Graphics devices information<\/h3>\n<p>The following commands only works with Nvidia&#8217;s binary Linux driver:<br \/>\n<code>$ nvidia-smi<\/code><br \/>\nOR<br \/>\n<code>$ nvidia-settings<\/code><\/p>\n<h3>Find the system AMD\/ATI Graphics devices information<\/h3>\n<p>The following command only works with AMD&#8217;s binary Linux driver called catalyst:<br \/>\n<code>$ fglrxinfo<\/code><\/p>\n<h2>Which version of Unity am I running?<\/h2>\n<p><code>$ unity --version<\/code><\/p>\n<h2>Find the system audio devices information<\/h2>\n<p><code>$ lspci | grep -i audio<\/code><br \/>\nOR<br \/>\n<code>$ cat \/proc\/asound\/cards<\/code><br \/>\nOR<br \/>\n<code>$ arecord -l<\/code><\/p>\n<h2>Display the system\/laptop battery status &amp; thermal temperature<\/h2>\n<p><code>$ upower -i \/org\/freedesktop\/UPower\/devices\/battery_BAT0<br \/>\n$ acpi -V<\/code><\/p>\n<h2>Find out how long the system has been running<\/h2>\n<p><code>$ uptime<br \/>\n$ who<br \/>\n$ w<\/code><\/p>\n<h3>Find the system load<\/h3>\n<p><code>$ uptime<br \/>\n$ cat \/proc\/loadavg<br \/>\n$ sudo top<br \/>\n$ sudo htop<br \/>\n$ sudo atop<\/code><\/p>\n<h3>Show the system reboot and shutdown history<\/h3>\n<p><code>$ last reboot<br \/>\n$ last shutdown<\/code><\/p>\n<h3>Show runlevel<\/h3>\n<p><code>$ runlevel<br \/>\n$ who -r<\/code><\/p>\n<h2>Display kernel ring buffer (boot time) messages<\/h2>\n<p>Use the following command to see boot time message including hardware configuration<br \/>\n<code>$ sudo less \/var\/log\/dmesg<br \/>\n$ sudo grep 'regx' \/var\/log\/dmesg<br \/>\n$ sudo grep '[h|s]d' \/var\/log\/dmesg<\/code><\/p>\n<h2>Display the system drivers (modules)<\/h2>\n<p><code>$ sudo lsmod<br \/>\n$ sudo modinfo {driver_name}<br \/>\n$ sudo modinfo kvm<\/code><\/p>\n<h2>Find the system IP address and related information<\/h2>\n<p>You need to use the <a title=\"See Linux\/Unix ip command examples for more info\" href=\"http:\/\/www.cyberciti.biz\/faq\/linux-ip-command-examples-usage-syntax\/\" target=\"_blank\" rel=\"noopener\">ip command<\/a>:<\/p>\n<pre class=\"bash\">## Info about all interfaces. Must be run as root via sudo command ##\nsudo ip a\nsudo ip\nsudo ip link ls up\nsudo ifconfig -a\n\u00a0\n## Only show eth1 interface info ##\nsudo ip a show eth0\nsudo ifconfig eth0<\/pre>\n<h3>Display the system routing table<\/h3>\n<pre class=\"bash\">## You can use any one of the following command ##\n## Must be run as root ##\nsudo ip r\nsudo route -n\nsudo netstat -nr\n<\/pre>\n<h3>Display the system ethernet bridge<\/h3>\n<p><code>$ sudo brctl show<br \/>\n$ sudo bridge link<\/code><\/p>\n<h2>Display the system DNS server and related information<\/h2>\n<p>Display the system name server IP address (ISP or your dns server IP should be listed here):<br \/>\n<code># cat \/etc\/resolv.conf<\/code><br \/>\nDisplay the system resolver configuration file. This is useful to find out how host lookups are to be performed:<br \/>\n<code># cat \/etc\/host.conf<\/code><br \/>\nUse above two files to configure name resolution.<\/p>\n<h2>Display information about the system ports and socket<\/h2>\n<pre class=\"bash\">## Must run as root via sudo ##\nsudo ss\n## Display all listing ports ##\nsudo ss -l\nsudo netstat -tulpn\nsudo netstat -tulpn | grep LISTEN\n\u00a0\n## Display all TCP sockets\nsudo ss -t -a\n\u00a0\n## Display all UDP sockets.\nsudo ss -u -a\n\u00a0\n## List all open files\nlsof | more\nlsof | grep something\nlsof \/dev\/sda2\nlsof \/path\/to\/file\n<\/pre>\n<h2>Display the list of running services<\/h2>\n<p><code>### SYS V ###<br \/>\n$ sudo service --status-all<\/code><br \/>\nOR<br \/>\n<code>## UPSTART ##<br \/>\n$ sudo initctl list<\/code><\/p>\n<h3>Find out if service is enabled:<\/h3>\n<p><code>## UPSTART ##<br \/>\n$ sudo initctl status service-name<br \/>\n$ sudo initctl status smbd<\/code><br \/>\nOR<br \/>\n<code>## SYS V<br \/>\n$ sudo service serviceName status<br \/>\n$ sudo service nginx status<\/code><\/p>\n<h2>View log files<\/h2>\n<p><code>$ cd \/var\/log<br \/>\n$ ls -l<br \/>\n$ tail -f \/var\/log\/fileName<br \/>\n$ grep 'something' \/var\/log\/fileNameHere<\/code><\/p>\n<h2>Find file by name<\/h2>\n<p><code>$ locate fileName<br \/>\n$ locate htpasswd<br \/>\n$ locate passwd<br \/>\n$ locate my.resume.doc<\/code><\/p>\n<h2>Find file by given condition<\/h2>\n<p><code>$ find {\/dir\/to\/search} -name {file-to-search} -print<br \/>\n$ find \/etc\/ -name \/etc\/passwd -print<br \/>\n$ find $HOME -name '*.doc' -print<\/code><\/p>\n<h2>View user account details<\/h2>\n<p><code>$ less \/etc\/passwd<br \/>\n$ grep userName \/etc\/passwd<br \/>\n$ getent passwd<\/code><\/p>\n<h2>View group account details<\/h2>\n<p><code>$ less \/etc\/group<br \/>\n$ getent group<br \/>\n$ grep group-name \/etc\/group<br \/>\n$ groups userName<\/code><\/p>\n<h2>View password policy<\/h2>\n<p><code>$ chage -l userName<br \/>\n$ chage -l root<br \/>\n$ chage -l vivek<\/code><\/p>\n<h2>View system usage<\/h2>\n<p><code>$ sudo top<br \/>\n$ sudo htop<br \/>\n$ sudo atop<br \/>\n$ sudo ps auxwww<br \/>\n$ sudo netstat [options]<br \/>\n$ sudo iostat<br \/>\n$ sudo mpstat 1<br \/>\n$ sudo sar [options]<\/code><\/p>\n<h2>Trace system call<\/h2>\n<p><code>$ strace -o output.txt \/bin\/foo<br \/>\n$ strace -p 22254 -s 80 -o debug.nginx.txt<\/code><\/p>\n<h2>Trace library call<\/h2>\n<p><code>$ sudo ltrace \/usr\/sbin\/httpd<br \/>\n$ sudo ltrace \/sbin\/chroot \/usr\/sbin\/httpd<\/code><\/p>\n<h2>View process info<\/h2>\n<p><code>$ sudo pstree<br \/>\n$ sudo pstree | less<br \/>\n$ sudo ps auxwwwm<br \/>\n$ ps alxwww<br \/>\n$ ps auxwww<br \/>\n$ lsof -b M -n -l<\/code><\/p>\n<h3>Change process priority<\/h3>\n<p><code>$ sudo \/bin\/nice -n -1 command-name-here<br \/>\n$ sudo \/bin\/nice -n -1 pid<br \/>\n$ sudo renice {priority} pid<\/code><\/p>\n<h3>View process&#8217;s CPU affinity<\/h3>\n<p><code>$ sudo taskset -p {pid-here}<br \/>\n$ sudo taskset -p 42<\/code><\/p>\n<h2>Display the system listing of all package installed<\/h2>\n<p><code>$ dpkg -l<br \/>\n$ dpkg -l | less<br \/>\n$ dpkg -l nginx<\/code><\/p>\n<h2>Display the system listing of all patches installed<\/h2>\n<p><code>$ sudo apt-show-versions -a | grep -i \"security\"<\/code><\/p>\n<h2>Display the list of needed runtime libraries to run file<\/h2>\n<p><code>$ ldd file<\/code><\/p>\n<h2>Find what package a file belongs to<\/h2>\n<p><code>$ dpkg -S \/path\/to\/file<br \/>\n$ dpkg -S \/bin\/ls<\/code><\/p>\n<h2>Create a backup list of all installed software<\/h2>\n<p><code>$ sudo dpkg --get-selections &gt; \/root\/installed.pkgs.txt<\/code><br \/>\nWant to restore it again?<br \/>\n<code>$ sudo dpkg --set-selections &lt; \/root\/installed.pkgs.txt<\/code><\/p>\n<h2>Display the system firewall configuration<\/h2>\n<p><code>$ sudo iptables -L -n -v<br \/>\n$ sudo ufw status numbered<br \/>\n$ sudo ufw status verbose<br \/>\n$ sudo ufw app list<\/code><\/p>\n<p>Do not forget to read man pages featured in this post:<br \/>\n<code>$ man dpkg<br \/>\n$ man htop<br \/>\n$ man ...<\/code><\/p>\n<p>Finally, make a backup &#8211; it cannot be stressed enough how important it is to make a backup of your system. A good backup plan allow you to recover from disk failure, accidental file deletion, file corruption, or complete server destruction, including destruction of on-site backups.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Find the system host name Display the system&#8217;s host name: $ hostname $ cat \/etc\/hostname server1 Display the system&#8217;s DNS domain name: $ dnsdomainname cyberciti.biz Display the system&#8217;s Fully Qualified Domain Name (FQDN): $ hostname&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-403","post","type-post","status-publish","format-standard","hentry","category-he-thong"],"_links":{"self":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/403","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/comments?post=403"}],"version-history":[{"count":0,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/posts\/403\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/media?parent=403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/categories?post=403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.asianux.org.vn\/index.php\/wp-json\/wp\/v2\/tags?post=403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}