Category: Operating System

  • How to Set up an FTP Server in Ubuntu Linux

    Login to your Linux shell menu as root


    [root@locahost]# apt-get install vsftpd
    [root@locahost]# vim /etc/vsftpd.conf

    At VIM, 1st comment out anonymous_enable by adding a # sign at the beginning of the line
    # anonymous_enable=YES
    2nd remove comment at local enable by removing the # sign
    local_enable=YES


    [root@locahost]# /etc/init.d/vsftpd restart

  • Adding color to your tail

    Tail is a very useful tool for monitoring error stream. Sometime the output from tail can have too much information and its black and white monotone output can be hard to follow with the eyes.

    The basic: Linux terminal has the capability to colorize text.
    for example:
    $ echo -e “Sample text nicely highlighted”
    will produce a simple text saying, well:
    Sample text nicely highlighted

    But with some terminal color tagging such as:
    $ echo -e “Sample \e[36mtext\e[0m nicely highlighted”
    The \e above is identical with \033. I would suggest use \033 because it is safer to be used with a programming language such as PHP. PHP will not recognize \e but it will recognize \033, you’ll see below.
    $ echo -e “Sample \033[36mtext\033[0m nicely highlighted”
    Sample text nicely highlighted

    Some basic coloring table can be seen here: http://www.bashguru.com/2010/01/shell-colors-colorizing-shell-scripts.html

    Color Foreground Background
    Black 30 40
    Red 31 41
    Green 32 42
    Yellow 33 43
    Blue 34 44
    Magenta 35 45
    Cyan 36 46
    White 37 47

    With the help of perl, which most likely comes with all linux distros, here is a way to colorize your tail output. Lets’ assume that every time you log something you will have a date-time prefixing your log. For example:

    [22-Dec-2011 20:28:45] E_DATASOMETHING ……
    Too much information …….
    Too much information …….
    [22-Dec-2011 20:28:46] E_FATAL Something
    Too much information …….
    Too much information …….
    Too much information …….

    Lets create a script that can colorize the date portion.
    Create an executable linux bash file:


    $ touch logwatch.sh
    $ chmod 755 logwatch.sh
    $ vim logwatch.sh

    The copy and paste the following to your empty logwatch.sh

    #!/bin/bash
    vNow=$(date +"%d-%b-%Y")
    tail -f ~username/errorlogfile.txt|perl -pe "s/$vNow/\e[1;30;32m$&\e[0m/g"

    Voilà!

    [22-Dec-2011 20:28:45] E_DATASOMETHING ……
    Too much information …….
    Too much information …….
    [22-Dec-2011 20:28:46] E_FATAL Something
    Too much information …….
    Too much information …….
    Too much information …….

    If you need something more complex, say you want to highlight several words on the file you can use a scripting power of PHP, I’m rusty with my pearl.
    Anyhow, save the script below as “colorize.php”, and you can have the words: blah, na, wa, and — highlighted on the fly!

    $ tail -f test.txt|php colorize.php blah na wa --


  • How to see open ports in Linux

    How to see open ports in Linux

    nmap -sS -O 127.0.0.1

  • Find Files in Linux by Name

    To find files in linux with a certain name portion or pattern we can issue a locate locate command.
    If locate is unable to find a matching file, then you might need to update your file index database.

    # locate journal-2011-07
    # updatedb

    In the example above we are trying to find a file that has journal-2011-07 in its name which can be journal-2011-07-01, journal-2011-07-02, my-journal-2011-07-09, etc.

    You can also use the find command. The find command does not use file indexing algorithm which might be slower than locate.
    The example below will look for all files with xml extension inside /home/ronald.
    The find command by default is recursive or it will look into subfolders.

    find /home/ronald/ -name *.xml

  • Map Network Drive using DOS command

    Create a batch file named “mapdrive.bat”
    Write the following text into its content


    REM Map network Drive
    net use j: \\server1\john_music
    net use p: \\server2\pdfs
    pause

    Explaination:
    Line 1 is to create a comment
    Line 2 (similar with line 3) is to map a network folder \\server1\john_music to drive J:>
    Line 4 is to pause the DOS window so it won’t close automatically

  • Finding a String Inside Multiple Files in Linux

    This is how you can find a text/string Proudly inside folder /var/www. The -H parameter is to show the filename and -R is to make grep look recursively.
    grep -H -R "Proudly" /var/www

  • Fix Microsoft Mouse in Linux Ubuntu

    nano /etc/X11/xorg.conf

    Section "InputDevice"
    Identifier "Configured Mouse"
    Driver "mouse"
    Option "CorePointer"
    # Option "Device" "/dev/input/mice"
    Option "Protocol" "ExplorerPS/2"
    Option "Emulate3Buttons" "false"
    Option "ZAxisMapping" "4 5"
    Option "ButtonMapping" "1 2 3 6 7"
    EndSection

  • Colorize Linux Shell Menu

    Do you ever feel like you’re going blind because the prompt text color and the result text color are the same?
    We here is how to colorize your shell menu

    Open your favorite text editor vim or nano, and add this at the end

    $ nano ~/.bashrc
    PS1='\[\e[1;32m\][\u@\h \t \w]\$\[\e[0m\] '

    0;30 black
    0;31 light red
    0;32 light green
    0;33 light yellow
    0;34 light blue
    0;35 light purple
    0;36 light cyan

  • Edit default Gnome-Terminal

    Every time I open a shell terminal in my Ubuntu, I always think that the window size is too small. I always ended up resizing the shell window manually using the mouse. I you’re having this problem here is how to fix it permanently.
    gnome-terminal --geometry=80x25 -x /home/janne/.adom/adom