portallinux → useful_findings.htm   This is a windrose

Useful findings   (Solving problems)

GNU/Linux

...shortcuts, ...useful commands, ...tricks



GNU/Linux Related Sections
 

Poser

Version 0.09: March 2009


Introduction

How often do we have "to go back to the web" in order to solve for the nth time a small problem we keep encountering? Well, it happens to me all the time, so I have assembled in this section a series of "useful tricks" (and commands) that have been useful to me in many circumstances. Thattaway I may even remember them :-)

You'll take full advantage of the following -rather eclectic- section only if you have already some knowledge of the GNU/Linux operating system (here, more specifically, the Gnome-oriented and Debian-based Ubuntu distribution).
Some of the commands listed here are self-explanatory, some are not; some are well-explained, some not. I'll modify, add, correct and remove stuff au fur et mesure.
Readers' contributions (and/or corrections) are always welcome.

Various commands and tricks
1st: decide the terminal dimensions     ••     being root for a while     ••     knowing your version
knowing your temperature     ••     Cleaning processes     ••     Preparing avi for TV
history marvels     ••     sound problems     ••     Debugging



1st: decide the terminal dimension
The terminal in GNU/Linux is a cosmic weapon. You better have it as perfectly honed as possible.
Check with the followinbg command in order to see if setting dimensions works at all:

gnome-terminal --geometry=180x28+6+52
(180x28 = dimensions; 6/52 = coordinates) if you want to use this as default from now on, then:
System => Preferences => Preferred Applications => System
terminal emulator = Custom
Command (for instance) = gnome-terminal --geometry=180x28+6+52



being root for a while
I much prefer Ubuntu (and Mac OS X's) sudo model to the root/user one typical of most Linux distributions. However at times you get fed up with your terminal asking once more for your password.
As usual (with any good operating system) there are various commands to get -and remain- root:

  1. sudo -s (HOME in previous user)
    echo $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
  2. sudo -i (HOME in root)
    echo $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
  3. sudo su - (HOME in root)
    echo $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  4. sudo su (HOME in root)
    echo $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
  5. sudo bash (HOME in previous user)
    echo $PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin
(and then CTRL+d, or exit to exit root)

In fact there are many other options to get root:  ! Please remember that being root all the time in a GUI environment is insane and bound to harm you soon or later.
However there are moments where you know (or rather you think you know) what you are doing, and in those (rare) cases you might enjoy being root without sudo timeouts.

Alternatively you can modify the TIMEOUT parameter and change the default 5 minutes to a longer period (in minutes): use sudo visudo (which is the safe way, using nano) and modify your /etc/sudoers.
If there's no 'Defaults' line, add a line with the parameter passwd_timeout to the file: Defaults passwd_timeout=10 and all users that can sudo will have 10 minutes root instead of 5. Limit to yourself with Defaults:mynick     passwd_timeout=10.
If there's already a 'Defaults' line there, just add the parameter passwd_timeout after a comma:
Defaults !lecture,!fqdn,passwd_timeout=15.

Note that
sudo -L
will show you all the possible options for Default. Alternatively: sudo -L | grep timeout

Anyway, there should be no need to explain you that adding either of both
timestamp_timeout=-1
timestamp_timeout=0
in order to allow being root for the whole session would be nonsensically insane :-)

Finally it should be recalled that sudo's timeout exists to avoid forcing users to type their passwords more than once for sequential commands, all of which start with "sudo...", because in principle, asking for passwords too often is insecure, NOT because of convenience for the users.

Another, different, method is allows an "unpassworded" use of a list of selected commands through the = NOPASSWD parameter, using sudo visudo and adding to the /etc/sudoers file (supposing your username is "me" and your box's hostname is "mybox") a line like:
me mybox = NOPASSWD: /bin/kill, /bin/ls
As you can see there is a list of the available commands that "me" can access using sudo without any need to enter a password; these commands are separated by commas.

More generally, still supposing your username is "me",
sudo ls --full-time /var/run/sudo/me/
is a useful command that will give you the number of the valid sudo tickets for "me".


Cleaning processes
There are many ways to check the active processes, apart from top and lsof, the following ps commands:
ps
ps -au
sudo ps -aeu
sudo ps -A
ps axu | less
will give you different lists (snapshots) of current processes; ps -au will for instance give you all the pts ("pseudo-terminal slaves").

Often useful is the "visual" representation:
pstree -a


While...
tty
...shows which pts we are on.

Anyway, now that we have the processes, we can "clean the system" killing them, using option 9: if the process you want to terminate is -say- PID 5520:
kill -9 5520

Related to this, there's a wondrous little graphic utility that allows you to see at once who is using most memory on your system: in fact it shows you the relative proportions of memory used by running processes (updated in real time).
By all means do install gmemusage (sudo apt-get install gmemusage), a very useful graphical memory usage viewer.
Of course, once you have individuated a particolarly program that "hogs" memory, you might want to get more information using something like -say-

lsof | grep opera

or,
lsof -c ope

Whereby you can also check the memory map of a given process -say- 17518 (find out with top),

pmap 17518 or pmap -x 17518




Preparing your avi for TV usage
This is about how to create VCDs starting from your AVI files. In our example we create a VCD, starting with myown.avi, that we transform first into a mpeg format (using ffmpeg) and then into vcd.bin & vcd.cue (using vcdimager). This we can then burn onto the CD (using cdrdao).

To prepare your avi file for burning, just use the commands ffmpeg (first) and vcdimager (next).
(if necessary install both commands first: sudo apt-get install ffmpeg and sudo apt-get install vcdimager)
ffmpeg -i myown.avi -target pal-vcd myown.mpg
You can of course choose ntsc-vcd instead of that pal-vcd, depending on your location and on your TV-box settings.
ffmpeg is an incredibly powerful and versatile application, just have a look at its manual pages: man ffmpeg.
In fact a variant of the previous command could be
ffmpeg -i myown.avi -y -target pal-dvd -sameq -aspect 16:9 myown.mpg
"-sameq" means "Same Quality". Meaning it will convert the video as the exact same quality as the original.

Now let's port the mpg we have obtained to a vcd.cue/vcd.bin
vcdimager -t vcd2 -l "MYOWN" -c vcd.cue -b vcd.bin myown.mpg
Then put a new CD into your cd-writer and launch cdrdao:
(if necessary install cdrdao first: sudo apt-get install cdrdao)
cdrdao write --device /dev/cdrw vcd.cue
You can quickly check if the resulting VCD works using the command
mplayer vcd://2
(or mplayer vcd://1 or mplayer vcd://)


knowing your version
There are many ways to check your kernel, ubuntu and gcc versions:
lsb-release -a
cat /etc/lsb-release
cat /proc/version
Note that the files in the /proc directory are not real files, they are hooks to look at information which is available to the kernel
So if you want to check & get info on your CPU(s):
cat /proc/cpuinfo
cat /proc/interrupts
There is also:
cat /etc/debian_version
This last command underlines the "paternity" of Ubuntu :-)




knowing your temperature
There are basically TWO ways to check your CPU's temperature.

You can either use the acpi motherboard monitor(s):
cat /proc/acpi/thermal_zone/THRM/temperature
acpi -t
acpi -V
Or install an ad hoc program that will read the CPU sensor(s): sudo apt-get install lm-sensors (and then sudo sensors-detect, answer yes to everything).

How does this work? Motherboards' manufacturers define one or more ACPI thermal zones, centered on a temperature monitoring device that sits on the motherboard (http://www.acpi.info/spec.htm). But there's also a "coretemp reading", that comes from a temperature sensor embedded inside the CPU (http://www.debianhelp.org/node/5156).
Most geeks trust the coretemp values more, being more confident in the true position of the temperature they provide (and don't really know where on their motherboards the temp monitors are).

It can happen: you have installed the sensors, but they will not work on your box.
In that case remove everything with
sudo apt-get remove --purge lm-sensors.
In fact sudo apt-get remove --purge is the "contrary" of sudo apt-get install.


history marvels
Find out what command lines you use most...
history | cut -b8- | cut -d' ' -f1 | sort | uniq -c | sort -rg | head
Your task is of course now, as a final gift to yourself, to explain what exactly happens through the command above :-)


sound problems
First check if you really have more than one card:
asoundconf list
Then repair your sound (this is a great general fixall for sound issues):
asoundconf reset-default-card
(or asoundconf reset-default-card PARAMETER, where "PARAMETER" is one of the cards given by the previous asoundconf list). and restart.

Other sound-related commands:
Does the system see the soundcards? And what is their respective number?
cat /proc/asound/cards

Show oss & alia
lsmod | grep snd

Show stuff
cat /etc/modprobe.d/alsa-base

Soundcards on your system
aplay -l
lspci -v
lspci | grep audio
lsmod | grep snd

"another program is blocking the soundcard" error
Launch...
ps au
...in order to check who's responsible, say "PID 32382", and then kill it...
sudo kill -9 32382


Should you choose OSS or ALSA drivers? Well, ALSA (Advanced Linux Sound Architecture) is free and standard for more recent GNU/Linuxes (>= 2.6.), with features such as full duplex, digital I/O and more.
OSS (Open Sound System) is free as well, and was the standard in more older GNU/Linuxes (<= 2.4), but has poor support for soundcards and features.

The recent "Hardy Heron" version of Ubuntu has introduced the pulse audio server. Strangely enough, when installing Hardy, the user is NOT automatically part of the various "pulse" groups, and so there is no sound until you manually join these groups.


Debugging (file-related)


For network debugging check the Searchers' tools, for file-related debugging there are many useful commands...
lsof | less -S
(A single open file can prevent a filesystem from being unmounted)
ps awxo pid,command | sort -n | head -10
(Sorting processes by PID indicates when and/or where an early process was started)
strace /bin/echo probeone
strace xmms
(Tracing system calls and signals is the sine qua non for debugging malfunctionings appz)
less /var/log/dmesg 
(To see what "dmesg" dumped into this file right after the last system bootup)

Other useful commands:
  1. dmidecode
    For instance: sudo dmidecode | grep bank
    "Get a rough idea on a pinch". Beware that DMI (Desktop Management Interface: a table provided by the BIOS) data have proven to be too unreliable to be blindly trusted: dmidecode does not scan your hardware, it only reports what the BIOS told it to. Still useful: some data present in the DMI table are unique, you will not find them anywhere else, this includes serial numbers, asset numbers, BIOS revisions. These are not things you can physically detect, so fetching the info from the DMI table is the way to go. This is used by the Linux kernel itself to uniquely identify motherboards.
  2. sudo biosdecode
  3. lshw
  4. hwinfo
  5. hwinfo | grep memory
  6. sysinfo         (has GUI)

cat var/log/syslog | grep -i dhclient 
This is a cat/grep example with dhclient as target example, but you can of course have "la totale" with less var/log/syslog or be inventive about your grepping, for instance:
cat var/log/syslog | grep 15:3 





Connection problems


For inexplicable reasons, sometime network manager has the blues and your wi-fi connection will not kick in. This is not to be confused with a slow connection, where the use of utilities like ping and mtr (mytraceroute) will show you the 'state' (or rather the speed) of your connection and help you trace eventual backbone problems.
Here you don't have any connection, or might might even have a connection to the router, but you still don't have access to the Internet.

I have always found very useful, in such cases, to connect my wifi card per hand. I am supposing here 1) that you have a open or a wep "protected" router (no wpa) and 2) that your wi-fi card is simply eth1. You should check first of all the info about your wifi-card with the command iwconfig (without any parameter) or with the command sudo lshw -class network, (and there, see "logical name"). Once you know if your wifi card is indeed eth1 (or something else), use the following commands in order to connect to the web "per hand":

down
sudo ifconfig eth1 down
release current lease just in case
sudo dhclient -r eth1
up
sudo ifconfig eth1 up
choose essid and connect
sudo iwconfig eth1 essid name_of_your_essid_in_quotes
give hexadecimal key (if needed)
sudo iwconfig eth1 key string_of_your_secret_key_in_hex_digits
or alternatively give password (if needed)
sudo iwconfig eth1 key s:password_in_ASCII
This should be enough.
You might add two extra commands:

sudo iwconfig eth1 mode Managed
sudo dhclient eth1

Finally check your wifi card and see your new assigned IP with the command lshw (list hardware):
sudo lshw -class network
Also check the various wifi access points around you:
iwlist scan
The name ifconfig comes from "interface configurator", while the name iwconfig comes instead from "interface wireless configurator"



"Must know" useful shortcuts (GNOME)
Don't "click around" like an headless windows chicken!
quicker than thou     ••     nautilus shortcuts &


quicker than thou
These might be so obvious, that I don't know if I should be blamed or, given the fact that they are so often underestimated, praised for my compilation:
ALT+F2
brings up the "run application" popup in gnome. Quicker than any "opening terminal" or "mousing around for icons" for launching a program you already know the name of.


NAUTILUS

You'll use nautilus a lot in Gnome, so it is good to remember how -say- alt+enter show the properties of the highlighted file.




(c) 3rd Millennium: [fravia+], all rights reserved, reversed, revealed and reviled