Linux Tips
-=> By Dave Bechtel <=-

I am actively soliciting interesting and useful command line examples.
Please include a detailed explanation of what your command does when you submit it. :)

This HTML document is released under the Gnu Public License (GPL);
Check The GNU site for details.

Additional license info:

The GNU Copyleft
Zoom to the bottom to see the GNU Public License for Linux Tips.

Here are some like-minded sites:

The Linux Gazette - Monthly
Portico - Collection of helpful tips Linux Newbie
Tune Linux Scrounge - LinuxTips


Misc. Reference:
Request For Comments (RFC standards) TuxFinder - RFC's, LDP, package finder, etc.
CD Burning tips, misc media resource CD-R FAQ
Linuxlinks - Yahoo-like resource Mandrake Knowledge Base
Example LILO.CONF Example LILO.CONF for SuSE on 3rd hard drive




Remember:

' shutdown -h now ' == ' /sbin/halt '
' shutdown -r now ' == ' /sbin/reboot '

/*================================================
= Sections:
=

=
================================================*/



/*= Conventions used in this document: =*\

\*========================================*/



= How to get help for a command
= (Commands are CASE SENSITIVE!):

' man <command / exec> ' == MANUAL page (HELP); also try ' <cmd> --help '
+
+ (Type ' / ' at the prompt to Search for text)
+ (' q ' == Quit)
+ (' < ' == Top)
+ (' > ' == Bottom)
+ (' h ' == Help for the ' less ' program that ' man ' uses for its display)

' man hier ' == Explanation of file / directory system

' info <command> ' == Alternate help (More likely the most updated source)
+
+ While Inside info:
+
+ <Space> == PageDown
+ <Del> == PgUp
+ b == Beginning (Top)
+ n == Next node
+ m == Menu select (type word)
+ d == Directory (Index)
+ q == Quit
+ h == Complete internal help for Info


= Shell (BASH) Internal Commands,
Shell-Related Cmds & Hot keys:

^C == Stop current ForeGround process
^D == Logout / Exit current Shell or chroot environment.
^H == <BackSpace>
^L == CLS
^\ == Kill current process / program with core dump

^Z == Interrupt current running process / cmd
+ ' fg ' == Continue in ForeGround OR:
+ ' bg ' == Continue as BackGround process (See " jobs " command for more)

' <command> & ' == Run cmd as BG process

' command 2>stderroutfile ' == (Literal) Redirect standard error output to file 'stderroutfile'
+
+ Example: ' startx 2>~/StartXErrors ' == Start X windows, and put all error messages in a file named ' StartXErrors ' in your Home directory


For long command lines:
' longcommandlinepart1 \ <enter>
continuecommandline \ <enter>
continuedtoend ' <enter> == Append ' \ <Enter>' to the end of the command you are currently entering, to continue as one long command.

Example:
505 [dave ~]$ history \
 |grep "ls" \
 >lshistory <Enter> == Grab all occurrences of "ls" in your Bash command history, and write the output to file "lshistory" in your current directory.


' chsh -l ' == List allowed shells ( /etc/shells )
' chsh -s shellname ' == Change login shell for user (such as pdksh)

Shift-ScrollLock == Memory info (Linux kernel hotkey)

Ctrl-Alt-F1 thru ^~-F7 == Virtual console switch (~F7 is usually Graphics, for X Windows; may vary depending on /etc/inittab.)

Shift-Pgup or Shift-PgDn == Scroll back and forth in console

Alt-RtArrow or Alt-LeftArrow == Virtual console switch
+ (Also use Ctrl-Alt if in XWindows)

=====

' ./<program-name> ' == Exec program that lives in current directory

Helpful tip from Portico: (For/Next loop)
n=0;while test -$n -gt -10; do echo n=$n; n=$[$n+1]; done "February, 05:23:23 - You can execute bash command a certain number of times by using something similar to this. That code will print "n=0", "n=1", and so on 10 times.
for i in $(seq 15) ; do echo $i ; done Another way of doing it, with the "seq" external command

' alias ' == Display / define aliases
' alias ls="ls -l" ' == Redefine ' ls ' for Long listings as default
+ ' unalias rm ' == Removes alias from memory

' cd <dir> ' == Chdir to "dir"
' cd - ' == Cd to the prev dir you were in w/o using POPD

dirs == Print list of remembered PUSHD dirs (Bash)

' echo $PATH ' == What is the PATH var set to?
' echo $[ <mathexpression> ] ' == (Literal) Command-line Calculator
+ ' echo $[ 1+2-5*3 ] ' == Example

' echo $PWD ' == What is my current working directory?
' echo [your message here] ' == Print a message on the screen

' export PATH ' == From this point on, make var $PATH [[case-sensitive]] visible to the environment of any commands and scripts that this shell / window executes. (Does not carry over into other windows or virtual terminals.)

history [n] == Display last n commands
+ ' redo <string> ' == Redo last command containing 'string'
+ ' !! ' == re-DO last command
+ ' !<numbergoeshere> ' == DO command # (number from History list)
+ Example:
+ ' !512 ' == Re-DO command #512

' open -c 5 -- su dave -c top ' == Open virtual console 5, user Dave, exec TOP
' open -c 12 [-s] -- su -c "tail /var/log/messages -f --lines 50" ' == Open virt console 12 using Root, Switch to console, monitor Log.
[ -s ] == Switch active screen to terminal 12 (Optional)

pwd == Print Working Dir (bash and other shells, including FTP)
pushd == Remember this dir, I may want to POPD back to it later (bash)
popd == Go back to the last pushd (bash)

reset == Reset terminal display
+ ' stty sane ^J ' (don't hit Enter)
+ ' echo ^V<ESC>c ^J '

set == Display all set variables (use ' set |less ')

' setterm -blank 0 ' == Turn off screen saver
+ ' xset s off ' == XWindows equivalent, to be executed from XTerm / rxvt, etc.

Batch/script args: $1 $2 $* (Think %1, %2, etc in DOS batch parlance)


= File manipulation:


' cp <source> <target> ' == copy file

+Tip1: " zipi='/mnt/zippy1/installed' " OR: ' zipi=$PWD ' == (Set var zipi to the current dir)
+Step2: " cp . $zipi " == Set variable name ' zipi ' to a directory and copy the files in your current directory to it

' cat <file> ' == TYPE file to console, among other things:
' cat <file> | less ' == Pipe file to scrollable Lister

' cat /dev/hda > /dev/hdb ' == Copy one disk to another (Faster than CP?)
' cat /dev/hda1 > /dev/hdb5 ' == Duplicate a partition to another disk (partition of the same size or greater)

' cat /dev/fd0 > <image-filename> ' == Grab floppy contents to an image-file
' cat /dev/fd0 > /dev/hda2 ' == Grab floppy to a disk partition so you can boot from it (see ' man activate ')


* Explanation of dd: Linux Gazette Issue 26

' dd if=/dev/fd0 of=quicken_install_disk_1.img bs=1440k ' == Read an entire floppy into an image file
+ Mounting a disk image: See Mount

' dd if=/dev/random of=10bytes.bin bs=10 count=1 ' == Read 10 bytes of random data to a file

' dd if=/dev/random of=100bytes.bin bs=10 count=10 ' == Read 100 bytes of random data to an image file

' dd if=/dev/hda bs=512 count=1 \
 of=/bootsect.drivec ' == Grab boot sector to file (if=InFile, of=OutFile)


' dd if=/dev/zero of=/dev/hda count=1 bs=512 && sync ' == WIPE MBR (Master Boot Record) on first hard drive without using DOS
(Note: YOU WILL have to repartition the disk and use ' fdisk /mbr ' under Windows for it to be able to boot, after this!)


How to make an EXT2 filesystem for burning onto a CDROM:
(Note: You need 650Meg of free disk space for this!)
(Betcha didn't know you didn't have to make an ISO FS for a CDROM, didja?)
(Some notes taken from CD Writing Howto)
' dd if=/dev/zero of=cdimage.raw bs=1024k count=650 ' Zeroes the initial Bigfile
' /sbin/mke2fs cdimage.raw ' Reply 'Y' when it says that the file is not a block device.
' mkdir /mnt/cdburn ' == If necessary
' mount -t ext2 -o loop=/dev/loop7,user,suid,exec,rw cdimage.raw /mnt/cdburn ' == Mounts the raw filesystem image to a loop device (Loopback must be supported in kernel.) Minor note - you don't *have* to use loop7.

--If you want to make a permanent entry in /etc/fstab for a cdburn image, use something like this:

' /mnt/driveg/cdtemp/image1.raw /mnt/cdburn ext2 loop=/dev/loop7,user,noauto,suid,exec,rw 0 0 '
' cd /mnt/cdburn; ls; df ' CD to the new image, Dir, and display free space.
You can now copy your files to the image.
To unmount the image properly:
' cd; umount /mnt/cdburn; losetup -d /dev/loop7 CD to your home dir, Unmounts image from the loop device, and losetup properly detaches the loop. Otherwise you will get a "device busy" error when you try to unmount the drive during shutdown.
To write the ext2 filesystem to a CDR(w):
' cdrecord -v fs=5120k -eject dev=$CDR_DEVICE speed=$CDR_SPEED -data cdimage.raw '

dir == Same as (dir/w) in dos (GNU util)

' file * ' == See which files are exec (ELF), ASCII text, etc
+ Also: ' ls -apF '

gpm == (Daemon) Provides cut & paste between TEXT consoles only (not X)
+ Left mouse button = Select
+ Right mouse button = Paste

' head <file> ' == List first 10 lines of file
+ ' tail <file> ' == Last 10 lines of file (good for /var/log/messages, etc)

' less <filename> ' == A better "MORE" command; use ' / ' to search, 'b'=PgUp

' ln <existingfile> <yournewname> ' == Create SymLink to file in your new dir

' ln <origdir> <existingaliasdir> -sfn ' == Replace existing Link
+
+ Example:
+ ' ln /usr/src/linux-2.2.3 /usr/src/linux -sfn '

' locate <filename> ' == Search system DB for file (see 'updatedb')

' lpr <filename> ' == print file
' lpq -a ' == Spool status
' lprm <jobnum> ' == Cancel print job

ls == List (DIR); Permissions on Left are Owner,Group,All other users
+ ' ls -al ' == List All files, long form (Same as ' vdir ')
+ ' ls | more ' OR ' ls | less ' == (Less provides PgUp; '/'=Search (Pgup='b'))
+
+ The ' ls -l ' ( LS -L ) output format:

+          1
+ 1234567890      (UID)  (GID)  (or Node)
+ drwxr-xr-x 9999  Owner  Group  Size     Date  Time  Filename
+
+ d          == Directory
+ l          == Link (Symlink) to another file
+  r         == Read access for User / Owner (see 'chmod')
+   w        == Write access for User / Owner
+    x       == User is able to eXecute (run) this file
+     r      == Read for Group
+      w     == Write for Group
+       x    == eXec for Group
+        r   == Read for All other users
*         w  == Write for All other users
+          x == eXec for All other users
+ (Other values in column 1)
+ c          == Character mode device
+ b          == Block device
+ p          == Pipe?
+ s          == Socket?

' mimencode -u -o <outfile> <infile> ' == Translate MIME encoded file to straight-text.
+ (Take ALL hdrs, etc out except for the actual encoded txt before using this command)

' mv <file1> <file2> ' == Move / Rename
' mv boot/boot/* /boot ' == Move duplicate dir (from botched restore or copy) to absolute-dir

rm == Delete file (ReMove)
" rm -- '<file>' " == (Literal: Include ' ' quotes) Remove any filename
' rm ./<filename> ' == Remove filename with illegal chars

' tail -f --lines 50 <filename> ' == Follow (loop) the last 50 lines of file

vdir == Same as ' ls -l ' (GNU util)

' watch -n 5 ls -l /mnt/zippy1 ' == CLS and redo <command> every 5 seconds


= Changing file permissions / group access:

chgrp == Give file access to Group
' chgrp -cvR <groupname> <file1> [ <file*> ] ' == Allow Group access to file(s)
+ ('R' is Recursive, also for the following cmds)

chmod == Modify file attributes for:
+ User, Group, AllOtherusers (non-group), or Allusers
+
+ Note: For readability, '.' in the LS example stands for any value
+ (Command example does not affect this position)
+
+ Note: For readability, '-' in the LS example stands for No access
+ (Command example DOES affect this position)
+
+ Note: For the purposes of brevity, all ' LS ' examples for chmod are assumed ' LS -L '.

' chmod -cv +x <file> ' == Make Executable for Owner(?) (LS == ?..x...... )
' chmod -cv a+x <file> ' == Make file executable for All users (LS == ?..x..x..x )
' chmod -cv u+rwx <file> ' == Make file Read,Write,Exec for User(Owner) (LS == ?rwx...... )
' chmod -cvR g+rwx <file*> ' == Make files Read,Write,Exec for Group (LS == ?...rwx... )
' chmod -cvR o+rwx <file*> ' == Give access for AllOther users not in Group (LS == ?......rwx )
' chmod -cvR o-rwx <file*> ' == Remove access for AllOther users not in Group (LS == ???????--- )
' chmod -cv a-rwx <file*> ' == Remove ALL access for ALL users except root


Chmod addendum/shortcut from Glenn Milley:

"Chmod may also be revised or set using an octal value, with a three
 digit sequence (req'd.), or alternatively with a fourth, leading digit.
 The relation between the alpha designations and the octal are shown below:

 ===== ( Optional fourth leading digit: )
 s       4       Set user ID (SUID; usually root) on execution  
 s       2       Set group ID on execution  
 t       1       Set sticky bit            
 ===== ( Regular settings: )
 r       4       Read         \
 w       2       Write         > Add these together for each position (user,group,other)
 x       1       execute      /

 Special Characteristics         User/Owner      Group   Others
                                 (u)             (g)     (o)
 --------------------------------------------------------
         4 (s)                   4       4       4       (r-typical)                                   
         2 (s)                   2       2       2       (w-typical)
         1 (t)                   1       1       1       (x-typical)

 Now you just make the selections and add the values in the appropriate
 column, e.g.,

 chmod 4755 <file1> is the same as,
+  chmod u=srwx,g=rx,o=rx <file1>

 To set Read,Write,Execute for userid only on a file and deny all other access:
+  chmod 700 <file>

 Note that the "=" sign defines permissions, a "+" would add and a "-" remove."

******** Further explanation: Security portal

chown == Give ownership of file away (Change Owner)
' chown -cvR <newowner> <file1> [file2] [file*] '
' chown -cvR djbechte.wheel <files*> ' == Give djbechte in group wheel ownership of files* in this dir and subdirs

1a. ' chgrp -cvR wheel /bin/AfterStep ' == Give group 'wheel' ownership of AfterStep directory and subdirs

OR:

1b. ' chown -cvR root.wheel AfterStep ' == Root still owns, wheel group can access

***

2. ' chmod -cvR g+rw AfterStep ' == Give Group Read/Write access to A.S.


=Process / Job Mgmt:

jobs == Status of running jobs (background)
+ ' kill %1 ' == Kill job #1 from JOBS list
+ ' fg %n ' == Bring job #n to foreground (can also do 'bg')

' kill <pid> ' == Kill process
' kill -9 <pid> ' == Force process

' kill -l ' == Print list of Kill Signals

+1) SIGHUP       2) SIGINT       3) SIGQUIT      4) SIGILL
 5) SIGTRAP      6) SIGABRT      7) SIGBUS       8) SIGFPE
 9) SIGKILL     10) SIGUSR1     11) SIGSEGV     12) SIGUSR2
13) SIGPIPE     14) SIGALRM     15) SIGTERM     17) SIGCHLD
18) SIGCONT     19) SIGSTOP     20) SIGTSTP     21) SIGTTIN
22) SIGTTOU     23) SIGURG      24) SIGXCPU     25) SIGXFSZ
26) SIGVTALRM   27) SIGPROF     28) SIGWINCH    29) SIGIO
30) SIGPWR      31) SIGSYS      32) SIGRTMIN    33) SIGRTMIN+1
34) SIGRTMIN+2  35) SIGRTMIN+3  36) SIGRTMIN+4  37) SIGRTMIN+5
38) SIGRTMIN+6  39) SIGRTMIN+7  40) SIGRTMIN+8  41) SIGRTMIN+9
42) SIGRTMIN+10 43) SIGRTMIN+11 44) SIGRTMIN+12 45) SIGRTMIN+13
46) SIGRTMIN+14 47) SIGRTMIN+15 48) SIGRTMAX-15 49) SIGRTMAX-14
50) SIGRTMAX-13 51) SIGRTMAX-12 52) SIGRTMAX-11 53) SIGRTMAX-10
54) SIGRTMAX-9  55) SIGRTMAX-8  56) SIGRTMAX-7  57) SIGRTMAX-6
58) SIGRTMAX-5  59) SIGRTMAX-4  60) SIGRTMAX-3  61) SIGRTMAX-2
62) SIGRTMAX-1  63) SIGRTMAX

ps == Process status
+ Note: Don't use ' - ' before PS options on Linux anymore (new BSD syntax)

' ps ax ' == See ALL processes on sys
' ps ax | grep <programname> ' == See if program is running
' ps eww <pid> ' == See entire command line for Process
* (Can use more 'w's if necessary to see Entire cmd line)

nice == Run program in BG (Batch); can also set priority
' nice top -d 10 ' == Run "top" process monitor, update 10 secs

' nohup <program / command> > /dev/null & ' == Run (command or program) in background, send output to /dev/null or other file, and continue running even if user logs off; (see man page)
+ ' disown -h jobnumber ' == Running job ("%1" or the like) is not removed from the ' jobs ' table but the job will not terminate if the current shell logs off or receives a SIGHUP.
+ ' disown -ar ' == All Running jobs will not terminate if the current shell logs off or receives a SIGHUP. (See ' man bash ' and /disown.)


=Printing commands:

' lpr <filename> ' == Send a file to the print spooler

' lpq ' == Query the print spooler for waiting jobs

' lprm <pid> ' == Remove jobid from print spool


=Admin:

' adduser <username> ' == Create new user in /home directory (ROOT)
+ ' passwd <username> ' == Change passwd for user (ROOT)

' crontabs -e ' == Edit CRON timetable for scheduled events (ROOT)

df == Disk free space
du == Disk usage
+ ' du /usr -h ' == See disk usage for specific directory / mount point, in Human-readable (Kilobytes) format
+ ' du -s | sort -rn | head -10 ' == Find the disk hog

dmesg == Look at kernel boot-log messages

' fdisk -l ' == List all partitions (ROOT)

How to copy information from one drive to another:
' mkdir /mnt/newdrive ' == Make temp dir
.
' for i in / /usr /home; do '
'  cp -pax $i /mnt/newdrive '
' done ' == Copy three directories from one drive to another (useful for new drive install)

free == Memory display (Also use local MEM cmd)
+ OR: ' cat /proc/meminfo '

e2fsck == ext2 filesystem chk (umount or mount read-only first!) (ROOT)
fsck == CHKDSK (ROOT)

' fuser -n /dev/dsp ' == Find out who's using / tying up the sound device
+' lsof | grep /mnt/drived ' == Find out who's accessing /mnt/drived

' hdparm /dev/hdc ' == Display drive geometry (ROOT)

kill == See "Process / Job Mgmt"

' last <userid> ' == See when <user> logged in last / is logged in

lsmod == List loaded kernel modules (ROOT)
+ ' modprobe ppa ' == Insert module "/lib/modules/2.4.20-xfs/kernel/drivers/scsi/ppa" into kernel (Note: ' insmod ' is deprecated.)
+ rmmod == Remove loaded module dynamically
+ ' /sbin/modprobe -l ' == List available modules
+ ' depmod -a ' == Resolve module dependencies

' mke2fs -c -m1 /dev/hdc1 ' == Format partition with EXT2 filesystem
* (FDISK /dev/hdc 1st!) (ROOT)

' mkbootdisk <kernel.version.number> ' == Make kernel boot disk on floppy
+ ' make zdisk ' == From /usr/src - makes from kernel source

' mount /mnt/cdrom ' == Look in /etc/fstab for cdrom and mount it
' mount -a ' == Mount all filesystems in /etc/fstab that are not marked with the "noauto" option

' mount imagefile.img /mnt/tmp -t msdos -o loop ' == Mount a disk image file

' mount -t <msdos / vfat / minix / ext2 / iso9660> \
 /dev/xxx /mountpoint [-o ro,exec,sync] ' == Mount syntax

' mount <-r / -o ro> /mnt/drivec ' == Mount a partition readonly
' mount /mnt/drivec -oremount,ro ' == Mount an already-mounted partition readonly

mtools == MSDOS Disk tools; format, etc:
+ mattrib
+ mbadblocks <drive:> == Check for bad blocks
+ mcd == CD
+ mcopy == Copy
+ mdel
+ mdeltree
+ mdir
+ mdu == Disk usage
+ mformat
+ mkmanifest == Translate Unix long filenames to MSDOS using packing-list
+ minfo == Print params of Dos filesystem (can use with Mformat)
+ mlabel
+ mmd == MakeDir
+ mmove
+ mpartition (non-Linux systems)
+ mrd == Rmdir
+ mren == Rename
+ mshowfat == Show FAT entries for file
+ mtype == Type to console
+ xcopy == (Kludge for now)

' nice <program> ' == Start program with low CPU requirements / priority
' nice -1 <program> ' == As root, Start program with HIGH CPU priority

renice == Adjust process priority
' renice +1 <pid> ' == Lower priority of pid

' renice +1 -u spoogeboy ' == Lower priority of all processes owned by user

' renice +1 -u spoogeboy -p <pid> -u goovbol -p <pid> ' == Alternate between usernames and pids

rehash == Update internal hash exec tables (*MAY no longer be supported - ?)

su [userid] == Defaults to ROOT; type EXIT when done == SuperUser / SwitchUser
+ ' su - ' == Switch User to ROOT, acts just like a "login" and sets up environment; type EXIT when done

top == Glance-like interactive CPU usage

' updatedb & ' == Refresh system db for locations of all files (see 'locate')

whoami == ID current user


=RPM Package Manager:

glint == X windows frontend to RPM (and BOY does it SUCK)
kpackage == KDE package manager

Tip: Instead of typing something like " RPM -i dosemu.arch.i386.rpm ", you can instead type:
+ " rpm -i dosemu*.rpm ".

How to INSTALL packages:
+ ' rpm -i --percent --replacefiles <pkgname / package*> '
* == Install package (dosemu.blah.rpm)

How to UPGRADE packages:
+ ' rpm -Uv --percent <pkgname> '
++ ' [ --oldpackage ] ' == Add this switch to allow older pkg to replace newer
++ ' [ --replacepkgs ] ' == Add to Force RPM to upgrade

How to UNINSTALL packages:
+ ' rpm -e <pkg> ' == Uninstall <dosemu>, not " dosemu.ver.arch.rpm "!!
+ ' rpm -e --nodeps <pkg> ' == Uninstall and forget dependencies
+ ' rpm -e -vv --test <pkg> ' == Simulate uninstall
+ (-vv=Print out all debug info)

How to QUERY packages:
+ ' rpm -q ' == Query package(s)
+ ' rpm -qi <pkg> ' == Detailed pkg info
+ ' rpm -qa | less ' == Query ALL installed packages
+ ' rpm -qail > ~/Allpkginfo ' == List all installed packages, their descriptions, and all files in the package to a file
+ ' rpm -qip * ' == Query ALL packages whether installed or not (you should be in the CDROM RPM dir for this)

' rpm --rebuilddb ' == Rebuild RPM database


=Using tar/zip/gzip/bzip2:

Note: ' gzip -9 gives similar results to ' bzip2 ', and runs MUCH faster.

Bzip2 home page: Here

' bzip2 -cd file.tar.bz2 | tar tvf - ' == View the contents of a bzip2 file
' bzip2 -cd file.tar.bz2 | tar xvf - ' == Extract files from bzip2

' bzip2 -zv9 filename ' == Compress file and MOVE it into a .BZ2 (use ' bzcat ' if you need to read/pipe it)

Using bzip2 instead of gzip to create a tarfile:
' cd <sourcedir> ' == Get to the dir you want to make a backup of
' tar -cv . | bzip2 > tarfile.tar.bz2 ' == Create tar image of current dir, pipe it to bzip2, route output to filename
' bzip2 -cd tarfile.bz2 | tar tfv - > tarname.LIST' == List files in tar.bz2 verbosely to tarname.LIST file


' gunzip <archive> ' == Careful with this, it uncompresses the .gz and leaves tar!
+ (This is usually not necessarily what you want. You're better off
+ redirecting tar.gz output to a pipe.)

' gzip -l <archive> ' == List the tar filename contained in .gz

' gzip -cd <tarfile.tar.gz> |tar tf - ' == List files in tar.gz

' tar -tz -f <archive.tar.gz> >files.list ' == List files in archive to output-file

' tar -tvf <tarfile.bz2> --use-compress-program bzip2 ' == Use bzip2 instead of gzip and list files verbosely


Unzipping multiple .ZIP files using wildcards:
' unzip -lc no\*.zip \*.it ' == Unzip all " .it " (Impulse Tracker) files in all " no*.zip " files (such as NOISE music to the current directory. (Need to use ' \ ' as an escape char so shell (bash?) does not expand the '*' and send files to the unzip program, but lets the unzip program handle wildcard expansion instead.)
+ Explanation from Portico: "April, 18:38:55 - If you are using the unzip program, and are trying to unzip multiple files at one time, you will notice that this does not work: ' unzip *.zip '. The reason that does not work is because your shell is handling the '*' for you, and passing all those file names to unzip, which unzip does not want. The correct way to do this would be " unzip '*.zip' " since unzip will handle wildcard expansion for you."

How to Copy a directory hierarchy to DIR2:
' cd <dir1> '
' tar cfv - . | (cd <dir2>;tar xf -) '

How to use TAR to INSTALL SOFTWARE:
See also: Linux Gazette, Issue 38
Tip: You should usually be ROOT to install software.
' tar -tzf <yourtar>.tar.gz |less ' == Check contents for dir structure (or use MC)
' cd <dirtoinstallto> ' == (Usually /usr/local/src for source code, or /usr/local/bin for binaries.) I usually install to /tmp/install at first.
' tar xzf <yourtar>.tar.gz ' == Extract
' cd <newsoftwaredir> '
' less README '
' ./configure '
' make install '

How to extract a tarball to a different dir:
' cd <newdir> '
' tar zxv -f <tarfile> ' == Untar existing tarball to current dir;
* ( OR: ) *
' tar -xzv -f <archive> <root/*> ' == Example using specific dir in archive
If ' pwd ' = /rootski, the resulting files are put in /rootski/root/* -- so rename dirs as necessary

How to make a full bkp:
' init 1 ' == And wait until you are in single-user mode
' tar -cpzhvX /Excluded.from.bkp.list -f fullbkp19990101.tar.gz / ' ' -c ' == Create new archive
' -p ' == Same permissions
' -z ' == Use gzip
' -h ' == Backup symlinked files, not just their links (Optional)
' -v ' == Verbose
' -X ' == Exclude files contained in following name
' gzip -t fullbkp*.tar.gz ' == Test archive

How to Restore from a full backup using a list of filenames contained in a file named ' /RestoreThese ':
' cd / '
' tar -xzvp --checkpoint --same-owner -f fullbkp*.gz \
 --files-from /RestoreThese '

How to backup Netscape to an ext2 Zip drive:
' tar -cpz /usr/local/netscape > /mnt/zippy1/netscapebkp.tar.gz ' ' -c ' == Create new tar
' -p ' == Same permissions
' -P ' == Absolute paths
' -z ' == Use Gzip

How to backup your /boot directory to a Zip drive and use BZIP2:
' tar -cp --use-compress-program bzip2 -f /mnt/zippy1/bootdir.tar.bz2 /boot/* ' == Traditional Dos-like syntax
** OR: **
' tar -cpv /boot/* | bzip2 > /mnt/zippy1/bootdir.tar.bz2 == Same result, only the -cpv lists the files as they go

Now, to list the files in the archive you just created:
' tar tf /mnt/zippy1/bootdir.tar.bz2 --use-compress-program bzip2 ' == List files in the new archive
** OR: **
' bzip2 -cd /mnt/zippy1/bootdir.tar.bz2 | tar tfv - ' == Same result

' zip -9r <archivename> <dir1 / file1> ' == Zip using max compress, Recurse dirs (Not recommended for Linux files; only TAR can keep permissions - but works fine for FAT32)
' tar cvf <dir> | zip -9 archivename - ' == This is probably what you want to do instead. It uses tar to store files and recurse dirs, but stores the big tarfile in a .ZIP with maximum compression
' unzip -p archivename | tar xf - ' == Unzip to Pipe (stdout) and use tar to extract the files

Translating between MSDOS CR+LF to Linux LF-only
' zip -l ' == Translate Linux LF to MSDOS CR+LF
' zip -ll ' == Translate CR+LF to LF
Example:
' cat infile |zip -ll - - |funzip >newfile ' == Translate MSDOS CR+LF to LF


=Networking:

connect == Connect via PPP using local alias (This is only for my machine; *I* use this doc as a Reference, too :)

' ifconfig ' == Display networking devices such as eth0, ppp0

' /bin/netstat -rn ' == Use if ' route ' fails to return a display

' /usr/bin/nslookup <IP addr / hostname> ' == Resolve IP addr to hostname / vice versa

' /bin/ping <10.200.10.40> ' == Test response time / availability
+ ' ping altavista.digital.com/ ' == Ping sitename

' /usr/sbin/traceroute <IP addr / hostname> ' == Display all hops between you and dest

PPP login script name: ' /etc/sysconfig/network-scripts/chat-ppp0 '

Fun with netcat(TM):

' netcat -l -p 32121 < filename ' == Server side == Listen on port 32121 and upload FILE to that socket when something connects to it
+ Remote side: Point browser to http://serverside:32121, and the file will be downloaded to the browser! You will have to give it a name though.

' netcat -l -p 32121 > filename ' == Server side == Listen on port 32121 and output whatever connects to it to FILE
+ ' cat filename | netcat -w 2 serverside 32121 ' == Send FILE to remote box without FTP :)

' netcat -l -p 32100 > | tar xvpf - ' == Server side == Listen on port 32100 and extract the connecting output as a tar file
+ ' tar cpf - directory | netcat -w 2 serverside 32100 ' == Send tar FILE to remote box and have it extracted on the other side


=Directories:

' /bin ' == Most commonly used essential user programs
+ Shells(bash, ksh), cp, mv, ln, tar, Editors, mount, dd, uname, hostname

' /boot ' == Boot information

' /dev ' == Devices

' /etc ' == Systemwide configuration files
' /etc/skel ' == Adduser skeleton files

' /lib ' == System libraries
' /lost+found ' == Files recovered from fsck

' /mnt ' == Mount point for removable disks

' /proc ' == Special directory with sys info

' /root/bin OR /user/xxx/bin ' == Put shell scripts here, use CHMOD +X

' /sbin ' == Essential sysadmin programs
+ (fsck, fdisk, shutdown, lilo)

' /tmp ' == Throwaway files; also start point for installing progs

' /usr/doc ' == Where DOCumentation lives
' /usr/bin ' == Vast majority of installed execs

' /usr/doc ' == Documentation
' /usr/doc/HOWTO ' == Where the HOWTO's live
' /usr/info ' == GNU Info files

' /usr/lib ' == Additional libraries

' /usr/local ' == Files generally not supplied by the distribution
' /usr/local/bin ' == Exec Files installed locally
' /usr/opt ' == Optional packages installed here

' /usr/share ' == Shared files
' /usr/sbin ' == Additional system progs

' /usr/src ' == Source code dirs

' /usr/X11R6/lib/X11 ' == Location of Xwindows cfg file

' /var ' == Variable-information files
' /var/lock ' == Lock files for executing progs
' /var/log ' == Log files
' /var/spool ' == Spoolfiles
' /var/spool/mail ' == User mailbox files

' /etc/rc.d/rc.sysinit ' == Execute this ONCE at bootup; fsck, mounts, etc
' /etc/rc.d/rc.local ' == Autoexec after all other inits; write login screen
' /etc/profile ' == Global cfg; Systemwide shell init (PATH, PS1) Keep short!

' /etc/motd ' == Message of the day

' /etc/fstab ' == File system / mount table
' /etc/lilo.conf ' == LILO configuration file

' /home/dave/.bashrc ' == Shell aliases for local user "dave"
' /etc/bashrc ' == Global aliases
' /root/.bashrc ' == Root's aliases
' /etc/shells ' == Approved shells that users can use

' /usr/src/linux ' == Soft symlink to current kernel (/usr/src/linux-2.0.34)
' /usr/src/linux/drivers/scsi/README.ppa ' == Zippy driver info

' /etc/services ' == Show which ports are used
' /proc/interrupts ' == Show which IRQ's in use (can only use cat or more to read)

' /var/lib/locatedb ' == This is where the "updatedb" script stores its results
' /var/log/dmesg ' == Messages displayed when system was last booted
' /var/log/messages ' == Check for PPP connect, general system msgs
+ Trim it every so often, it keeps growing!!

' /usr/src/Newkernel / XNewkernel ' == Recompile kernel (Local alias)
' /usr/share/afterstep ' == Afterstep config file location


=Useful progs:

/sbin: (CRITICAL System files)

/usr/sbin:

/usr/bin:

(Local Installs by me:)
/usr/local/bin:


=X Windows:

Ctrl-Alt-'+' == Next higher resolution
Ctrl-Alt-'-'
Ctrl-Alt-Bkspc == Emergency Exit
Ctrl-Alt-Shift-Arrow == Move around in virtual desktops

' startx ' == Start X windows shell (don't use &)
+ ' startx -- :0 ' == (default) Start first instance of X window (Alt-F7)
+ ' startx -- :1 ' == Start second X window on (Alt-F8), can be diff userid.
+

+ ( Startx runs .xinitrc, or /usr/X11R6/lib/X11/xinit,
+   then        .Xclients, or /etc/X11/xinit/Xclients )
+
+ To bypass startx, use xinit directly:
+ xinit /usr/bin/sawfish & == Start sawfish window manager

' import -display localhost:0.0 -window root screenshot.jpg ' -- If you have ImageMagick installed, this takes a screenshot of your root X display. (Use from a text VC such as alt-F2.)

' Xconfigurator ' == X Windows setup prog (Case sensitive!)

' netscape ' == Start netscape using alias (/usr/local/netscape/netscape)

' xlock -nolock <-inroot> -mode <modex> ' == Start screensaver

+  Good modex: bouboule, bat, eyes, flag, galaxy, geometry, hyper<cube>,
+              world, worm, kaleid, lissie, lightning, maze, mountain,
+              penrose, pyro, qix, spiral, star, slip, swarm

' xset s off ' == Turn off screen saver for X

' xv -root -max -quit <yyy.jpg> ' == Set X background pic, Fullscreen
+ ( Without ' -max ' == Tile )
+ ' [-random <dir>/*.gif] ' == Pic at random
+ ' [-ncols 16] ' == Limit to 16 colors
+ ' [rmode -1] ' == Tile
+ ' [rmode -2] ' == Mirrored tile
+ ' [rmode -4] ' == Centered tile
+ ' [rmode -6] ' == Centered Warp


=Misc:

Video chipset for GB3D: CL-GD546x (4) Meg of RAM (Cirrus chipset)


=Kernel upgrading:

  1. Compile speedup:
  2. " alias make='make -s -j 3' "



===

' cd /usr/src '
' mkdir linux-2.4.1 ' == (Whatever kernel #)

' ln linux-2.4.1 linux -sfn ' == Create/update symlink to point to new src

' tar xzvf linux-2.4.1.tar.gz ' == Extract entire source tree using gzip

[*** Patching:

     0. [ mv patchfile.tgz /usr/src ] == Not necessary, 
          but might be useful to keep all patches in the src directory
     1. cd /usr/src

     2. gzip -cd patch-xx.gz | patch -p0 == This way you don't have to uncompress
        the patch.

     (If it prompts for which file to patch and the dir is sparc,alpha, etc:
      Just press Enter and then Y to skip patch)
      
     3. Repeat the 'gzip' (#2) step for each patch in sequential order (2.4.1,
        2.4.2, etc.)

     4. When done patching: ' mv linux-2.4.1 linux-2.4.8 ' == Rename original
          dir to latest patch version

     5. ' cd /usr/src '
     6  ' ln linux-2.4.9 linux -sfn ' == Re-make soft symlink 
        (Use latest patch version instead of 2.4.1)< 

***]

' cd /usr/src/linux ' == Linux=Symlink to /usr/src/linux-2.2.xx

' make mrproper ' == OPTIONAL - only if you want to start fresh!
' make <config / menuconfig / xconfig> '
* ( xconfig files are saved in /usr/src/linux )

' mkdir /lib/modules/<kernelver>.old ' (2.4.19.old)
' cd /lib/modules '
' mv 2.4.19 2.4.19.old ' == Keep backup copy of modules
' mkdir <newkernel#> ' (such as 2.4.20)
' ln <kernelver> preferred -sfn '

' cd - ' == Back to /usr/src/linux
' time make dep && time make bzImage && time make modules && time make modules_install '

Important note: Watch for errors here! Don't continue if you get any!!



' depmod -a * ' == Resolve modules
' /usr/sbin/mkinitrd --ifneeded -v /boot/initrd-2.4.1.img 2.4.1
+
+ You may have to copy some .o files from /usr/src/linux/drivers into
+ /lib/modules/preferred if the mkinitrd fails.

' cd /boot '
' ln initrd-2.4.1.img initrd -sfn '

' cd /usr/src/linux '
' cp arch/i386/boot/bzImage /boot/vmlinuz-2.4.1 ' == New kernel #
+ (Old method: Fullpath) ' cp /usr/src/linux/arch/i386/boot/bzImage /boot/vmlinuz-2.4.1 '

' cp System.map /boot/System.map-2.4.1 '

' cd /boot '
' ln vmlinuz-2.4.xx-whatever vmlinuz -sfn ' == Symlink update
' ln System.map-2.4.xx-whatever System.map -sfn '

[ edit /etc/lilo.conf ] == If necessary, make sure you can boot to old kernel

' /sbin/lilo -v=2 ' == You should see "Writing boot sector." at the end - if not, ERROR!!
+ You can use ' lilo -v=2 -b /dev/fd0 ' to write the Lilo bootsector to a floppy disk.

' reboot ' == ( shutdown -r now )

Kernel 2.6 tips



Linux Tips - Tips for Linux/Unix users and newbies
Copyright (C) 1999, 2000 David J Bechtel

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.


This document was converted with the help of txt2html and asWedit. I have also used Bluefish for Linux to modify it.
My thanks to the authors.