[LINUX HOW-TO] Usefull terminal commands !

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
The-Boxhead Offline
Donor
Posts: 943
Joined: May 2005
Reputation: 17
Location: Norway
Post: #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
(This post was last modified: 2011-06-28 23:33 by The-Boxhead.)
find quote
The-Boxhead Offline
Donor
Posts: 943
Joined: May 2005
Reputation: 17
Location: Norway
Post: #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
(This post was last modified: 2011-06-27 22:03 by The-Boxhead.)
find quote
derechteversus Offline
Member
Posts: 58
Joined: Dec 2009
Reputation: 0
Post: #3
sudo nano mkdir /home/testdir

there is one nano too much
find quote
The-Boxhead Offline
Donor
Posts: 943
Joined: May 2005
Reputation: 17
Location: Norway
Post: #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
find quote
sushiban Offline
Junior Member
Posts: 13
Joined: Oct 2010
Reputation: 0
Post: #5
I would add also:
aplay
dmesg
lspci
find quote
The-Boxhead Offline
Donor
Posts: 943
Joined: May 2005
Reputation: 17
Location: Norway
Post: #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
find quote
MacUsers Offline
Fan
Posts: 407
Joined: Jun 2009
Reputation: 0
Location: London, UK
Post: #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!!

MONEUAL 320B | ASUS P5Q-VM | Core2Duo E6320 | GeForce GT220 | Kingston KVR 800Mz HyperX DDR2 4GB (2 x 2GB) | UJ-120 BD-ROM | Pioneer VSX-920-K | KEF KHT3005SE-W | Panasonic TH-37PV500B | Ubuntu 10.04 | XBMCbuntu [ v10.0, r35648 ]
find quote
The-Boxhead Offline
Donor
Posts: 943
Joined: May 2005
Reputation: 17
Location: Norway
Post: #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
find quote
spiff Offline
Grumpy Bastard Developer
Posts: 12,179
Joined: Nov 2003
Reputation: 82
Post: #9
why on EARTH are you advertising running commands that deletes a file in your home directory as the super userConfused?

also last time i checked, /home is nobody's home directory Smile

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
find quote
Malard Offline
Team-XBMC Developer
Posts: 400
Joined: Jul 2010
Reputation: 16
Location: Peterborough, UK
Post: #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
find quote
Post Reply