Saturday, April 20, 2013

How To: Gather information about your pc using the Linux command line.

Today I will show you how to use the Linux command line to find out all sorts of stuff about your PC hardware and software. There is also a bash script at the bottom of this post that will run all of these commands and save the information into a folder in your home directory and then create a archive of all the files.

Most of these commands should already be installed on your system however lm-sensors and hddtemp you probably need to install. I'll tell you how to install them when we get to them.

Right then on to the list.

sudo dmidecode

The command dmidecode gives you a lot of information about your PCs hardware which is read from the PC's BIOS. While not 100% reliable it's a good way to find out the more obscure stuff about your PC hardware. More information on dmidecode can be found here:

sudo lspci

The lspci command lists all the PCI buses and devices connected to your PC, This can include USB controllers, The IDE controller, The SATA controller, As well as all the PCI/PCIe cards you have installed.

sudo lsusb

Similar to the lspci command the lsusb command lists all USB devices connected to the computer.

uname -a

This command displays the name of the PC, the kernel version, the date and time and architecture of your PC.

sudo lsmod

The command lsmod displays all the kernel modules that are currently loaded on your computer.

sudo fdisk -l /dev/sda

This command displays information about your hard drive like size, partitions and the file systems on the partitions as well as a few other details. Note that you may need to change the sda part depending on what type of hard drives you have as well as how many hard drives you have. Use the next command to find out the names of your hard drives.

df -hT

Similar the previous command this one lists all the filesystems mounted on the computer. This command is a good way to find out what your hard drives are called on Linux.

ifconfig -a

This command displays information about all the network interfaces active on your PC. Handy if you are setting up a network connection.


The command uptime displays the current time, how long the computer has been running, how many users are logged on and the load average for the past 1, 5 and 15 minutes.

echo $PATH

This command displays the contents of your $PATH variable. This is basically a list that the system uses to find executables when you call a command (like echo for example) so you don't have to go to the directory where the executables are before executing them.

To install the last two commands simply type this into a terminal:

sudo apt-get install lm-sensors hddtemp

And type in your password when prompted. Now you can use the "sensors" command and the "hddtemp" command. before you can use the "sensors" command you need to run:

sudo sensors-detect

This command scans your computer for any sensors it can find. It will ask you whether you want to scan for different types of sensors. Say yes to all these questions. When it's done it will show a list of drivers that are needed for the sensors that it finds. It will ask if you want to add these drivers to your "/etc/modules" file. Say yes here. Now you can run the sensors command:

sudo sensors

The sensors command displays the temperatures of all the temperature sensors as well as the RPM speed of any fan speed sensors.

sudo hddtemp /dev/sda

As the name might suggest this command displays the temperature of all the hard drives connected to your computer. As with the fdisk -l command you may need to change the sda part depending on what type of hard drives you have as well as how many hard drives you have. Use the df -hT command to find the names of your hard drives.

Finally here is that bash script that will run all of these commands and put the output of each of the commands into a file and put all of those files into a directory called PCinfo in your home folder. It will also create a .tar archive in the directory that the script is with all the files in.

I've also added a few commands that copy the syslog, apport.log and kern.log files as well as the fstab file into the PCinfo folder as well as these can also be useful for finding information about the Linux system.

Again where hard drive names are just simply replace them with your own. I may improve this at some point so if I do I'll try and remember to edit this post to update it as well as post it separately.

To use this bash script simply copy the following code and paste it into a empty text file and save it. Then you just need to allow it to be executed, To do this go to the directory the script file is in in a terminal and type this in:

chmod 755 PCinfo

Hit enter and it should now be able to be executed. What follows is the bash script:


mkdir ~/PCinfo

sudo dmidecode > ~/PCinfo/dmidecode

sudo lspci > ~/PCinfo/pci_devices

sudo lsusb > ~/PCinfo/usb_devices

cp /var/log/syslog ~/PCinfo/

cp /var/log/apport.log ~/PCinfo/

cp /var/log/kern.log ~/PCinfo/

sensors > ~/PCinfo/sensors

uname -a > ~/PCinfo/uname

sudo lsmod > ~/PCinfo/lsmod

sudo fdisk -l /dev/sda > ~/PCinfo/disks

sudo hddtemp /dev/sda > ~/PCinfo/hddtemp

cp /etc/fstab ~/PCinfo/

df -hT > ~/PCinfo/disk_info

ifconfig -a > ~/PCinfo/network_info

uptime > ~/PCinfo/uptime

echo $PATH > ~/PCinfo/PATH

tar -cvf PCinfo.tar ~/PCinfo