Logo Background RSS
  • Remove / Delete a Directory Linux Command
    By sps on June 24th, 2009 | 18 Comments18 Comments Comments

    Delete / Remove a Directory Linux Command

    Q. I am new to Linux and command line. How do I delete or remove a directory?

    A. Use rmdir command. This command remove the DIRECTORY(ies), if they are empty. For example, type the following command to remove /tmp/docs directory:

    $ rmdir /tmp/docs
    If directory is not empty you will get an error:
    $ rmdir letters
    Output:

    rmdir: letters: Directory not empty

    You can change directory to find out files:
    $ cd letters
    $ ls

    Linux remove entire directory

    To remove all directories and subdirectories use rm command. For example remove letters and all subdirectories and files inside this directory, type the following command:
    $ rm -rf letters/

  • How do I remove all empty directories?
    By sps on June 24th, 2009 | 11 Comments11 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.

  • ls: command options
    By admin on March 25th, 2009 | 9 Comments9 Comments Comments

    ls: command options

    Option Action

    -a                  list hidden files

    -d                  list the name of the current directory

    -F                  show directories with a trailing ‘/’
    executable files with a trailing ‘*’

    -g                  show group ownership of file in long listing

    -i                  print the inode number of each file

    -l                  long listing giving details about files
    and directories

    -R                  list all subdirectories encountered

    -t                  sort by time modified instead of name

  • Install mod_bandwidth
    By admin on March 23rd, 2009 | 3 Comments3 Comments Comments

    What is Mod_Bandwidth

    “Mod_bandwidth” (mod bandwidth) is a module for the Apache webserver that enable the setting of server-wide or per connection bandwidth limits, based on the directory, size of files and remote IP/domain.

    For Apache 1.3x. ONLY! This how-to is not compatible with old versions of apache, including but not limited to 1.3beta

    How to install mod_bandwidth

    1. Login to your server via SSH as root.

    2. Type: mkdir /root/mod_bw

    3. Type: cd /root/mod_bw

    4. Type: wget ftp://ftp.cohprog.com/pub/apache/module/1.3.0/mod_bandwidth.c

    5. Type: /usr/local/apache/bin/apxs -c /root/mod_bw/mod_bandwidth.c -o /usr/local/apache/libexec/mod_bandwidth.so

    6. Type: mkdir /usr/local/apache/bw_limit

    7. Type: mkdir /usr/local/apache/bw_limit/link

    8. Type: mkdir /usr/local/apache/bw_limit/master

    9. Type: pico -w /etc/httpd/conf/httpd.conf

    10. Locate the following Line: LoadModule rewrite_module libexec/mod_rewrite.so

    11. Before the above line add this:
    LoadModule bandwidth_module libexec/mod_bandwidth.so

    12. Now locate this line: AddModule mod_env.c

    13. Before the above line add this:
    AddModule mod_bandwidth.c

    14. Now locate this line: # Document types.

    15. Before the above line add this:
    BandWidthDataDir “/usr/local/apache/bw_limit”
    BandWidthModule On

    16. To enable mod_bandwidth on a virtual host locate the virtual host entry for the specified domain/acount you wish to limit. Just before the line add the following:
    BandWidthModule On
    BandWidth all 512

    The 512 can be replaced with whatever rate you wish to limit the acount too.

    17. Save the file and exit.
    CTRL-X then Y then enter.

    18. Type: service httpd restart

    19. Type: cd /usr/sbin

    20. Type: wget ftp://ftp.cohprog.com/pub/apache/module/cleanlink.pl

    What is cleanlink?
    Cleanlink is a deamon that is used to clean links created by mod_bandwidth when they aren’t removed properly by the server. (When a httpd process doesn’t terminate the usual way.)

    21. Type: chmod 755 cleanlink.pl

    22. Type: pico -w cleanlink.pl

    23. Change $LINKDIR to the following:
    $LINKDIR=”/usr/local/apache/bw_limit/link”;

    24. Save the file and exit.
    CTRL-X then Y then enter.

    25. Type: perl cleanlink.pl

    26. Type: pico -w /etc/rc.d/rc.local

    27. Scroll down to the very end of the file and add the following:
    # The following line Launches CleanLink for Mod_Bandwidth
    perl /usr/sbin/cleanlink.pl

    28. Save the file and exit.
    CTRL-X then Y then enter.

    mod_bandwidth has many options. If you wish to modify mod_bandwidth and enable more options please visit the documentation available by the programmer here: http://www.cohprog.com/v3/bandwidth/doc-en.html

  • Stop Coredump file
    By sps on March 23rd, 2009 | 4 Comments4 Comments Comments

    Many webmasters ask me how to stop core dump files in Apache.. Now today i will tell you how to stop core dump file in apache.  This is basically happens when System Crashes it makes a coredump file in the public_html Directory.

    The possible reason for the core files getting generated is when a php process is killed, apache creates core files under your account .

    On phpSuexec servers this may cause due to incorrect php.ini file placed in your account and if it is caused due to php/apache then you can get rid off those core files by editing the httpd startup file on the server end .

    Lets start

    Code:
    root@server [~]# vi /etc/init.d/httpd

    Search for ulimit lines .For eg : you can see these lines

    Code:
    ulimit -n 1024
    ulimit -n 4096
    ulimit -n 8192
    ulimit -n 16384

    You need to add ulimit -c 0 at the end .Which will look like :

    Code:
    ulimit -n 1024
    ulimit -n 4096
    ulimit -n 8192
    ulimit -n 16384
    ulimit -c 0

    root@server [~]# :wq

    Save changes and quit.
    Now kill / stop apache service and then start apache service on the server .

    Code:
    root@server [~]# service httpd stop
    root@server [~]# service httpd stop
    httpd (no pid file) not running
    root@server [~]# service httpd startssl
    root@server [~]# service httpd startssl
    httpd (pid 21154) already running

    Finished :D

    It works most of the OS.

    Self tested on CENTOS 5.2 i686 on standard

  • Link Building
    By vinod on March 14th, 2009 | 4 Comments4 Comments Comments

    In every webmaster forum and blog out there, the community always goes nuts over finding ways to get universities and government sites to link to you. This post is dedicated to helping those people save their money and allow them to get an unlimited amount of .edu and .gov links for free, all through the power of google!

    The ’site:’ feature in Google allows only results with that domain name or domain extension to show up. You can “hack” this feature to allow Google to find the most relevant university and government websites related to your sites.

    Examples:
    Google query: site:.gov blog [or site:.edu blog]
    Results in: Google finds any .gov website that is running a blog or has a /blog/ directory. You can then visit these blogs and post comments (if you can find wordpress blogs like this one), and get hundreds of free .gov backlinks.
    [Alternative queries: 'blog' 'blogs' 'wordpress' 'comment' 'guestbook' '2007' '2006']

    Google query: site:.edu *your niche* + blog
    For example: site:.edu internet marketing blog
    The top result is a .edu blog that links to a non edu blog, but that blog is related and is PR3 and has edu backlinks. That is also a great relevant place to comment, even if it is not directly a .edu. On the other hand, the third result was a PR3 highly related .edu internet marketing blog with zero comments. That is easy .edu backlinks!

    You can easily replicate these queries to fit your needs, and it is highly scalable. You can find .edu, .gov, and if you are lucky, .mil blogs. If you are not as picky, you can just search specifically for the blogs without the .edu or .gov extension, and you can find some high pageranked blogs on the first pages of results. Play around with it, enjoy it, it’s free!