10 - Other Frequently asked questions with answers

===============================================================================
10 - Other Frequently asked questions with answers.
===============================================================================

Q: How can I play an .au file ?
A: The file suffix .au means it's an audio file, so you can either do
   the same as for mp3's: mpg123 file.au
   or you can (since .au files are raw audio): cat file.au > /dev/dsp
   or: cat file.au > /dev/audio

Q: What exactly is bash ?
A: If you have read this tutorial you would know ... it's a shell type.

Q: I wanna make some sub-directory's to /usr/local/ but I'm to lazy to write
   almost the same line over and over again, is there any easier way ?
A: Yes there is: mkdir /usr/local/{dir1,dir2,dir3}

Q: I have a dir with files like this: file.1 file.2 file.3 etc.
   is there any way I can list say, file.3, file.4, file.6, file.9 only
   without using grep ?
A: Yes there is: ls file*[3469]*

Q: I want to remove some files with wildcards included in the command
   (rm -rf .??*), is there any way I can see what the command will remove
   before I actually do the command ?
A: Yes there is: echo rm -rf .??*

Q: How can I remove file names that are/have special characters like a file
   named:  -!?* !!?
A: Do this: rm ./-!?* !!?
   The ./ makes sure it will look in the current directory, and the
   (back slashes) will make sure that the special characters special meaning
   is over looked, so they are treated just like any other character.

Q: I accidently deleted something on my system, is there any way
   of getting it back ?
A: Yes there is, read this file /usr/doc/HOWTO/mini/Ext2fs-Undeletion
   (or /usr/doc/HOWTO/mini/Ext2fs-Undeletion.gz)
   This is also good knowledge if someone *hacks* your system
   and think they are safe just because they deleted the logs.
   Or you can download a program called 'recover' from www.freshmeat.net

Q: How do I compile my kernel ?
A: Read this file:  /usr/doc/HOWTO/Kernel-HOWTO

Q: Can I make a variable read-only so noone can change it ?
A: Yes you can: readonly variable_name
   As say that I have a variable: $myvar
   Then I would do: readonly myvar
   And to display all the read-only variables just do: readonly

Q: How can I display all the set variables ?
A: With the command: set
   To get the eviorment use this command: env
   And to display the system variables, type a $ and press TAB.

Q: Something is wrong with a script, but I dont know what, how can I find out ?
A: by doing this: /bin/sh -x <scriptname>
   + means that the command was successful.
   - means that the command was unsuccessful.

Q: I'm using hexedit and simlar commands alot, but I'm getting to lazy to
   find out where all the binarys live, isn't there any faster way of
   opening a binary or script that's in my $PATH then to locate, find or
   something like that and then go from there ?
A: Well, I dont know how much faster it is, but you can always
   do this: hexedit `which <file>`

Q: How can I list only the directorys in a directory without the files ?
A: Well, some distros has an alias "lsd", and it does: ls -d */

Q: How can I transfer a file if the computer doesn't have any FTP ?
A: If you wanna actually copy a file to a place that dont have ftp
   or for some other reason you can't use ftp, there is 2 commands that can
   do this: scp (secure copy - requiers ssh)
   And: rcp (remote copy - requiers rlogin)
   They work like this:
   scp local.file user@host.domain.com:/remote/directory/
   rcp local.file user@host.domain.com:/remote/directory/

Q: Is there any way I can view my processes so I can see the free stack,
   father processes siblings and children etc. ?
A: Yes there is, press: Ctrl + Scroll-Lock

Q: Is there any way I can view the memory buffers etc. ?
A: Yes there is, press: Shift + Scroll-Lock

Q: Is there any way to get some info from the stack ?
A: Yes there is press: AltGr + Scroll-Lock

Q: My volume is really low when I play stuff, how can I change it ?
A: Use the program `aumix` it should be on most systems by default,
   and it's pretty self explanatory.

Q: I think it's a pain pressing upp arrow until I reach the command I want
   to use, that is to long to type again, is there any faster way ?
A: Yes, press Ctrl+R and type something that matches a previously used
   command, and just press enter to execute it or Ctrl+C to cancel.

Q: Is there any console based mpeg movie players ?
A: Not that I know of, but if there is, I'd like to know myself.

Q: How can I take a screenshot without having to install Gimp or something
   like that ?
A: Well, the easyest way of taking a screen shot in X is to do the
   following command: import -window root foo.jpg
   That will dump a screen shot as foo.jpg, in your current directory.

Q: How can I import variables from one script to another, like a config file ?
A: You can read all variables from a file by doing ". <file name>", say
   that you have a file called myvars and you want to you those variables
   in a script, then you add the line:  . myvars
   in the beginning of the script, after the #!/bin/bash line.
   The . is actually a command, that reads and executes commands in a file,
   which here works to imported the variables since they are executed
   from within the script.

Q: I'm using `port sentry` as a firewall controll software, now my routing
   table is over full, how can I take away all that's routed to 'localhost'
   in one command or string ?
A: Well like this: for ips in `route | grep local | cut -c 1-14`; do route del -host $ips gw 127.0.0.1 2>/dev/null ; done
   That should do the trick.

Q: If I'm in a directory full or rpm files and I wanna find out which rpm that
   contain say the file vga.h, how would I do that ?
A: Well you can do this:
   for foo in `ls -1 *.rpm`; do rpm -qlp $foo | grep vga.h 1>/dev/null 2>&1 && echo $foo; done

Q: Is there any place I can find out where all the ^ (Ctrl) characters mean ?
A: Yes, look in the ascii table below, it works like this:
   M is the 13'th character in the alphabet, and in the ascii table
   013 (dec) has the value CR which means Carriage Return.
   this means that ^M (Ctrl+M) is the same as pressing the return button.
   And ^A which is 001 (dec) is Start of Header, in other words take the
   cursor to the beginning of the current line.

Q: How do I write stuff in hex code ?
A: Well, like this:

-------------------------------------------------------------------------------
                                ASCII codes
-------------------------------------------------------------------------------

    ASCII Table (7-bit)

       Decimal   Octal   Hex    Binary     Value
       -------   -----   ---    ------     -----
         000      000    000   00000000      NUL    (Null char.)
         001      001    001   00000001      SOH    (Start of Header)
         002      002    002   00000010      STX    (Start of Text)
         003      003    003   00000011      ETX    (End of Text)
         004      004    004   00000100      EOT    (End of Transmission)
         005      005    005   00000101      ENQ    (Enquiry)
         006      006    006   00000110      ACK    (Acknowledgment)
         007      007    007   00000111      BEL    (Bell)
         008      010    008   00001000       BS    (Backspace)
         009      011    009   00001001       HT    (Horizontal Tab)
         010      012    00A   00001010       LF    (Line Feed)
         011      013    00B   00001011       VT    (Vertical Tab)
         012      014    00C   00001100       FF    (Form Feed)
         013      015    00D   00001101       CR    (Carriage Return)
         014      016    00E   00001110       SO    (Serial In)
         015      017    00F   00001111       SI    (Serial Out)
         016      020    010   00010000      DLE    (Data Link Escape)
         017      021    011   00010001      DC1 (XON) (Device Control 1)
         018      022    012   00010010      DC2       (Device Control 2)
         019      023    013   00010011      DC3 (XOFF)(Device Control 3)
         020      024    014   00010100      DC4       (Device Control 4)
         021      025    015   00010101      NAK    (Negative Acknowledgement)
         022      026    016   00010110      SYN    (Synchronous Idle)
         023      027    017   00010111      ETB    (End of Trans. Block)
         024      030    018   00011000      CAN    (Cancel)
         025      031    019   00011001       EM
         026      032    01A   00011010      SUB
         027      033    01B   00011011      ESC    (Escape)
         028      034    01C   00011100       FS    (File Separator)
         029      035    01D   00011101       GS
         030      036    01E   00011110       RS    (Request to Send)
         031      037    01F   00011111       US
         032      040    020   00100000       SP    (Space)
         033      041    021   00100001        !
         034      042    022   00100010        "
         035      043    023   00100011        #
         036      044    024   00100100        $
         037      045    025   00100101        %
         038      046    026   00100110        &
         039      047    027   00100111        '
         040      050    028   00101000        (
         041      051    029   00101001        )
         042      052    02A   00101010        *
         043      053    02B   00101011        +
         044      054    02C   00101100        ,
         045      055    02D   00101101        -
         046      056    02E   00101110        .
         047      057    02F   00101111        /
         048      060    030   00110000        0
         049      061    031   00110001        1
         050      062    032   00110010        2
         051      063    033   00110011        3
         052      064    034   00110100        4
         053      065    035   00110101        5
         054      066    036   00110110        6
         055      067    037   00110111        7
         056      070    038   00111000        8
         057      071    039   00111001        9
         058      072    03A   00111010        :
         059      073    03B   00111011        ;
         060      074    03C   00111100        <

         061      075    03D   00111101        =
         062      076    03E   00111110        >
         063      077    03F   00111111        ?
         064      100    040   01000000        @
         065      101    041   01000001        A
         066      102    042   01000010        B
         067      103    043   01000011        C
         068      104    044   01000100        D
         069      105    045   01000101        E
         070      106    046   01000110        F
         071      107    047   01000111        G
         072      110    048   01001000        H
         073      111    049   01001001        I
         074      112    04A   01001010        J
         075      113    04B   01001011        K
         076      114    04C   01001100        L
         077      115    04D   01001101        M
         078      116    04E   01001110        N
         079      117    04F   01001111        O
         080      120    050   01010000        P
         081      121    051   01010001        Q
         082      122    052   01010010        R
         083      123    053   01010011        S
         084      124    054   01010100        T
         085      125    055   01010101        U
         086      126    056   01010110        V
         087      127    057   01011111        W
         088      130    058   01011000        X
         089      131    059   01011001        Y
         090      132    05A   01011010        Z
         091      133    05B   01011011        [
         092      134    05C   01011100
         093      135    05D   01011101        ]
         094      136    05E   01011110        ^
         095      137    05F   01011111        _
         096      140    060   01100000        `
         097      141    061   01100001        a
         098      142    062   01100010        b
         099      143    063   01100011        c
         100      144    064   01100100        d
         101      145    065   01100101        e
         102      146    066   01100110        f
         103      147    067   01100111        g
         104      150    068   01101000        h
         105      151    069   01101001        i
         106      152    06A   01101010        j
         107      153    06B   01101011        k
         108      154    06C   01101100        l
         109      155    06D   01101101        m
         110      156    06E   01101110        n
         111      157    06F   01101111        o
         112      160    070   01110000        p
         113      161    071   01110001        q
         114      162    072   01110010        r
         115      163    073   01110011        s
         116      164    074   01110100        t
         117      165    075   01110101        u
         118      166    076   01110110        v
         119      167    077   01110111        w
         120      170    078   01111000        x
         121      171    079   01111001        y
         122      172    07A   01111010        z
         123      173    07B   01111011        {
         124      174    07C   01111100        |
         125      175    07D   01111101        }
         126      176    07E   01111110        ~
         127      177    07F   01111111      DEL

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

Say that you want to echo "Hi" with hex code, you do this:

echo -e "x048x069"

The x part is to let `echo -e` know that it's hexa decimal code.
You can even hide commands like that.

Here is a script example of hiding the `top` command in hex and execute it:

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

#!/bin/bash

hexcode='x074x06Fx070'

`echo -e $hexcode`

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

This will execute what echo echos, due to the "`"'s.
So that script will actually start the `top` command.

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

Another question I got a while back is how to make a DWORD (Double Word),
that means how to rewrite an address or IP to hex/oct/dec.

And it's not that hard, all it takes is some mathematics.
It works like this:

There are several methods, but let's start with the Decimal way
of making a DWORD.
Say you have IP: 127.0.0.1
then you do:
127 * 16777216 = 2130706432
0 * 65536      = 0
0 * 256        = 0
1 * 1          = 1
Sum:             2130706433

Or if you have the IP: 123.123.123.123
123 * 16777216 = 2063597568
123 * 65536    = 8060928
123 * 256      = 31488
123 * 1        = 123
Sum:             2071690107

Note:
      16777216 = 2^24
         65536 = 2^16
           256 = 2^8
             1 = 2^0

Next method is to convert it to HEX, OCT etc, to convert from dec to oct etc.
you can either use the ascii table a few lines up, or you can download
a program called ascii from www.freshmeat.net.
Last time I saw it it was located at:
http://freshmeat.net/projects/ascii/download/ascii-3.0.tar.gz

So assuming you have downloaded that and and wanna covert 127.0.0.1 and
123.123.123.123 to HEX DWORDs, do this:

alien:~$ ascii 127 0 0 1
ASCII 7/15 is decimal 127, hex 7f, octal 177, bits 01111111: called ^?, DEL
Official name: Delete

ASCII 5/7 is decimal 087, hex 57, octal 127, bits 01010111: prints as `W'
Official name: Majuscule W
Other names: Capital W, Uppercase W

ASCII 3/0 is decimal 048, hex 30, octal 060, bits 00110000: prints as `0'
Official name: Digit Zero

ASCII 3/0 is decimal 048, hex 30, octal 060, bits 00110000: prints as `0'
Official name: Digit Zero

ASCII 3/1 is decimal 049, hex 31, octal 061, bits 00110001: prints as `1'
Official name: Digit One

alien:~$

Take the hex numbers after the decimal of 127, 0 and 1 and you'll come
to the conclution that 127.0.0.1 in a hex DWORD is: 7F303031 

You can use OCT the same way .. with as many leading 0's as you please

0173.0173.0173.0173 or 000173.00000173.000173.000000000000000000000173,
it still means IP 123.123.123.123

And ofcorse to add on the confusion you can mix the methods.
0173.0x7b.00173.123

Now there is even more to this like that you can add any multiple of the
number 4294967296 (2^32) to the number without the IP changing ....
But let's not get into that ....

So basically typing:
http://0173.0x7b.00173.123/
in your web browser will end you up at IP 123.123.123.132 (which doesnt excist)
but the idea is the same for everything, so if you see some lame spammer
thinking that you wont know from what address he sent something ...
The just back count it and send abuse mail to his internet service provider.

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

If someone has more questions mail, them to me at: alien@ktv.koping.se
maybe I'll include them in the tutorial, but I'll do my best to answer
the questions anyway.

Leave a Reply