[LINUX HOW-TO] Usefull terminal commands !
#1
For many years i've been fidling around learning
ubuntu/linux and came around quite a good deal of usefull
commands. I wanted to make a register of my most used terminal commands
when fidling with problems in ubuntu/xbmc

IMPORTANT: Linux is CaSe sensitive so if a you e.g type in
the command Df -h nothing will happen because
the command is df - h with lower case characters. The same
applies to directories and files.

A nice general guide to the linux bash world:
http://ubuntuforums.org/showpost.php?p=3...ostcount=1

How to get into the linux terminal ?
U can do this 2 ways. The first is by using your local
keyboard and tv directly. If you have xbmc on the screen
you cant press CTRL ALT F2 to open a bash window
To get back to xbmc you can hit CTRL ALT F7

The way i prefer to do it is by logging into my linux box remotely
from my windows laptop. Both your xbmc box and laptop must be on the same subnet to get it working:
Download putty, it's a small free SSH/Telnet client
http://www.chiark.greenend.org.uk/~sgtat...nload.html
Get the version that matches your windows build

When installed open putty.exe and type in your xbmc box ip adress
and port 22. Save it for later use by hitting the save button (create a name for the connection in the saved session field first)

Load your XBMC saved session by double clicking it from the list
You should now be greeted with a terminal window asking you for a password


General info commands
(does not change anything and should be harmless)


Check Disk Space:
Code:
df -h

Check what linux distro you are using:
Code:
lsb_release -a

Check what linux kernel you have:
Code:
uname -a

Get info about a package installed:
Code:
dpkg -s xbmc

List all usb devices connected:
Code:
lsusb
Code:
lsusb -v

To generaly test your sound using aplay:
Code:
aplay /usr/share/sounds/alsa/Front_Center.wav
aplay /usr/share/sounds/alsa/Front_Left.wav
aplay /usr/share/sounds/alsa/Front_Right.wav
aplay /usr/share/sounds/alsa/Rear_Center.wav
aplay /usr/share/sounds/alsa/Rear_Left.wav
aplay /usr/share/sounds/alsa/Rear_Right.wav
aplay /usr/share/sounds/alsa/Side_Left.wav
aplay /usr/share/sounds/alsa/Side_Right.wav
aplay /usr/share/sounds/alsa/Noise.wav

More Speaker Testing:
Code:
speaker-test -Dplug:surround51 -c6 -l1 -twav

List your soundcard device:
Code:
cat /proc/asound/cards
Code:
aplay -l

List out all hardware detected:
Code:
lspci -v | less

Get all boot-time kernel logging for a system:
Code:
dmesg | less

Same as above but also with timestamps:
Code:
less /var/log/kern.log

To see what version of nvidia drivers installed:
Code:
dpkg --status nvidia-current | grep Version | cut -f 1 -d '-' | sed 's/[^.,0-9]//g'

Basic terminal commands:

To run a command with superusers privileges:
Code:
sudo "command"
where "command" is any command you might want to run
with elevated priviliges

If you need to do extensive work as root you can do the following:
This way you keep your current users bash config and history
Code:
sudo -s

Or you can change to root user all together:
Code:
sudo su

Be warned though, running commands inside a terminal
with root privileges is a fast way to fubar your system !!

More info about sudo:
https://help.ubuntu.com/community/RootSudo

To return to your current users home directory from anywhere:
Code:
cd ~

To list content of a folder:
Code:
ls

To navigate to a folder:
Code:
cd /etc/X11
This will take you to the X11 folder inside the etc folder

Edit files:
Code:
nano /etc/X11/xorg.conf
This will open xorg.conf for editing. To close nano without
changing anything hit CTRL X

To create new file:
Your home dir is located under /home/"your username"
On a standard xbmc live install if you logon in the terminal as user xbmc your homedir is /home/xbmc
In my examples i use /home/xbmc

Code:
nano /home/xbmc/mytestfile.txt
This will create a text file called mytestfile.txt under your home dir.
Type in something in the file and hit CTRL X and nano will now ask
if you want to save changes - select Y and ENTER
The file is now saved.

To delete a file:
Code:
rm /home/xbmc/mytestfile.txt

To create a directory:
Code:
mkdir /home/xbmc/testdir
Will create "testdir" in your home directory.

To remove a directory and all files subdirs:
Code:
rmdir /home/xbmc/testdir

To start/stop a program:
Code:
service xbmc stop
Code:
service xbmc-live stop
Code:
service xbmc start
Code:
service xbmc-live start

Another way to force a program to shutdown is by using the kill command:
Code:
sudo kill -9 `pidof xbmc.bin`

To check your wired network info:
Code:
ifconfig

To check your wireless network info:
Code:
iwconfig

To scan wireless networks:
Code:
iwlist scan

To restart the network:
Code:
/etc/init.d/networking restart
If you made changes to your network config you need
to restart networking services. It will also renew your dhcp leases

Turning Network interfaces on/off
Sometimes when troubleshooting it can be handy to quickly take network interfaces up/down
to reinitialize the interface
Usually your wired network adapter will be "eth0" and your wirelss netowrk adapter will be "wlan0"
You can use the iwconfig to get a valid list.
Code:
iwconfig eth0 down
Code:
iwconfig eth0 up
Code:
iwconfig wlan0 up
Code:
iwconfig wlan0 down

To shutdown your linux box:
Code:
sudo halt
or
Code:
sudo shutdown -h now

To reboot your linux box:
Code:
sudo reboot

Usefull commands:
Warning these commands can change your system
so do not run them unless you need to. Use it as a refference only !


To update/upgrade your installed packages:
Code:
sudo apt-get updates
Code:
sudo apt-get upgrade
This will upgrade all packgages to latest version. Sometime
this can break functionallity so be carefull !

To update/upgrade specific package:
Code:
sudo apt-get install xbmc
Code:
sudo apt-get install xbmc-live
This will check of you have the latest version
and if there is a newer version it will ask you if you want to upgrade.

To uninstall a package:
Code:
sudo apt-get uninstall xbmc
Code:
sudo apt-get uninstall xbmc-live

To completely remove a package and all dependencies:
Code:
sudo apt-get --purge remove xbmc
Code:
sudo apt-get --purge remove xbmc-live
This will also remove all dependencies and might seriously break functionality !

Another way to remove packages can be:
Code:
sudo dpkg --purge xbmc
Code:
sudo dpkg --purge xbmc-live
Can be handy if something remains from an uninstall.

To free up disk space and get rid of left behind packages:
Code:
sudo apt-get autoremove
Code:
sudo apt-get autoclean
This will clean up temporary files and should not be dangerous to use.

To search for a package:
Code:
apt-cache search xbmc
This will give you all available packages that contains the word "XBMC"

To fix broken installs/packages:
Code:
sudo apt-get install --fix-broken
Code:
sudo dpkg --configure -a
This will try to fix broken packages in your system.

To upgrade your current linux distro to a newer version:
Code:
sudo apt-get dist-upgrade
This is a dangerous command and can break your install so do be carefull
and make backups of anything imporant. I have done this a few times
with no problems, however this is not always possible depending on your config/setup


Okay this is what i currently remember from my head, i will ad more
if i see something is forgotten. And as always any input to my list
is welcome ! Also please report if you find something you don't like
or if you have any commands you think should be here Smile
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#2
In this section i will add usefull tips & tricks to make your xbmc life a little easier:

Tip1: (thanks to forum user MacUsers !)
Create a auto restart command for xbmc:

First of all make sure you have proper rights to perform the command:
Code:
sudo su
Then create a xbmc-restart command:
Code:
printf '#!/bin/bash\nkill -9 `pidof xbmc.bin`' > /usr/local/bin/xbmc-restart
Make it executable:
Code:
chmod +x /usr/local/bin/xbmc-restart
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#3
sudo nano mkdir /home/testdir

there is one nano too much
Reply
#4
HeHe, indeed you are right, fixed !
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#5
I would add also:
aplay
dmesg
lspci
Reply
#6
Good idea, i added them Smile
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#7
For a keyboard less setup, restart XBMC with this:
Code:
kill -9 `pidof xbmc.bin`
For the convenience, create a file, as root user, with name something like: xbmc-restart in the "/usr/local/bin" and make it executable.
Code:
printf '#!/bin/bash\nkill -9 `pidof xbmc.bin`' > /usr/local/bin/xbmc-restart
chmod +x /usr/local/bin/xbmc-restart
NOTE, the single quote [' ...'] in the printf line, otherwise it will not work. Then just use (as whatever user):
Code:
xbmc-restart
to restart xbmc when it keeps you hanging on at the black screen. Cheers!!
MINIX NEO U22-XJ | Denon AVC-X3800H | KEF Q750 | KEF Q150 | KEF Q250c | KEF Q50a | KEF Kube 10 MIE | LG OLED65G16LA | CoreELEC
Reply
#8
Thanks for the tip MacUsers, i found it very useful so i have added
it to the Tips section !
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#9
why on EARTH are you advertising running commands that deletes a file in your home directory as the super userHuh?

also last time i checked, /home is nobody's home directory Smile
Reply
#10
@The-Boxhead

Many thank's for your 'tips and tricks' when using Linux, I'm sure many of these commands will be invaluable to some of our users.

To follow up a little on what spiff was saying, most of your commands are 'abusing' the use of "sudo" especially when creating and editing files in your home directory (which would usually be /home/myusername/) then you as their owner already don't require super user privileges to delete. I think the reason your having to use sudo, is because your trying to add and delete files from the parent folder of your home directory, i.e. /home/

Generally speaking, this isn't a good place to be saving files, its a bit like saving directly to C:\Documents and Settings instead of C:\Documents and Settings\Malard

Could I ask that you up date your posts taking on board these thoughts?

Also, I'm sure other linux users far more knowledgeable than myself will be able to offer some improvements or ideas of other commands that people might find useful!

Thanks
Reply
#11
@Malard and Spiff:

Thanks for your input. Yes offcourse my references to home dir
as simply /home is wrong. I have now fixed this.
I have also removed sudo from many command examples since
they are not needed and is prolly abuse, yes Wink

Thanks for you input guys, much appreciated. I am not a linux expert
so getting input from experienced user are very valuable !

If anyone still thinks my post contain errors or breaks linux best practice rules
please inform me and i will try to fix it !
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#12
Star 
This has been one of my most difficult problems, when writing how-tos its exactly not to tempt the "idiot" gene... a Impossible task for anyone, this is because the more and better you try, nature comes up and makes a better "idiot".

So having said that you posted...

Code:
sudo apt-get dist-upgrade
Invariably upgrading a distro breaks something, this tempts the "idiot" gene a great deal, this command should come with a BIG disclaimer and or warning. This considering some % of users will have XBMC installed and alsa and lirc...IDK just my point of view.

Another thing is the command to run xbmc-live or stop xbmc-live
Code:
sudo start xbmc-live or sudo stop xbmc-live
also works. Because I run as root for admin/maintenace compile/install purposes basically because "I hate entering sudo", sudo may be redundant on these idk. Honestly these dont work for me without sudo or being root. But everything works OK XBMC wise and as expected.

I have a few commands that I found invaluable and thought sharing would help your list... here's is what I rustled up in my insanity.

If having lm-sensors installed you need to configure it and get results...
Code:
sensors-detect
This goes through the detections of supported sensors and drivers used on your system and file writes to file, requires some user input.
Code:
sensors
Displays the temperatures of all devices detected by sensors-detect
Code:
sensors -s
After any modification to sensors config file this enables new configuration. Can be run before or after the sensors command...
Code:
sudo modprobe "driver"
This temporarily loads a driver or kernel module into current session for e.g. ic2-dev
Code:
echo "driver" >> /etc/modules
Inserts driver or kernel module so it is loaded after reboot automatically.
Code:
sudo dkms add -m driver-name-src -v 1.0.0-ubuntu
Add a drivers source and version into dkms tree (helpfull to have it build automatically after a kernel upgrade. 1 0f 3
Code:
sudo dkms build -m driver-name-src -v 1.0.0-ubuntu
Part of previous only this builds the driver source so it becomes ready to be installed. 2 of 3
Code:
sudo dkms install -m driver-name-src -v 1.0.0-ubuntu
Again part of previous this one actually installs driver and makes it immediately available. 3 of 3
Code:
lsmod
Show info about all loaded drivers into current session.
Code:
sudo dpkg -i filename.deb
Installs a .deb file manually
Code:
sudo dpkg -i --force-overwrite filename.deb
Helpful when theres problematic .deb's which refused installing and may cause broken pipes failed configurations of packages preventing installation.
Code:
sudo dpkg --configure -a
Usually issued to finishing configuration of unconfigured packages (worth mentioning in conjunction with previous)
Code:
wget -n -q http://linktofile.com
Grabs a file with no visible output on terminal from any destination.
Code:
sudo chmod +x filename.extension
Makes a file executable though there is no need for a file extension for executable files in Linux (because Linux is great that way) usually executable files come in form of scripts e.g. filename.sh or .run packages though this is hardly a rule.
Code:
sudo ./filename.sh
sudo ./filename.run
sudo sh filename.sh
sudo sh filename.run
Runs or executes a script or .run package some scripts don't like being executed with either one or the other (usually errors out perhaps because of syntax), for this reason I found it worth mentioning this and both methods, even though script writers will let users know how to execute them.
Code:
sudo chown user:user /dir or filename
Changes owner of a directory from root:root to user:user to be used carefully, usually running this may cause failures if your modifying a /dir or filename ownership that shouldn't be modified. Dangerous command if you dont know what your doing, but helpful if you do know. This also tempts the "idiot" gene.
Code:
sudo chown user -R /dir
this changes ownership recursively not only of a directory but everything inside that directory. Dangerous command if you don't know what your doing, but helpful if you do know. This also tempts the "idiot" gene.

lshw cat /proc/cpuinfo lspci lshw -class network cat /proc/ioports cat /proc/iomem cat /proc/interrupts

Those are old commands and their respective results useful in some cases I will expand on them when I can, I dug them out of a very old post when I was 1 month into learning about the wonders and curses of Linux running jaunty on my trusted and pain in the ass Asrock ION HT 330. Basically it was meant to compare how similar ION gen 1 systems are, because they were all built by Pegatron a hardware manufacturer for the first year or two. Though to determine the similarity one had run and compare the results.

Heck the list goes on I think covering all useful commands in a thread could go on forever but I find this helpful for novices that actually are curious and want to learn about Linux. I think its a good idea even if not a new one.

Note: The use of "idiot" gene - not meant as offensive to anyone in particular but it accurately describes a widely known phenomenon. Usually associated with PEBKAC no one is immune and no known cure exists.

Note: Some of the commands I posted are dangerous indeed so when in doubt have a full system backup/image before any tinkering... This is probably the most valuable tip to prevent a massive waste of time and prevent full system reinstalls.

hope some of these commands help others same way they have helped me understand a little about Linux.

I still am a massive n00b at Linux but I try and never totally given up, persistence is key.

It only took me 4 hours to write this post... Shocked and even after double triple checking I have this feeling something is missing... ah the joys of sleep deprivation.

cheers.
Reply
#13
wow, great post X3lectric !

I have many of the same thoughts as you conerning writing how to's.
So i agree totally on have difficult it can be to not do more damage than good Wink

Im gonna try and take your thoughts into my org post and write
some warnings and tips. This command reference is not something i wrote
to use as a sollution, it's more a reference\toolbox that one can use when working with problems, instead of messing around on different forums each time you forget a command you know you need !

I'm gonna add your commands to the org post with your comments if it's ok ?

And yes the dist upgrade command should have a bigger warning i agree !!
Maybe i should collect all commands regarded potentially dangerous to it's own list and the safe commands to it's own list. I regard all commands that involves only listing out info as safe...
PointOfView Nvidia ION Atom 330 - TRANSCEND 2GB DDR2 DIMM 800MHz - G.SKILL 64GB SSD 2.5
Open Elec Beta4 1.95.4
XBMC Online Manual - HOW-TO post about a problem in a useful manner - Create/View Bug Report
Setup/Fix correct resolution on XBMC/Ubuntu - Usefull linux terminal commands
Reply
#14
Thumbs Up 
The-Boxhead Wrote:snip

Im gonna try and take your thoughts into my org post and write
some warnings and tips. This command reference is not something i wrote
to use as a sollution, it's more a reference\toolbox that one can use when working with problems, instead of messing around on different forums each time you forget a command you know you need !

I'm gonna add your commands to the org post with your comments if it's ok ?

snip

Yes sure go ahead, merge away. Big Grin There is no one post anywhere on net that has all useful commands with vaguely user friendly explanations never mind ones with a warning. I get why you started this post, I feel your pain... Sad

Another pain is you'll soon find the 10k per post forums character limit, will force break the continuity/fluidity of this how-to is somewhat lost... I dont see you presaved ~5 posts on the conservative side for the half desired effect and target audience.

/me kicks the forum management to "fix" this limitation. Rolleyes This is to posting how-tos, what loosing your hard-on is to sex. cof (tumbleweed and a woosh of air)

On the dangerous commands I agree BIG warnings, heck cant make them big enough. And definitely a "segregation" of the most likely commands to cause a a potential disaster vs the safe ones.

for e.g. when you upgrade a kernel and once you are sure everything is ok with new kernel no need to keep old kernel, so I often purge the old kernel, however the dirs in usr/src and /lib/modules/ mostly remain so to remove them the usual command need to be issued.
Code:
sudo rm -rf /dir
again this is a useful command but a typo and bam you may just reboot and find your system is borked.

This is why my recent how-tos start with a strong suggestion to backup/image before tinkering, usually ignored and ppl never learn.

You wont find me doing anything unless I have a backup/image of the working system. backing up also not same as a hdd image which does not need to be a sector by sector.

This is a valuable how-to, but like all how-tos and posts these days should come with a BIG disclaimer... Eek ridiculous but true... but I digress.

Sorry for the slight rambling Off-T

cheers The-Boxhead keep it up...
Reply
#15
Apologies for resurrecting this thread, but it was the closest I could find to answer a question I have regarding SSH'ing and in particular PuTTy.

If I log into my Raspberry Pi running OpenELEC 4.2.1, then run this:

Code:
xbmc-send --action="UpdateLibrary(video)"

The library updates as expected, then I'd like to run:

Code:
xbmc-send --action="exportlibrary(video,true,true,false,true)"

The problem I'm having is knowing WHEN to run the 2nd command, is there anyway to get some kind of notification of when the library has finished updating? tail perhaps?
Reply

Logout Mark Read Team Forum Stats Members Help
[LINUX HOW-TO] Usefull terminal commands !0