General Troubleshooting in Linux
Last Updated: Mon, Feb 9, 2009Hardware
Getting ram information
cat /proc/meminfo
or if you want to get just the amount of ram you can do:
cat /proc/meminfo | head -n 1
Another fun thing to do with ram is actually open it up and take a peek. This next command will show you all the string (plain text) values in ram.
sudo dd if=/dev/mem | cat | strings
Getting cpu info
Sometimes in troubleshooting we want to know what processor we are dealing with along with how much cpu is currently being used by our OS and programs. We can do this with these two commands.
cat /proc/cpuinfo
top
Check the temperature of your CPU
Keeping a computer within a safe temperature is the key to maintaining a stable system.
cat /proc/acpi/thermal_zone/THRM/temperature
List PCI and USB devices
To list all the PCI devices in your system issues the following command:
lspci
For USB use:
lsusb
Check out how much hard drive space is left
df -h
See what hard drives are currently detected
It is often times helpful to know what hard drives are connected to a system and what name was given them in the Linux directory. This info allows us to mount the hard drive and manipulate it.
sudo fdisk -l
Installed Programs
Packages
Ever want to find all the packages that are installed on your system? You can find all the packages and also find out why they are on your system. You can even determine what packages depend on them if any.
Find all installed packages
dpkg --get-selections | less
Find out why a packages is installed and what depends on it
aptitude why packagename
Find out where the package stores all of its files
dpkg -L packagename
Kill a process
ps -A | grep ProgramName
kill 7207
Miscellaneous
Go to a terminal
Ctrl + Alt + f3
return with, Ctrl + Alt + f7
Show all network connections
There are many great network scanners and assessment tools available for Linux but netstat is a very easy to use often a first step in troubleshooting network issues. We will leave the rest of the network tools for a later article as there is so much to cover.
netstat
List all files that are currently open on the system
This command will allow you to see all the files that are currently open on your system. Limiting the directory or coupling this command with grep is often useful for finding files that are still open restricting the ability to unmount a device. Lsof will also ouput the process id or PID. You can then kill the process using the kill command above.
lsof
Keep an eye on something for awhile
The watch command will repeat a command at a set interval (default 2 seconds) and output the response. This is useful for watching directories that change, watching hard drives fill up when a lot of data is being transfered, or using it with lsusb to watch for USB devices being plugged in.
watch ls
watch df -h
Find where a binary is stored and its libraries
Often times when running a cron command you want to include the absolute path to the command. Sometimes I run scheduled PHP tasks. This can be acomplished by using the ‘whereis’ command.
whereis php5
Logs
See if you have kernel boot issues
dmesg | less
For more logs just cd into the /var/log directory and start using, cat, less, tail, grep, find or any other tool to view and search.