Linux CLI - Tips and Commands
Many commands in linux cannot be run as any user other than root (linux version of administrator user).
If you try to use a command and you get a response: "cannot find command". Try logging in as root.
You can run commands as root in a terminal without logging in to the desktop manager as root.
Different linux distributions do this in different ways but they are all fairly similar
Try one of these commands in a terminal (command line)
sudo su
su
su root
After these commands you will be prompted for the root password.
If this command completes succesfully you will be logged in as root (for this specific terminal session only)
If you close the terminal you will have to log in as root again
If you fail to enter the correct password you may need to reset it.
Try the command: passwd
As long as you dont have one set you will be able to set it with this command.
If you have a root password set you will need to provide it before you can reset it.
You can set some permissions and procedural files
to allow you to run root commands in a terminal without actually logging in as root.
I do not recommend this and will not explain the procedure
Some linux distributions also require that certain commands use a prefix of /sbin/ or /bin/
example: /sbin/ifconfig
or
/bin/ifconfig
Executable files that are not in the right folder will also have to run from the directory they are contained in.
command: man - linux stores manual entries for commands and programs that explain usage and sytnax
To view manual entries use the man command followed by the command or program
for which you would like to view the manual entry.
example: man mplayer
Unfortunately manual entries will not be available for many commands and programs.
Manual entries are hit and miss, if your lucky there will be one
To exit a manual entry just type q.
module - a module is the programming structure that allows linux to control hardware in a computer
Some hardware modules need to be compiled into the kernel which we will not be discussing.
The most recent distributions should have the best rates of hardware compatibity.
command: modinfo - gives information on a specific module (if available)
example: modinfo lp
This command would hopefully give the function and syntax of the lp module.
command: lsmod - this command will list the modules that are currently loaded in the system
(very usefull command for hardware troubleshooting)
command: modprobe - either loads a module or alters its functionality through additional commands
example: modprobe gamecon map=0,7
This command loads the gamecon module
(a module that allows linux to use console gamepads like snes,playstation)
map=0,7 specifies that the controller is attatched to parallel port 0
7 is the designation for playstation.
command: rmmod - removes specified module
example: rmmod lp
This command removes the lp module (the lp module controls printers through the parallel port)
In order to use the gamecon module for the parallel port you have to have the parallel port available.
The lp module maintains control of the parallel port by default in linux.
So to use the gamecon module with the parallel port you must first open the port with;
rmmod lp - then load the gamecon module with modprobe gamecon map=0,7
Then assuming you have a properly configured playstation controller attatched to the parallel port,
it would be functional.
During distribution installation you should be prompted to select services that will be started at boot.
If you do not select the parallel and serial ports to be started you will probably not be able to use them .
You can do this after installation but that procedure may vary depending on distribution.
command: dmesg - lists attatched devices and modules using those devices
(very usefull command for hardware troubleshooting)
command: lspci - lists system hardware using pci interface
(very usefull command for hardware troubleshooting)
command: lsdev - lists attatched devices
(very usefull command for hardware troubleshooting)
command: fdisk -ls ; lists storage devices, size, partitions and filesystems
command: mount - in order to access filesystems in linux they must be mounted
Especially in current distributions, many storage devices are auto detected and mounted by default.
There are some cases when storage devices need to mounted manually.
In order for non root users to mount filesystems they must be listed in /etc/fstab.
The appropriate permissions must also be granted in the /etc/fstab/file.
To mount a filesystem that is not listed in fstab you must know;
the filesystem (ex: vfat, ntfs, iso99660), designation (ex: /dev/hda2) and the mountpoint (ex: /mnt/win),
The syntax is mount -t type device mount-point
example: mount -t vfat /dev/hda2 /mnt/win
command: umount - unmounts specified filesystem
Same syntax as mount command
Generally you can unmount a device with just its designation
example: umount /dev/hda2
Generally linux doesn't write to media until it is unmounted.
Meaning if you remove a floppy or a flashdrive without unmounting it, the data does not get written.
Using NTFS file system in linux
In order to mount ntfs partitions with write capabilities you must use ntfs-3g.
Many current distributions have ntfs-3g installed by default.
If not it will probably be available in that distribtions software repositories.
If it isn't you will have to compile it from source code (discussed later)
Fuse is a dependency of ntfs-3g.
An ntfs partition mounted without ntfs-3g will be read only.
To mount with ntfs-3g use mount syntax and add -3g.
example: mount -t ntfs-3g /dev/hda2 /mnt/win
For more info type man ntfs-3g (after ntfs-3g has been installed).
Mounting filesystems at boot
To have filesystems mounted at boot they must have entries in the file /etc/fstab.
Warning: incorrectly modifying fstab file can make your system unbootable.
To edit fstab file; log in as root (in terminal).
Backing up your fstab before editing is recommended!!!
cp /etc/fstab /home/(enter your username here)
The above command will copy your current fstab file to your home directory.
Use command kwrite (or vi, or gedit in gnome) /etc/fstab.
Add an entry for your desired partition
Example entry: /dev/hda2 /media/hd2 ntfs-3g defaults 0 0
/dev/hda2 specifies device, /media/hd2 is the mountpoint, ntfs-3g specifies filesystem, defaults sets permissions
Sound
For some reason distributions usually install with some of the sound options muted.
Alsa is the most comman soundcard driver in linux (OSS is another but is less prevelant)
To unmute the desired options, open a terminal and log in as root.
Type alsamixer, now you can use the m button (for mute and unmute)
use right and left arrows to change options and up and down arrows to adjust volume.
Type man alsamixer in a terminal for further options.
Most distributions also have gui's for alsamixer.
You can also use a menueditor to create a gui link in your menu to open alsmixer.
Ethernet
Ethernet options are usually set up during installation
Most distributions also gui tools for configurating and activating network cards.
The command for viewing and changing ethernet options in a terminal is ifconfig.
ifconfig lists ethernet interfaces
Usually your ethernet interface will be eth0.
example: ifconfig eth0 up | 192.198.0.1
This command species interface eth0, activate (up), the pipe adds the address (192.198.0.1)
Using down instead of up will deactivate the interface.
Not specifying an address will use the default (should either be auto assigned by isp or a preset static address).
Type man ifconfig for further options.
Wireless
The command for wireless interfaces is iwconfig.
To see available wireless networks use iwlist scan.
There are gui tools for wireless interfaces in most distributions as well.
Syntax; iwconfig eth0 essid "My Network" <--- your network name here
For further options with ifconfig and iwconfig use man (ifconfig or iwconfig)
Current versions of linux have good compatibility with wireless cards
In the event your distribution doesn't recognize your wireless card try ndiswrapper.
ndiswrapper attempts to use a windows driver for your wireless card.
There are gui's available for ndiswrapper as well.
If you have ndiswrapper already installed type man ndiswrapper.
Most current distributions install ndiswrapper by default
or have it available in their software repositories.
Syntax;
ndiswrapper -<option>
-i <inf file>
installs new Windows XP driver, where <inf file> is full path to
INF file for that driver.
-l lists the currently installed drivers.
-e <driver>
removes an installed Windows XP driver named <driver>.
-m writes an alias for wlan0 (default wireless device) into module
configuration file so that ndiswrapper kernel module is loaded
automatically when this interface is used.
File Sharing in Linux
To share between linux systems you can use Lisa.
Lisa must be installed first of course.
There should be a gui for Lisa configuration.
Once Lisa is configured you must start it.
Just type Lisa to start the service.
If that does not work you probably need to use the command from the directory that contains the Lisa executable.
Google Lisa for you distribution to find its directory.
To share files between linux and windows systems you must use Samba.
Samba should either come pre installed or be available in repositories for current distributions.
kde and gnome have gui networking tools to view shared windows files.
Generally you need to physically mount a share in order to stream media files (video files).
For KDE the easiest way to stream media across a network without mounting the share
is to install kmplayer (a linux media player for kde) or kplayer.
In Gnome you just need to install totem-xine or totem-gstreamer.
Accessing your linux shares in windows is a little more difficult.
You will need to make sure your firewall is set to allow file sharing.
Some distributions may have other security features that need to be checked.
Security settings and gui tools for them vary distribution to distribution.
/etc/samba/smb.conf is the configuration file that controls how samba works.
It is always a good idea to back up configuration files before altering them!
If you want to share linux files without a password set security = share.
If you have trouble try using some of the following options on your shares
Shares are located at the bottom of the smb.conf file; guest = ok, hosts allow = all
(or the host names of network pc's, ip addresses may work also)
The smb.conf file usually contains examples of what a share should look like.
Running -testparm /etc/samba/smb.conf - will check your syntax and give you a summary of your configuration.
You can use a different security setting and create samba users and passwords also.
Compiling software from source code
Linux is open source for the most part.
Meaning that its mostly free and the programming code is available and can be altered.
There are many distributions and they all function differently.
Because of this, software for Linux is not written for one distribution, it is written for many.
Repositories the source code for those programs and pre-compliled it for your distribution.
If the program you want is not availalbe via repository or doesnt work like you want you can try to complile it yourself.
In order to compile source code you need to have the right compilers and sometimes developement packages
minimum you need c and C++ compilers. type man g++ to check if you have c compilers installed
if they dont come preinstalled go to your package manager and search for "compiler"
find one that has c, c++ and install it.
you may also need other things before you can compile a program from source code
a text file called dep, dependies, info, or readme may list them
if you dont have all the requirements you will get compilation errors
some programs will compile but will not full functionality if you dont have everything you need
to compile a program from source look for a text file called install, compile or readme
usually you will find one of these with instructions for compiling the program
the most common compilation consists of these three commands, issued as root
./configure
make
make install
these commands have to be issued from the directory that contains the source code
each of these commands can take a few minutes to complete
the command make clean (if the corresponding file was created) will remove files that are no longer needed
sometimes you may only be required to issue the make and make install programs or even just make install
there are other common installation scripts such as "program".py
in which case you usually only have to execute the installation script
if you get compilation errors look for lines like
"checking for "random libraries.....yes"
"checking for "random libraries"....no"
you may want to install the libraries/programming languages listed with no
you may also get an error like "failed to compile gtk>=2.4 not found"
this would mean you need to install gtk 2.4 or above
a program may be dependent upon a version of another program that is incompatible
you should research a program against your distribution and version before attemting to compile it
to uninstall a program that has been compiled, go to the directory it was compiled from and as root
type make uninstall
the command for turning a .cpp file into an executable is g++ -o /home/user/program program.cpp
g++ is the compiler, -o /home/user/program specifies name and place to put executable, program.cpp the .cpp file to be compiled
to run the executable, from the directory it is in type ./(enter executable file name here)
Multi booting operating systems
both windows and linus have bootloaders which control how and what operating systems are started at boot
both the windows and linux bootloaders are capable of allowing a computer to boot multiple operating systems
in order to install multiple operating systems on one hard drvie you must have multiple partitions
windows2000 and xp include a partition editor - partition magic works well and linux has many tools for editing partitions
linux even has tools for resizing partitions that contain data
of course in order to resize a partition you must have free space available otherwise you will lose data and maybe functionality
the windows bootloader will automatically add previous versions of windows to the bootloader during installation
as long as you install the older operating system first you will be able to choose one from the boot menu
so if you install win98, then winme, then win2000, then winxp when you boot you can pick from any of them
the windows bootloader also has the ability to boot other operating systems including linux
(only advanced users should attempt to modify the windows bootloader)
if you install linux with windows already installed linux will detect it and add it to the loader
many new distributions of linux also give you the option of mounting the windows partition at boot
it is a good idea to back up your linux bootloader
you may be able to reinstall a linux bootloader from the original distro install cd if your system becomes unbootable
you can also install the linux bootloader to a floppy disc if you have it formatted correctly
linux can also be installed on a flash drive which can booted in any pc that has a bios which allows boot from usb
some distributions release special installation packages specifically for usb drives
-written and refined by M-



