Tags:
create new tag
, view all tags
GNU Shortcuts contains some dirty short tips and tricks about how to use a bunch of command line programms in the shell. It will not necessarily be limited to GNU programs. (By "shortcut" I mean something like abreviation or the german word "Abkuerzung". Please correct me if you know a better word for it.)

See also LinuxCommands.

See AboutThesePages.

Introduction

GNU Shortcuts contains some dirty short tips and tricks about how to use a bunch of command line programms in the shell. It will not be necessary be limited to GNU programs. (Shortcut shall mean something like abreviation or the german word "Abkuerzung". Please correct me if you know a better word for it.)

Who ever is using one of the below described programs and curses because of its limitations, please do a "man program" in the shell to see the power all these programs have. This topic contains some of the command line options for those helpful programs that I need again and again and that I forget again and again smile or the same stuff about program I read about and do not want to forget. (So it shall become a note book for me too)

There might be some of my german notes left. Sometimes because I did not start on translating them and other times because I find them better than my translations and leave it on others to delete them.

Usefull Sites

This site is real good stuff!!!

http://www.act.cmis.csiro.au/gjw/linux/dlcpid300xt.html

A cookbook at its best!!!

Useful Commands (with some basic options)

mii-tool

Set and check things as: eth1: 10 Mbit, half duplex, link ok (Output on my server smile This utility checks or sets the status of a network interface's Media Independent Interface (MII) unit. Most fast ethernet adapters use an MII to autonegotiate link speed and duplex setting.

sitar - System InformaTion At Runtime

It is a Perl Script which reads the /proc filesystem and produces a fantastic html file that contains everything on your system.

To my opinion it should be fine to install the src rpm as it is a perl script and to my understanding there is no such thing as a binary distributioni.

Main.StefanWolber: Do you have a link to sitar? It might be helpful to include one here (and maybe for other similar utilities, like ttt, below?) as it does not seem to be included in, for example, my default install of Mandrake 9.1

ttt - Tele Traffic Tapper

Ttt monitors the network and automatically picks up the main contributors of the traffic within the time window (60 sec by default). You can see the behavior of the traffic of the past 60 seconds. The graphs are updated every second by default. Also, you can do remote monitoring using tttprobe and tttview programs.

arp -a | sort +1

Lists the IP Adress - MAC Adress resolution on your machine. The sort command make only sense on servers where more MAC Addresses are known. In this case it sorts for the second column. more commands on arp:

Show ARP table contents - arp -a

Add ARP perm. entry (Unix and OS/2) - arp -s 'ip_addr' 00:00:00:00:00:00

Add ARP temp. entry (Unix and OS/2) - arp -s 'ip_addr' 00:00:00:00:00:00 temp

Add ARP entry (Windows) - arp -s 'ip_addr' 00-00-00-00-00-00

Add ARP entry (recent Windows) - arp -s 'ip_addr' 00-00-00-00-00-00 'if_addr'

Delete ARP table entry - arp -d 'ip_addr'

cat /etc/passwd | grep "^$LOGNAME:" | cut -d: -f5 | cut -d, -f1

  • (wb) [[][]] --

This is used here as a first example for shell commands and will be discussed in detail below. Lots of further examples will be discussed below. cat prints out a file to stdout. stdout is usually in the bash the console or monitor. That means everything is running down in your shell as long as as the file is. (/dev/stdout) | is called a pipe and use to connect the stdout of one program with the stdin of another program. stdin is the standard input of a program, usually the keyboard. (/dev/stdin) | is the main reason why those Gurus keep on telling us to use the shell. There are lots of programs (as further discussed below, that are very good in one thing. Piping them together gives you an awfull lot of power (at least in the shell) as long as you know what you are doing. For all others (as me) this shortcuts shall help at least with some features.

What follows in above example is a substitution. In a shell there are predefined variables. (Best known also from M$ is the PATH variable. (Oh, I guess I am writing to much but everything under this first extensive documented example will be short (I promise))). "" tells that what is in between shall be substituted first. $LOGNAME tells the shell to use the LOGNAME variable that is defined when somebody logs in. (you can view the value of a variable by "echo $LOGNAME"). The first charakter in "^$LOGNAME:" calls some of the upper magics (as far as I understand it) called Regexp or Regular Expressions. To me it says it shall look for a line where the first thing (long sentence for the meaning of ^) is your login name.

grep is handy for searching. For example if you type "grep FU" it looks in the actual directory for a file with the string "FU". In the above mentioned case grep searches the stream that comes from stdin for all lines that contain your login name from the file passwd and puts those lines to stdout. There is another little program waiting that cuts every thing before column 5.

cut cuts from the input if the input is structured by delimiters (in M$ world this format is some times called csv (comma separated values) Excel can also export its tables structured). First thing to define are the delimiters (with csv it's per default a ","). This is the same as with the sort program. It's done with -d: which tells cut that it shall expect colums between the delimiters. To see what I am talking about just put in the bash a cut /etc/passwd.

grep -Hn httpd/htdocs *

Shows you recursively (from this directory to all subdirectories) all files (with filenames in the beginning) and the line number any occurances of httpd/htdocs

There is a better phrase for this that I allways forget as I never noted it here. Something with "find ."

xfontsel

X Font Select / Shows which Fonts and Sizes are available. Zeigtan welche Schriften, Zeichensätze und Grössen verfügbar sind.

Example for a shell script (That makes a file of thumpnails for a directory with pictures:

#!/bin/bash for i in *.jpg; do convert $i -geometry 75x75\! `basename $i .jpg`_small.jpg done The ! after 75x75 is masked by

showkey

- Eingabe - nicht unter Terminalemulation unter X - sondern in Konsole, zeigt gedrückte Taste an.

loadkeys personal.map

grep string /etc/init.d/*

sucht in /etc/init.d/ alle Dateien nach string ab.

ntpdate -s ntp.uni-trier.de slug.ctv.es ntp.maths.tcd.ie ntp.cs.strath.ac.uk

(Befehl nach ip-up, -s leitet Fehler und Statusmeldungen in das Syslog um) ntpd -q sorgt für einmaligen Abgleich. Dafür wird benötigt, eine Datei /etc/ntp.conf mit obigen Server vorher steht jeweilig server und danach iburst. /sbin/hwclock --systohc --utc sorgt für weitergabe der Systemzeit auf die Hardwareuhr

grep

-i Gross- und Kleinschreibung ignoriren - l nur Dateinamen in denen Ausdruck gefunden wurde, nicht zugehörige Textzeile -v nur Textzeile ohne Ausdruck -3 jeweils 3 Zeilen vor und nach Textzeile mit Ausdruck (-A3 nur 3 folgende -B3 vorhergehende Zeilen -E '(Bus|Bahn|Flugzeug)' Verkehr.txt reagiert auf jedes der Wörter

perl -pi~ -e 's/abc/def/g' file.txt

makes file.txt~ and replaces in file.txt abc by def. (Specially for Peter Thoeny to be reviewed very carefully - he might learn something by this example :-))

whois

whois -h whois.server.net domain.de or whois whois.server.net@domainPLEASENOSPAM.de whois -h whois.iana.org de - Who is responsible for toplevel domain de Works also for IP. whois.arin.net tells who is responsible for IP

Crontab

2>&1 >/dev/null (no E-Mail to owner) @reboot instead of timetable at the beginning starts programs at reboot 2>/dev/null gives all messages in stderr to NIL, 1 is for all normal output (stdout)

Icoutils

extracts Icons from Windowsprograms.

du -mscx * | sort -nr > /datsize

shows the size of the directories with the biggest files first in the file datsize in the root directory

root-tail -f -g 80x25+0-52 -fn 6x10 -shade /var/log/messages,white

/var/log/ker.log,green (Shows the log files on the root-window (background of the X-Desktop - is over written by KDE), see LinuxUser 12/02 for installation notes.

man -P "less +'/*umask*'" bash

Searche the manpage of "bash" for the expression "umask" in all words (gives also gluemasking) and use less to give the result.

id [username] Shows the informations from /etc/passwd and /etc/group

for the actual user or any other user as specified in the brackets.

logger "test 12" writes "test 12" to /var/log/messages

tailbeep -f /var/log/messages -s "test 12" -t /dev/tty12

with -x a program can be started. Tailbeep can be started during the init procedure -> see LinuxUser 12/02 Reads /etc/tailbeep.conf FILE="/var/log/messages" PAT="search_pattern" FREQ="5000" DUR="25"

convert earth.png earth.bmp

The progam convert is part of the ImageMagick tool package. Beneath lots of other stuff it can convert from one graphic file format to another.

convert - detailed description

aus dem ImageMagick Paket

convert -page A4 huehner.jpg document.ps Skaliert das Document so, das es eine DIN A4 Seite gut ausfüllt.

convert 'vid:*.jpg' directory.jpg Erstellen eine Inhaltsverzeichnisses eines Verzeichnisses mit jpg Dateien.

convert -font @d-worcti.ttf -pointsize 50 -pen white -draw "text 50,50 'Viele Huehner'" huehner.jpg huehner_txt.jpg 50 pixel nach rechts und unten wird mit 50 Punkt größe weiss der Text geschrieben und in neuer Datei gesichert.

convert -mattecolor blue - frame 6x6 alte.datei neue.datei zeichnet einen vertikal und horizontal jeweils 6 pixel breiten Rahmen um das alte Bild und speichert in neuem.

convert -geometry 640x480 konvertiert bei konstanten Seitenverhältniss beliebige Datei, z.B. 320x200 pixel nach 640x400

convert -geometry 640x480! verzerrt

convert -geometry 200% vergrößert

siehe shell script zum Anlegen von Thumbnails bei Tools

Regexp

hu.. (. Ein beliebiges Zeichen - huhn oder hund. hut nur mit folgendem Leerzeichen) ^ Zeilenanfang $ Ende * beliebig viele Zeichen me*r = meeeer, mr (auch 0 Zeichen) tt+n = ttn, tttn, tttttn nicht tn jo.*nes = jones, johannes, joghurt ist feines Essen [abc] a oder b oder c [a-zA-z0-9] = Bereiche (mit ^ am Anfang darf Zeichen nicht vorkommen) abc* = abc,abcc nicht abcabc (abc)*= abc, abcabc nicht abcc Sonderzeichen müssen in der Shell mit \ aktiviert werden \(abc\)\* (für die Shell noch von ' ' eingeschlossen) ausser egrep (grep '\(abc\)\*' oder egrep '(abc)*' wart(enIendIung) = warten oder wartend oder wartung)

(That's it for today, to be continued) (This first paragraph is only used to make sure that my internal linking works.) (I will then also make use of the existing skeleton to organize this topic)

ALLGEMEINE INFOS

Reset Windows Passwords or modify registry from Linux

Use the Knoppicilin cd from c't magazin. Mount the appropriate partition. (mount /dev/hda1 /mnt/hda1) Save it. (partimage) "cd /mnt/hda1/Windows/system32/config" (for Win XP. For Win NT and 2000 replace Windows with WINNT) If filesystem is FAT32 you can modify the registry data directly with chntpw (make a backup first), with NTFS you copy the registry files SAM, SECURITY, and system with "cp SAM SECURITY system /ramdisk" to the ramdisk and change to it. With "chntpw -i SAM SECURITY system" the tool starts interactively. Syskey should not be deactivated in Modus 1 (Syskey saves its additional key free accessible.) Deactivation is only necessary if the key is secured with an additional passphrase or if the key is external i.e. on a floppy. Now the user has to be choosen who will get a new passwd. Best is administrator. Administrator usually can do all other tasks thereafter under windows. Now the new password has to be choosen. Now the write access for the NTFS partition has to be enabled, "mount -o remount,rw /mnt/hda1". The original registry files should be saved (again smile before copying back the modified ones. Afterwards the NTFS partition should be umounted and checked with "ntfsfix /dev/hda1".

Another nice feature of chntpw is the simple registry editor. With it problems during broken programs during start up (autostart) can be fixed. With "chntpw -e software"the editor is started with the registry file software. The navigation is done as usually in a linux filesystem(incl. autocompletion). Automatical start up is done (next to others see c't 9/03) at "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\Current Version\Run**". With q all changes will be saved. For all the other procedures on NTFS please see above.

Convert from one E-Mail Programm to the other (for Example from Netscape / Mozilla to KMail

see http://www.timcoston.com/linux/index.php

Schuldistribution -> www.lernnetz-sh.de/kmLinux kmLinux

Serverdistribution: Fli4l und Eisfair ->

www.eisfair.org/german/download.htm (beide für kleinere altersschwache Rechner.

Rettungs CD Distributionen:

c't 2/02 CD, Knoppix

Infos über Linux booten -> LinuxUser 12/02

/proc

MagicSysRq-Key

With this procedure one can catch the system even if the system is hanging (Linus beware) It has to be enabled by "echo 1 > /proc/sys/kernel/sysrq"

Information about the startparameter of a process beg- cat

/proc/$PID/cmdline | tr "\000" " " -end

Information about the environment of a process beg- cat

/proc/$PID/environ | tr "\000" "\n" -end

fstab

1 2 3 4 5 6 /dev/hda1 /mnt auto defaults or auto, umask=0,uid=999,gid=555,exec,user,ro 0 0 1 - Device file (as listed at the /dev directory) 2 - Mount point 3 - Filesystem (auto is usually fine, other filesystems are iso9660,ntfs vfat, reiserfs, ext2, umsdos, nfs, smbfs, ignore - ignores Partition. None file systems are proc, usbdevfs and devpts). Use //wincomp/C /mnt/winc smbfs user,noauto,username="tux",password="Passwort" 0 0 (uses smbmount) linuxcomp:/home/stefan /nfs nfs user,noauto 0 0 (Everything has to be added to /etc/exports on linuxcomp) to mount the c drive of a windows computer in the net 4 - Options for the access. "defaults" is for the default. user tells that users are allowed to mount this device. exec tells that programms can be run. uid and gid tells the user who owns the file system. "auto" tells that the device is mounted during the system start. umask is setting the inverse access rights (7 minus the rights (0=rwx, 2=r-x, 1=rw-)). 5 - Options for dump (Program to backup the Ext2 filesystem) 6 - Options for consisty check by fsck. Root directory has to be marked with 1, all others with two and file systems that have not to be checked are 0.

Computer Rettung

Restore a damaged filesystem (Partition / Floppy) see LinuxUser 08/2004

dd_rescue /dev/hda3 /mnt/image.dat or dd_rescue /dev/fd0 /mnt/image.dat (dd_rescue continues dumping even with I/O errors it just fills zeros in there)

reiserfsck --fix-fixable /mnt/image.dat fsck.ext3 -p /mnt/image.dat fsck.vfat -A /mnt/image.dat

mkdir /temp mount -o loop,ro /mnt/image.dat /temp

Diverse Kommandos und Tools

cp -dpR /home/* /mnt (kopier Verzeichnisse rekursiv)

rm -R /home/* delete all files and directories in /home/

Novell -> Netadmin

(ct CD 2/02) gzip -c /mnt/foo > /fl/foo.gz

rm -rf /tmp/* (Alles in tmp löschen)

Teilen einer Datei split -b 1.440.000 file (ohne Punkte)

cat teil1 teil2 teil3 > Ziel (Zusammensetzen unter Linux)

copy /b teil1+teil2+teil3 Ziel (windows)

Image einer Partition dd if=/dev/hda1 I gzip -c > /mnt/image.gz (bei mehr als 2GB dd-lfs benutzen)

Zurück spielen gzip -d -c /mnt/image.gz I dd of=/dev/hda1

Von einer Partition auf andere kopieren dd if=/dev/hda1 of=/dev/hda6 (>2Gb->dd-lfs)

hexedit <2MB>vche Daten auf Festplatte bearbeiten: ct 6/00 S.116 ct 26/01 S.130

Rekonstruktion /Untersuchung kaputter Partionstabellen gpart -v -l /tmp/log /dev/hda (untersucht 1. IDE-Platte und schreibt Ergebnisse nach /tmp/log (s.man gpart) -> siehe auch e2fsck und debugfs

Manuelles Einrichten Netzwerkdevice ifconfig eth0 194.97.108.99 netmask 255.255.255.192 up route add default gw 194.97.108.65 eth0 export http_proxy=http://proxy.domain.net:8080 nc -> netcat tcpdump; nmap - testet Rechner auf offene Ports, netstat - Status Netzwerk, ping; host -a und dig checken Nameserver; arp zeigt MAC Adressen im Netzwerk

Mailadresse: wolber@skeeve:~> nslookup Default Server: LinServB.Buettner-Dryer.Com Address: 194.97.108.65

> set querytype=MX
> buettner-dryer.com

Knoppix specific stuff

Kompile Kernel

In /usr/src/linux/Makefile there is a variable EXTRAVERSION that has to be set to -xfs.

make-kpkg --append-to-version -ipsec --revision 1.0 \ --config x kernel-image modules-image

--apend-to-version appends some remarks for you to remember why you kompiled the adapted kernel. Additionally the modules directory at /lib/modules contains this remark and will not overwrite whatever you had there before. -- revision To my experience the kernel does not get assembled as a new package if there is already a package with the same name. -- config x is the same as make xconfig modules-image as a target compiles also other programs as for example the pcmcia paket.

make oldconfig will make a new .config for if the .config is from an older kernel. It will only ask questions for new options.

.config for knoppix is at /boot.

History in bash

May be add in /etc/inputrc: "C-v PgUp": history-search-backward "C-v PgDn": history-search-forward

where C-v PgUp is the way in Vim to enter the code of the key PgUp.

The history-search fonction allows to find lines in history that begins with the characters you already typed on the command line. By default, PgUp and PgDn are not mapped by bash, so this enhancement won't bother anyone.

Samba

We replaced our old Novell Server with a Linux / Samba combination. Ok I have to admit it was done by somebody else mostly, but at least I initated the process and am doing the fine adjustments (others will call it playing) right now.

smbstatus shows files locked by the system.

Contributors

  • (wb) StefanWolber - 11 Nov 2002
  • <If you edit this page: add your name here; move this to the next line; and include your comment marker (initials), if you have created one, in parenthesis before your WikiName.>

Comments on this Page

Main.RandyKramer: Thanks for your comments. I need some encouraging from time to time.

Me too! (So thanks!) - RandyKramer

_It alway astound me to see with how much stuff you fill this net smile

Thanks!

I added a link for sitar and for ttt.

Thanks!

I am running the Knoppix Distribution (Great Stuff - Debian based with great hardware recognition and you are able to run a hole Linux System from a CD without touching the harddrives and may install from there later). I also deleted your comments.

I'm running Knoppix (3.2) also at this point (on my "main" workstation) — installed to the hard drive. - RandyKramer

Thanks for any changes you did. Please delete this after you read it. Regards StefanWolber

I didn't delete anything because I added the comments you see, please delete anything that seems deletable after you see this. (I did delete some old "formatting" cruft from the page.) - RandyKramer

I am running also the Knoppix 3.2 installed on the hard drive smile I will not delete any of these comments, let be for remembering what we have written so far or let be for what ever. StefanWolber

Page Ratings

Edit | Attach | Watch | Print version | History: r26 < r25 < r24 < r23 < r22 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r26 - 2005-12-15 - StefanWolber
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding WikiLearn? WebBottomBar">Send feedback
See TWiki's New Look