linuxtips

an assorted and certainly varied list of linux tips, some of which certainly don't apply anymore

Remove trash from nautilus
rm -rf ~/.local/share/Trash/files/*
------------------------------------
 
--------------------------------------------
ADD AN EXTRA HARD DRIVE
--------------------------------------------------------------------------------
#run fdisk
/sbin/fdisk /dev/hdb

# inside fdisk, create new partition
n
# primary
p
# with default sizes (all HD) RET RET

#Write and save partition table
w

#Then format the partition to ext3 (will take some time)
/sbin/mkfs -t ext3 /dev/hdb1

#Mount partition
mkdir /opt2
mount -t ext3 /dev/hdb1 /opt2

#To add definitively, edit /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
none /dev/pts devpts gid=5,mode=620 0 0
none /proc proc defaults 0 0
none /dev/shm tmpfs defaults 0 0
/dev/hda2 swap swap defaults 0 0
/dev/hdb1 /opt2 ext3 defaults 1 2
/dev/cdrom /mnt/cdrom iso9660 noauto,owner,kudzu,ro 0 0
/dev/fd0 /mnt/floppy auto noauto,owner,kudzu 0 0
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
MORE LINUX SHORTCUTS AND COMMANDS
--------------------------------------------------------------------------------
batch any_command
Run any command (usually one that is going to take more time) when the system load is low. I can logout, and the process will keep running.

at 17:00
Execute a command at a specified time. You will be prompted for the command(s) to run, until you press <Ctrl>d.

This command will add the permission to read the file "junk" to all (=user+group+others):
chmod a+r junk
This command will remove the permission to execute the file junk from others:
chmod o-x junk

<Ctrl>s
Stop the transfer to the terminal.

<Ctrl>q
Resume the transfer to the terminal. Try if your terminal mysteriously stops responding.

rwho -a
(=remote who) Determine all users logged on your network. The rwho service must be enabled for this command to run. If it isn't, run setup as root to enable "rwho".

history | less
Show the last (1000 or so) commands executed from the command line on the current account. The "| less" causes the display to stop after each screenful.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
EASY SCREENSHOTS
--------------------------------------------------------------------------------
Type

import background.jpg

then make a box around what you want with you cursor.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
LIST OF SUBDIRS IN A DIRECTORY
--------------------------------------------------------------------------------
Type

ls -alF | grep /$

for a list of subdirs in the current directory.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
LOOKING FOR BIG FILES
--------------------------------------------------------------------------------
Where has all my disk space gone! start in /home or /var and run the following:

du -S | sort -n -r | more

which will lists directory sizes, starting with the largest.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
SAVING LONG BASH COMMANDS FOR LATER
--------------------------------------------------------------------------------
While using bash, if you have typed a long command, and then realize you don't
want to execute it yet, don't delete it.

Simply append a # to the beginning of the line, and then hit enter.

Bash will not execute the command, but will store it in history so later you can
go back, remove the # from the front, and execute it.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
WHEN A TAR MAKES A MESS OF YOUR DIRECTORY
--------------------------------------------------------------------------------
If you untar a package, and it makes a mess of your directory because the packager
didn't include the files in his tarball in a directory, you can use

rm `tar ftz stupidpackage-1.0.0.tar.gz`

to quickly get rid of those cluttering files.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
SORT DIRECTORIES BY SIZE
--------------------------------------------------------------------------------
To get the size of all directories in the current directory:

find . -maxdepth 1 -type d -print | xargs du -sk | sort -rn

A spiffy way to see what directories are taking up the most space on your hard
drive is

du -sk * | sort -n

-- this will show just the base-level directories in whatever directory
you run this in. So it will include the size of sub-directories, but not list them
in the output.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
READ-ONLY /dev/null FAILURE
--------------------------------------------------------------------------------
Some process in the system can wrongly update /dev/null to be a regular file.

This might cause a "/dev/null read-only" error on startup, preventing the system
to properly boot.

This is a way to fix it (in maintenance mode, as prompted when the error occurs):

mount -m -o remount,rw /
rm -f /dev/null
mknod -m 666 /dev/null c 1 3

and Reboot the system.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
CDRECORD UNDER 2.6
--------------------------------------------------------------------------------
change the dev parameter from

dev=0,0,0

to

dev=ATAPI:0,0,0

Example:

cdrecord dev=ATAPI -scanbus

and then:

cdrecord -v -eject dev=ATAPI:0,0,0 myfile.iso
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
MOZILLA WITH EVOLUTION AS YOUR EMAIL CLIENT
--------------------------------------------------------------------------------
2004-03-07 Fedora Tips 49:

If you like the Mozilla browser but prefer to use Evolution as email
client in FC1 so how does one do this ??.

Mozilla doesn't have a means of doing this out of the box (or so I
believe) so I did some searching and found a neat little addon from
here which is really handy. KUDOS to the developers of this
addon. Simply click on the install menu item, scroll to the *nix area
and click on the here link then follow the instructions.

Once the install is finished restart your browser and select

--edit/prefences

and the new mozex option will appear.

Check the

--Intercept Clicks/mailto option
and enter

--/tmp/mozex

for the temp directory and

--evolution mailto:%A?Subject=%S&Cc=%C&body=%B

for the mailer. Restart the browser and give it a test.

There are a heap more options to play with and good examples at the
developers website - submitted by Stephen Webley
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
NETWORK CONNECTIONS
--------------------------------------------------------------------------------
netstat

Use the netstat console command to print network connections, routing
tables, interface statistics, masquerade connections, and multicast
memberships. netstat has several command line switches to control its
function. Here are some of the common ones:

Printing network status
netstat -p Shows the PID and name of the program to
which each socket belongs

netstat -a Shows both listening and non-listening sockets

netstat -t Shows TCP connections

netstat -u Shows UDP connections

netstat -e Displays additional information. Use this option
twice for maximum detail
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
All you have to know about RPM
--------------------------------------------------------------------------------
rpm -Uvh --oldpackage Samba-old-version.rpm

rpm -q --whatrequires kernel

How can I find from which package the file /usr/bin/smbmount belongs?

rpm -qf /usr/bin/smbmount

How can I list what files will be installed by a RPM package?

rpm -ql cpp
rpm -qpl cpp-3.3.2-1.i386.rpm

How can I install a package directly from Internet? Can I use a proxy?

rpm -Uvh ftp://user:pass@ftpserver/directory/package.rpm

Use the Backup option "--repackage" so you can reinstall the old
package you've removed during upgrade process

rpm -Uvh --repackage new-kernel.rpm

rpm -ivh --oldpackage /var/spool/repackage/old-kernel.rpm

How can I make backups of my old packages when updating or removing them?

rpm -Uvh --repackage new-package.rpm

rpm -e --repackage new-package.rpm

rpm -Uvh --oldpackage /var/spool/repackage/old-package.rpm

How can I figure out the size of a installed package?

rpm -qa --queryformat '%10{size} %{name}-%{version}\n' | sort -n
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
OTHER DICTIONARIES AND HYPHENATION IN OPENOFFICE
--------------------------------------------------------------------------------
1. to get the next files:

sk_SK.aff
sk_SK.dic
hyph_sk_SK.dic

2. to copy the files into

/usr/lib/openoffice/share/dict/ooo

3. to modify the dictionary.lst as follows:

DICT sk SK sk_SK
HYPH sk SK hyph_sk_SK

4. now you can set the openoffice option
Nastroje->Volby->Nastavenie jazyka->Jazyky
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
SPECIAL KEYS
--------------------------------------------------------------------------------
I recently bought a new keyboard, and as with most new keyboards these
days, it has a lot of custom keys that won't do anything (out of the box)
on Linux.

Getting these keys to do anything useful, is a bit involved (and time
consuming) but not especially difficult. It also depends on a number of
different factors, such as which window manager you're using.

For those running FC1, Gnome 2.4 and Metacity, and for the benefit of
those who haven't figured out how to use those extra keys yet, here's a
quick HOWTO:

Steps 2 and 3 should be run a root.

1) ...

Run "xev" in a terminal ... it's part of XFree86-tools

Press one of the "custom" keys.

Look carefully at the output:

KeyPress event, serial 23, synthetic NO, window 0x2a00001,
root 0x7d, subw 0x0, time 2400405, (126,229), root:(134,275),
state 0x0, keycode 229 (keysym 0x0, NoSymbol), same_screen YES,
XLookupString gives 0 bytes: ""

The info you need above is "keycode 229" - in this example, this is the
"search" key on a Logitech Deluxe Access" keyboard.

2) ...

Using your favourite text editor, edit /etc/X11/Xmodmap (part of the
xinitrc package).

Add the following line:

keycode 229 = LogiSearch

Save and quit.

Note: I chose the name "LogiSearch" arbitrarily. You can give it any name
you like, so long as you keep a note of that name - and remember it is
case sensitive (as with most things on Linux).

3) ...

Edit /usr/X11R6/lib/X11/XKeysymDB (part of the XFree86-libs-data package).

Choose a range of identifiers not already in use, on my system I chose
10090001 upwards (this is a hex value).

Add the following line:

LogiSearch :10090001

Save and quit. Note that by default this file is read only, so you will
need to "force" save - e.g. with "w!" using vi.

4) ... ( As non-root )

Run gconf-editor (changes here are on a per-account basis)

Navigate to apps -> metacity -> global_keybindings.

Right-click on "run_command_2", and chose "Edit key..."

In the "Key value:" box, type "LogiSearch" without the quotes.

Navigate to apps -> metacity -> keybinding_commands.

Right-click on "command_2", and chose "Edit key..."

In the "Key value:" box, type "gnome-search-tool", without the quotes
(part of the gnome-utils package)

Quit gconf-editor and logout (restart X), no need to reboot.

That's it. Hitting the "search" key will now launch gnome-search-tool.

Remember you have to run gconf-editor for *every* user account you wish to
have access to the custom keys.

One key down, twenty to go ... sigh.

I managed to set up xmms to use the multimedia keys, using xmms-shell
(http://freshmeat.net/projects/xmms-shell/).

Here's a sample from my configs:

/etc/X11/Xmodmap
keycode 236 = LogiEmail
keycode 237 = LogiMedia
keycode 176 = LogiVolUp
keycode 174 = LogiVolDn
keycode 162 = LogiPlay
keycode 164 = LogiStop
keycode 144 = LogiBack
keycode 153 = LogiFfwd
keycode 160 = LogiMute

/usr/X11R6/lib/X11/XKeysymDB
LogiEmail :10090001
LogiMedia :10090002
LogiVolUp :10090003
LogiVolDn :10090004
LogiPlay :10090005
LogiStop :10090006
LogiBack :10090007
LogiFfwd :10090008
LogiMute :10090009

gconf settings
global_keybindings
run_command_2 LogiEmail
run_command_3 LogiMedia
run_command_4 LogiVolUp
run_command_5 LogiVolDn
run_command_6 LogiPlay
run_command_7 LogiStop
run_command_8 LogiBack
run_command_9 LogiFfwd
run_command_10 LogiMute

keybinding_commands
command_2 evolution
command_3 xmms
command_4 aumix-minimal -w +1
command_5 aumix-minimal -w -1
command_6 sh /home/kgr/scripts/xmms-toggle-play.sh
command_7 xmms-shell -e stop
command_8 xmms-shell -e back
command_9 xmms-shell -e forward
command_10 sh /home/kgr/scripts/xmms-toggle-mute.sh

#!/bin/bash
# xmms-toggle-mute.sh

xmmsstatus=$(xmms-shell -e status >/dev/null 2>&1)
statusresult=$?
if [ "$statusresult" -eq 1 ]
then
exit 1
fi

getvol ()
{
echo $3
}

if [ -f /tmp/xmms-volume.save ]
then
read oldvolume </tmp/xmms-volume.save
else
oldvolume=80
fi

xmmsstatus=$(xmms-shell -e status | tail -n 5 | head -n 1)
if [ -n "$xmmsstatus" ]
then
volval=$(getvol $xmmsstatus)
fi

if [ "$volval" -eq 0 ]
then
xmms-shell -e "volume $oldvolume" >/dev/null 2>&1
else
echo >/tmp/xmms-volume.save $volval
xmms-shell -e "volume 0" >/dev/null 2>&1
fi
exit 0

#!/bin/bash
# xmms-toggle-play.sh

xmmsstatus=$(xmms-shell -e status >/dev/null 2>&1)
statusresult=$?
if [ "$statusresult" -eq 1 ]
then
exit 1
fi

xmmsstatus=$(xmms-shell -e status | head -n 1 | grep "Current song:")
if [ -n "$xmmsstatus" ]
then
xmms-shell -e play >/dev/null 2>&1
else
xmms-shell -e pause >/dev/null 2>&1
fi

exit 0

I assume there are ways of getting all this to work under different window
managers, YMMV. Also, I've been toying with the idea of getting a
"Logitech diNovo Media Desktop" keyboard. This thing is essentially a USB
keyboard using Bluetooth for wireless transmission. Getting it to work
(including the extra keys) under Linux will probably be a bit more
involved than the relatively simple steps here. My next project, I guess.

In the meantime, it would be great if all the above steps could be
combined into a nice GUI "keymap configurator" for Gnome/KDE. Any takers?
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
RPM BY SIZE
--------------------------------------------------------------------------------
There is sometimes a need to see a list of all RPM packages installed on the
system, sorted by package size. Here is how to do it:

rpm -qa --qf "%-10{SIZE} %-30{NAME}\n" | sort -n
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
BOOT LINUX OFF A USB KEY
--------------------------------------------------------------------------------
To boot off of usb key:

- cp isolinux/* to the device
- rename isolinux.cfg to syslinux.cfg
- run syslinux on the device

That should be it.
--------------------------------------------------------------------------------


----------------------------------------------------------------------------------
DCOP AND KLIPPER
----------------------------------------------------------------------------------
Playing with klipper:

If you want to give the klipper something that you typed in the console, for
example:

$ dcop klipper klipper setClipboardContents "my long line that I have in the
console and I want to copy+paste somewhere else"

$ dcop klipper klipper setClipboardContents "`cat file_you_want_to_copy`"

There is a module under development called dcopperl (kdebindings) that will be an Perl API for dcop calls.
----------------------------------------------------------------------------------


----------------------------------------------------------------------------------
BURNING BIN/CUE FILES
----------------------------------------------------------------------------------
cdrdao write --device 0,0,0 --speed 8 ./file.cue

you can add --simulate to test it first

please note that some times you need to edit the cue file to the correct
file.bin because in M$ its not case sensitive.
----------------------------------------------------------------------------------



--------------------------------------------------------------------------------
MULTISESSION CD BURNING
--------------------------------------------------------------------------------
The first time you record a session on a disk, use the -multi switch
in cdrecord:

$ cdrecord -v -eject speed=8 dev=0,1,0 -multi test.iso

The disk will be fixated in a manner that makes it readable and open
for adding more data. To add more sessions to this disk, mkisofs needs
to know the starting and ending sector numbers, which you can find
like this:

$ cdrecord dev=0,1,0 -msinfo
0,27139

Be sure to have the disk you are adding data to in the CD
recorder. Then add two new switches, -C and -M:

$ mkisofs -o test2.iso -Jr -V Session2 -C 0,27139 -M 0,1,0 /files/path/

Or better, let the command shell do the work:

$ mkisofs -o test2.iso -Jr -V Session2 -C `cdrecord dev=0,1,0 -msinfo`
-M 0,1,0 /files/path/

Multisession CD drives read the last session written. This command
takes the TOC from the last session and combines it into the new
TOC. For the last session on the disk, omit the -multi option.
--------------------------------------------------------------------------------


----------------------------------------------------------------------------------
REDHAT MANUALS - CD BURNING
----------------------------------------------------------------------------------
mkisofs -o backup.iso -J -R -A -V -v /home/joeuser/

or

mkisofs -o backup.iso -J -R -A -V -v /home/joeuser/file.ext

-o Specifies an output file name of the ISO image.

-J Generates Joliet naming records; useful if the CD is used in Windows
environments.

-R Generates Rock Ridge (RR) naming records to preserve filename length and
casing, especially for UNIX/Linux environments.

-A Sets an Application ID — a text string that will be written into the volume
header of the image which can be useful to determine what applications are on
the CD.

-V Sets a Volume ID — a name that is assigned to it if the image is burned, and
the disc is mounted in Solaris and Windows environments.

-v Sets verbose execution, which is useful for viewing the status of the image
as it is being made.

cdrecord -scanbus

cdrecord --dev=0,3,0 --blank=fast

cdrecord -v -eject speed=4 dev=0,3,0 backup.iso
----------------------------------------------------------------------------------


----------------------------------------------------------------------------------
HEAD, TAIL, CAT and TAC
----------------------------------------------------------------------------------
[$] head file
prints first 10 lines

[$] tail file
prints last 10 lines

[$] head -n 4 file
prints first 4 lines

[$] tail -n 4 file
prints last 4 lines

[$] head -c 200 file
prints first 200 characters

[$] tail -c 200 file
prints last 200 characters

[$] head file1 file2 file3
will print the specified number of lines from each file separating them with the
header beginning with ==> followed by the name of the file.

[$] cat file1 file2 file3 | head or [$] head -q file1 file2 file3
will print the specified number of lines from the input stream made up of the
files listed after the cat command, but treated as one single file.

[$] tail -f /var/log/access.log
-f option tells tail to keep on reading data from the specified file and feeding
it to its own standard output.

[$] cat file | head -c 1788 | tail -c 789
to read a chunk of 789 bytes starting from byte 1000 counted from the beginning
of that file

[$] tac file (Note that tac is cat spelled backwards.)
to reverse the order of lines in a file
----------------------------------------------------------------------------------


DEALING WITH RPM
--------------------------------------------------------------------------------
Query commands

These commands query a package that has already been installed. To query a package that has NOT been installed yet, add the -p option to the command.

For example, rpm -ql package would become rpm -qpl package.

To find out the package names using wildcards rpm -qa | grep pattern

What files are included in the the package rpm -ql package

To show general info on a package rpm -qi package

What package owns this file? rpm -qf path/to/file

What are the config files in a package? rpm -qc package

What are the documentation files in a package? rpm -qd package

What are the scripts in a package? rpm -q --scripts package

What services does this package provide? rpm -q --provides package

What services does this package require? rpm -q --requires package


rpm -ivh source-package

This installs the source in /usr/src/packages/SOURCES and installs the spec
file in /usr/src/packages/SPECS.


rpm -bp spec-file

This extracts the sources into /usr/src/packages/BUILD and applies any
patches from the source package, but does not compile it or create a binary rpm
package.


rpm -ba spec-file OR rpm --rebuild spec-file

This compiles the source and builds a binary rpm, then places it in
/usr/src/packages/RPMS/Architecture.


rpm -ivh package

This installs the binary package.

If you want to remove a list of RPMs without typing each on separately, you can
use the xargs command with rpm. Here are the commands and output from a session
where I wanted to delete several RPMs at once. First, I used rpm -qa to find
all the xine RPMs. When I verified the list, I passed the list to xargs to
execute an rpm -e on each of them. The final rpm -qa verifies that they have all
been uninstalled.


artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine
xine-lib-0.9.7-0
xine-lib-aa-0.9.7-0
xine-lib-alsa05-0.9.7-0
xine-lib-arts-0.9.7-0
xine-lib-d4d-0.9.7-0
xine-lib-docs-0.9.7-0
xine-lib-oggvorbis-0.9.7-0
xine-lib-oss-0.9.7-0
xine-lib-w32dll-0.9.7-0
xine-ui-0.9.7-0
xine-ui-aa-0.9.7-0
artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine | xargs rpm -e
artifact:~/datacore/suse-7.3/xine # rpm -qa | grep xine
artifact:~/datacore/suse-7.3/xine #

--------------------------------------------------------------------------------



--------------------------------------------------------------------------------
Usage Of The Linux lp Print Commands
--------------------------------------------------------------------------------

(all commands are summarys of only the main functionality unless noted)

lpr [-#number of copies][filename]
initiates printing services on the printer

lpq [-l][-Pprinter][job # ...][user ...]
monitors the line printer queue (all options shown)
-l = long listing
-P = to specify the non default printer

lpc [command {all|printers}]
line printer control - oversees printer hardware management
the following are a list of options for "command"
abort, clean, disable, down, enable, restart, start, status, stop, up
useful example: lpc status lp

lprm [-Pprinter][-][job # ...][user ...]

removes jobs from printer queue (all options shown)

the `-' commands lprm to remove all of the users jobs and all jobs if su

--------------------------------------------------------------------------------

mpage Settings And Usage

mpage [OPTIONS][files ...]

OPTIONS:

-8, -4, -2, -1 select # pages per sheet

-o toggles outlines, default on

-l toggles landscape or the default, portrait

-m#l#r#t#b left, right, top, bottom margin definition (20 pts default)

-M#l#r#t#b logical page margins

-a 12 over 34 vs. default, 13 over 24

-S for ps files, allows distortion to fill aspect scaling

-r reverses print order - nothing else changes.

-j# page range and/or skip real pages (#=1st, -#=2nd, %#=interval)

-P[lpr] specifies alternate real printer - lpr is default

-L# set lines per page def ls=55 por=66

-W# set columns per page def ls=132 por=80

Headers options:

-h h defines the header for the -H option

-H header for each logical page. Non-PS files defalut, where no -h has been set
is: change time, filename, page #

-X[header] header for each physical page

Examples:

mpage -8 -m20t30l30r50b -j1-1 -P -L60 -X"Exec Summary" ./file2print

This works well with the -4 (page) option too.



--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
FOREGROUND AND BACKGROUND
--------------------------------------------------------------------------------
Moving a Foreground Job into the Background:

$ sed 's/.$//' < winf.txt > ufile

Suppose the sed command is taking a long time. Type CTRL-z in to
suspend the job:

CTRL-z

Suspended, now send to background:

$ bg %sed


[6] sed 's/.$//' < winf.txt > ufile &

$

The sed command continues in the background
while you continue to use the terminal.
--------------------------------------------------------------------------------


--------------------------------------------------------------------------------
MORE about FIND
--------------------------------------------------------------------------------
find . -name '*.c' | xargs grep 'write' # find *.c files with 'write'
find / -daystart -mtime -7 -print # modified in the last 7 hours
find / -ctime -7 -print # changed in the last 7 hours 
find . -size +100k -exec ls -l {} \; | \

awk '{printf "%40s %10s \n", $9, $5}' | \

sort -n +1 #
Greater than or equal to 100KB. Sort the output numerically
find . \( -name "*.scr" -o -name "*.rpt" \) -print # Find files under current directory named string.scr or string.prt
find / -name csh -print # find file named "csh" anywhere
find . -name '*.c' -print # find all files ending in ".c"
find ~ -name a.out -print # find all a.out files
find ~ -name core -exec /bin/rm \{\} \; # find all core files and remove
find ~ -type f -exec chmod 0444 \{\} \; # make all plain files public
find ~ -type d -exec chmod 0755 \{\} \; # make all directories public
find ~ \( -name a.out -o -name '*.o' \) -atime +14 -exec /bin/rm \{\} \;
# get rid of all files a.out or
# ending in .o which haven't been
# accessed in 14 days
find ~ -name a.out -atime +7 -print # print all a.out's unused in last week
find ~ -size 500000c -print # print names of files that are bigger
than 500,000 characters
--------------------------------------------------------------------------------



--------------------------------------------------------------------------------
CD BURNING BUT DISABLING DMA
--------------------------------------------------------------------------------
[root]# hdparm -d0 /dev/hdd

/dev/hdd:
setting using_dma to 0 (off)
using_dma = 0 (off)

[root]# mkisofs -r -J -o image.iso dir_with_files/

[root]# cdrecord -v dev=0,3,0 -speed=4 /path/toimage/image.iso

to check the burned cd:

[root]# md5sum *.iso ---> iso md5 number
[root]# df -k /mnt/cdrom2 ---> block_count
[root]# umount /mnt/cdrom2
[root]# dd if=/dev/cdrom2 count=block_count bs=1024 | md5sum ---> cd md5 number
--------------------------------------------------------------------------------


----------------------------------------------------------------------------------
BACKUPS IN SEVERAL FLOPPY DISKS
----------------------------------------------------------------------------------
[~] split -b 1400k file.tar.gz f

Will produce faa, fab, fac, fad, ...

To join them back:

[~] cat fa* > recoveredfile.tar.gz
----------------------------------------------------------------------------------



--------------------------------------------------------------------------------
INSTALL FROM HARDDISK
--------------------------------------------------------------------------------
(1) copy the CDs to a FAT32 partition
(2) boot from CD1 and ask for a HD installation boot floppy disk
(3) boot from the floppy disk and tell where the CDs are
--------------------------------------------------------------------------------


MDK 9.0 TIPS
--------------------------------------------------------------------------------


WHAT IS THE LINUX DOING INTERNALLY?
-------------------------------------

All of the mandrake tools are "explaining" what they do, by writing entries
in /var/log/explanations. These "explanations" can also be seen in mcc - you
just need to ask for it.

NVIDIA support
---------------

NVIDIA works just fine, at least if you choose to use XFree 4.2.1
during install. But 3D doesn't work by default. You have to
download the latest NVIDIA src.rpm:s from http://www.nvidia.com/ , and
rebuild + install them. The procedure is simple, and goes:

1. Download NVIDIA_kernel-1.0-3123.src.rpm
NVIDIA_GLX-1.0-3123.src.rpm
from http://www.nvidia.com/

2. Navigate to the directory where you saved the downloaded files and
type the following insida a CLI as root:

rpm -rebuild NVIDIA_kernel-1.0-3123.src.rpm

and press "enter"

now you get loads of exotic text inside the CLI, but focus your
attention on the line following the word "wrote" ie:

wrote /usr/src/RPM/RPMS/i586/NVIDIA_kernel-1.0-3123.i586.rpm

3. rpm -ivh /usr/src/RPM/RPMS/NVIDIA_kernel-1.0-3123.i586.rpm

now the Nvidia videokernel is installed on your system :)

4. Follow EXACTLY the same procedure as above with the NVIDIA_GLX
file, so that it becomes rebuilt and installed as well :)

5. Open a texteditor, still logged in as root, and open the file
/etc/X11/XF86Config-4. Search for the text driver "nv", and
change "nv" to "nvidia" and save the file.

6. Log out, and restart X(ctrl-alt-backspace) and you will see a
"nice" Nvida splashscreen, now you got yourself a hell of an
OpenGL 3D-box :-)






--------------------------------------------------------------------------------
USING Kdbg
--------------------------------------------------------------------------------
Before loading the file, set 'execution->arguments...->Working directory'
Now load the executable
--------------------------------------------------------------------------------



DISABLING X AUTO START
--------------------------------------------------------------------------------
Most commercial Linux distributions default to starting an X-Window manager
following system initialization. That's a lot of system resources to have
running if you're compiling a program or editing configuration files. To change
this behaviour, edit the /etc/inittab file and locate the line that reads:
id:5:initdefault and change it to id:3:initdefault. The system will start with
a command line login, and when the need arises to run a window manager, it's
easy to simply type "startx".
--------------------------------------------------------------------------------



REMOVING CARRIAGE RETURNS AND LINE FEEDS:
---------------------
tr -d '\n' < teto > teto2
removes UNIX-style returns from the text in teto, creating teto2
tr -d '\r\n' < teto > teto2
removes DOS-style returns from the text in teto, creating teto2
---------------------



BUSCANT I MODIFICANT COSES:
---------------------------

$ which perl
Busca l'arxiu executable en la llista del $PATH
$ locate perl
Busca els fitxers relacionats amb el terme

Abans de fer locate, sovint cal fer (com a root)
# updatedb
Actualitza la base de dades

$ find -name met*

$ find /home/david -name 'index*'

$ find /home/david -name 'index*' -type d
tipus directori

$ find /mp3collection -name '*.mp3' -size -5000k
$ find /mp3-collection -name 'Metallica*' -and -size +10000k
semblant a l'anterior
$ find /mp3-collection -size +10000k ! -name "Metallica*"

més de 10MB --però NO-- Metallica
$ find /mp3-collection -name 'Metallica*' -or -size +10000k
més de 10MB --O BÉ-- Metallica

$ find /home/david -amin -10 -name '*.c'
accedit fa menys de 10 minuts
$ find /home/david -atime -2 -name '*.c'
accedit fa menys de 2 hores
$ find /home/david -mmin -10 -name '*.c'
modificat fa menys de 10 minuts

$ find / -mount -name 'win*'

NO buscar en dispositius muntats

# find /home/httpd/html -name "*.html" -print | xargs \
> perl -p -i.bak -e "s/Copyright 1999/Copyright 2000/g;"
Busca el patró, fa un backup de tots els archius i
canvia totes les instàncies de Copyright 1999 a Copyright 2000

$ find -type f -name "index*" -exec grep "dins fitxer" \{\} --with-filename \;
$ find -type f -name "index*" -exec grep -i "hola hola" \{\} --with-filename -n \;
-i ignora majúscules/minúscules
-n amb el número de línea

$ cat vi.html | awk '{sub("\r",""); print}' > vi.html.new
treure els \r
$ cat a.html | awk '{gsub("\r$",""); print}' > a.html.1; mv a.html.1 a.html

--------------------------------------------------------------------------------



BURNING CD IMAGES:
--------------------------------------------------------------------------------

The standard tool for burning CDs in Linux is cdrecord. You only use
'cdrdao' for burning audio CDs to get rid of the 2 seconds
pause between tracks or to burn cue/bin images.

Burning an image from the hard disk to CD works like this:

cdrecord -v -eject speed=XX dev=x,y,z cd_image.iso

'-v': 'Verbose' switch. This enables the progress
indicator. Optional. '-eject': Eject disk after
burning. Optional. 'speed=XX': Speed factor (i.e. either 4,
8, 12, 16 etc). If you don't know the speed of your CD burner,
use '20' (without quotes). 'cdrecord' will
automatically adjust this number to the capabilities of your hardware.

'dev=x,y,z': These three numbers tell 'cdrecord'
which device to use. Run

cdrecord -scanbus to find out which to use for yours.

Not that complicated, isn't it? From the wealth of options
cdrecord provides, the '-dummy' option provides a sometimes
useful functionality: it goes through the whole process without
actually burning any data to the disk.

Burning a cue/bin image with cdrdao looks like this

cdrdao write --device 0,3,0 --buffers 64 --eject image.cue

Not much difference to the cdrecord command above. You have to make
sure, though, that the cue/bin pair is in the same directory and has
the same name (apart from their different extensions, that is).

"What about those three or four key strokes you were talking
about at the beginning?" Gee, you are insisting, aren't you?
;-) Well, on my machine, I've defined an alias for the cdrecord
command line above in my '.bashrc':

alias biso='cdrecord -v -eject speed=12 dev=0,6,0'

Now all I've to do is type

biso image.iso

and the rest happens all by itself.
--------------------------------------------------------------------------------



--------------------------------------------------------------------------------
TRUCS Control de processos:

Per fer una instantània dels processos actius:
ps -x -r

-x mostra processos que no estan controlats per cap terminal
-r tansols processos que s'estan executant

Per fer una visualització contínua:
top -i

-i descarta qualsevol procés inactiu o zombie
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
Prioritat de processos:
--------------------------------------------------------------------------------
Als processos, a Linux, se'ls hi pot donar prioritats, referint-se als
fragments de temps que se'ls hi assigna als porcessos, en el processador
del PC.

Segons el nivell de prioridad, poden anar més ràpid o menys.

La prioridad dels processos oscil·la entre dos números: -20 i 20. El nivell 0
és el predeterminat.
El nivell -20 és el més alt i el 20 el més baix.

Per controlar les prioritats s'utilitzen les comandes: NICE i RENICE.

nice -n nivel_de_prioridad comando
renice nuevo_nivel_de_priorirad número_del_identificador_del_proceso

El número d'identificador del procés es pot obtenir, per exemple, amb:

ps -x

o a l'iniciar el procés amb:

./comanda &
-------------------------------------------------------------------------------



Some basic commands
--------------------------------------------------------------------------------
xkill Kills a running program
exit Exits the terminal
reboot Reboots the system
halt Shutsdown the computer
startx Starts xwindows from terminal
man man(command)shows help files
info info(command) shows help files
--help (command)--help shows help files
su Allow you to login as Super User

ls "Lists" the contents of the directory
pwd Displays "present working directory"

cd cd (name) change directory TO:(name)
mkdir mkdir (name) Makes new directory
rmdir rmdir (name) Removes directory
clear Clears the terminal window

date Displays current date and time
cal Displays a calander
uptime Displays time since last reboot
df Displays the disk usage on partitions
du Displays disk usage of directory

id Displays your identification to system
groups Displays groups of current user
ulimit -a Displays users limits
uname Displays name of machine logged into
who Displays "who" is logged on the system
w Similar to "who"

wall Sends message to all logged in users
top Displays cpu processes memory etc
ps Displays current running processes




How To Update By Installing Anew
--------------------------------------------------------------------------------
While being the better alternative, doing an update
by installing anew means a lot of work:

Make backups. This involves all the changed configuration files.
A backup of all configuration files is not advisable.
To find out which configuration files have changed since installation, run

find /etc -mtime -60 -type f -print > changed.txt

as 'root'. This will give you a list of files ('changed.txt') in '/etc'
which have been changed (or installed) during the last 60 days.
You might need to adjust the -mtime value according to the age of
your current installation. Create a backup directory in your home
directory (mkdir ~/backup). Check 'changed.txt' for accuracy and run

find /etc -mtime -60 -type f -exec cp {} ~/backup \;

as 'root'. Repeat this for your own, for root's and for any other user's
home directory.
You might want to copy the backup directory to an external medium
(it should fit on a floppy). If '/home' doesn't have a partition
on its own, you have to do this!
Consider whether you want to backup downloaded program packages or
source directories, too.


Install the new system. If you haven't copied the backup directory to
an external medium or if your home directory contains much personal
stuff, do the installation in 'custom' or 'expert' mode. You need to
do this to prevent the installation program from formatting your

'/home' partition!


Apply the backups to your new system. Do this with consideration! The
configuration files of the new system may contain important new content,
which you should not blindly overwrite. You should use the 'diff'
command to see if there are changes besides your customizations, like

diff -y --width 80 --suppress-common-lines [your backup file] [appropriate new config file]

If there are, apply your customizations to the new config file rather
than overwriting it with the old one.
This is the reason why you shouldn't just back up all the configuration
files on your old system: comparing these would keep you busy for
quite a while... ;-).


Install your own programs again (optional). This might be a good chance
however to check if there are newer versions of them out there...

I usually need two hours to be up and running again, if everything runs
smoothly, that is ;-). But it leaves me with a shiny new system to mess
around with again...
--------------------------------------------------------------------------------