Tag: 96

  • $ ps axu | grep…

    $ ps axu | grep [a]pache2

    grep processes list avoiding the grep itself

  • Notepad in a browser (type this in the URL bar)

    $ data:text/html, <html contenteditable>

    It doesn’t save your notes, but it’s great for jotting something down quickly.

  • Run the built in PHP-server in current folder

    php -S 127.0.0.1:8080

     

    You must have PHP 5.4.0 or later to be able to run the built in server.
    This web server is designed for developmental purposes only, and should not be used in production.

  • Synchronise date and time of server over ssh

    $ date –set=”$(ssh user@server ‘date -u’)”

  • Find the start time of a process.

    $ ps -eo pid,lstart,cmd

    Alternatively you can also use,
    $ ls -l /proc/pid

  • Query Wikipedia over console

    dig +short txt .wp.dg.cx

  • Simple http server

    python -m SimpleHTTPServer

  • Find the top 10 largest directories

    $ find . -type d -print0 | xargs -0 du -s | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {} | sort -rn

  • Kill a broken ssh connection.

    $ ~.
    This is useful for example if you are on ssh in a server and the server goes down without letting you out.

    This is part of a larget sets of escape sequences provided by ssh. You can find them with ~? Here’s the list:

    ~. – terminate connection (and any multiplexed sessions)

    ~B – send a BREAK to the remote system

    ~C – open a command line

    ~R – request rekey

    ~V/v – decrease/increase verbosity (LogLevel)

    ~^Z – suspend ssh

    ~# – list forwarded connections

    ~& – background ssh (when waiting for connections to terminate)

    ~? – this message

    ~~ – send the escape character by typing it twice

    (Note that escapes are only recognized immediately after newline.)

    View this command to comment, vote or add to favourites
    View all commands by carlesso

    by David Winterbottom (codeinthehole.com)

  • Find the population of the world

    $ curl –silent http://www.census.gov/population/international/ | grep wclocknum | sed -r ‘s#^.*>([0-9,]+)<.*$#\1#'

  • Show directory tree

    $ find . -type d | sed -e “s/[^-][^\/]*\// |/g” -e “s/|\([^ ]\)/|-\1/”

  • Psgrepp

    $ ps aux | grep $(echo $1 | sed “s/^\(.\)/[\1]/g”)

  • 20char long alphanumeric password

    $ head -c20 /dev/urandom | xxd -ps

  • My devel setup on my laptop.

    Since, i cannot afford to have an additional H/W setup, i thought of creating my own setup on a virtual environment.  
    I tried Virtualbox for setting up my virtual env, Because I am more comfortable on it. Download the VirtualBox setup from the virtual box site. Download you favorite Linux/Windows distribution and setup a virtual machine with that. Now, comes the most trickiest part, I really don’t like running multiple windows on my desktop, and unnecessary clutter the way it looks. Moreover, going through the tab becomes slight painful, so, I decided to go headless(of course running it headless).

    You can run this command to run your virtual machine, without even bother to open your virtualbox application, and can modify your system startup to run it on every boot and shut it down whenever your sytsem is shutting  down.

    [code language=”bash”]vvboxmanage startvm "DEVELHOST" –type headless # Here Devlehost is my virtualbox name.[/code]

     

  • emacs todo mode

    This tutorial has been posted by Logan Lee on the Usenet (http://groups.google.com/group/gnu.emacs.help/browse_thread/thread/6d55768f621067c6/cec507b4c628b776?pli=1):

     (1) To enter todo major mode, M-x todo-mode.
     (2) Let's jump to the default Todo category. Press 'j' then select 'Todo'.
     (3) Let's insert a dummy task. Press 'i' then enter description then category that it belongs to. In this case, there is only one category (ie. Todo) so enter 'Todo' as its category.
     (4) Let's insert another dummy task in order to demonstrate raising or lowering priority of a task or filing a task once it's done. Do this by pressing 'i' again and following the rest of step 3.
     (5) Now, try pressing 'r' to move the task at cursor up by one line or 'l' to lower it by one line. The line position of a task represents its respective priority.
     (6) Now, try pressing 'f' at a task to file it. Filing a task means you add it to a file called '.todo-done' located at your home directory. You will see on your screen that the filed task has disappeared from view.
     (7) Lastly, let's try adding a new category. 'M-x todo-add-category'. First, you will be directed to the source of '.todo-do' file. Don't panic because of unknown syntax shown to your screen. Proceed to step 8 to learn  more about the syntax of .todo-do file.
     (8) The format of .todo-do file:
    
    
     ;; This specifies that "Todo" and "New Category That You Have Added" are
     ;;+categories of todo-mode.
     -*- mode: todo; todo-categories: ("Todo","New Category That You Have Added"); -*-
     */* --------------------------------------------------------------------------- 
     ;; Lists tasks under Todo
     */* --- Todo
     */* 2007-01-02 19:12 Dummy Task2        ;; These are dummy tasks from steps 3,4.
     */* 2007-01-02 19 11 Dummy Task1        ;;+Task2 is higher priority than Task1.
     --- End
     ;; Lists tasks under New Category That You Have Added
     */* --- New Category That You Have Added
     ;; As you can see there are no tasks belonging to "New Category That You Have Added" ;)
     --- End
     (9) There are other commands and associated abbreviations which can be found in Todo item at menu bar.
  • Setting up networking in Debian

    Networking in Debian GNU/Linux

    Configure interface in /etc/network/interfaces
    [code language=”text”]
    iface eth0 inet static
    address <ip address>
    netmask <netmask>
    [/code]

  • Defunct Processes

    What is a defunct process ?

    A defunct (or zombie) process is one whose exit status has yet to be reaped by its parent. The exit status is reaped via the wait(2), waitid(2), or waitpid(2) system call. In the normal course of system operation, zombies may occur, but are typically short-lived. This may happen if a parent exits without having reaped the exit status of some or all of its children. In that case, those children are reparented to PID 1. See init(1M), which periodically reaps such processes.

    An irresponsible parent process may not exit for a very long time and thus leave zombies on the system. Since the operating system destroys nearly all components of a process before it becomes defunct, such defunct processes do not normally impact system operation. However, they do consume a small amount of system memory.

    preap will attempt to prevent the administrator from unwisely reaping a child process which might soon be reaped by the parent, if:

    • The process is a child of init (1M).
    • The parent process is stopped and might wait on the child when it is again allowed to run.
    • The process has been defunct for less than one minute.

    preap should be applied sparingly and only in situations in which the administrator or developer has confirmed that defunct processes will not be reaped by the parent process. Otherwise, applying preap may damage the parent process in unpredictable ways.

    Killing defunct (zombie) processes on Solaris – preap and orphan processes with init(1M)

    A defunct (or zombie) process is one whose exit status has yet to be reaped by its parent. So when a process shows as “defunct” in ps, you need to reap it. Here’s how:

    preap(1) – force a defunct process to be reaped by its parent

    Syntax: /usr/bin/preap PID

    So, to get rid of all zombies on our system, all we have to do is script this to real all process marked as defunct:

    /usr/bin/preap $(ps -ef | grep defunct | awk ‘{ print $2 }’ | xargs)

    So, what’s an orphan process then? If the parent of a defunct process happens to exit, it becomes an orphan, and is asigned PID 1 as a parent – see init(1M).

    Read more on zombies, defunct processes, orphans, preap and init here.

  • Installation Report

    Installation Report
    Date: 18 May 2008

    Installation of NVIDIA Graphics Card
    Get into pure console mode (runlevel 3)

    * Reboot into Recovery Mode or switch down to runlevel 3 or the equivalent
    * apt-get update
    * apt-get install binutils

    Install Kernel Source

    * apt-get install linux-source-2.6.12 – replace 2.6.12 with your kernel version (‘uname -a’ or ‘uname -r’)
    * cd /usr/src
    * tar -jxvf linux-source-2.6.12
    * ln -s linux-source-2.6.12 linux

    Install Kernel Headers

    * apt-get install linux-headers-2.6.12-1 linux-headers-2.6.12-1-386

    Install nVidia Drivers

    * sh NVIDIA-Linux-x86-1.0-8178-pkg1.run

    Up-grading the kernel.
    This will support the network card and help in configuring the wifi.