Welcome to the new Linux Foundation Forum!

Share your best command line scripts

mfillpotmfillpot Posts: 2,180

The name says it all. Please share your best command line scripts and explain their use.

Comments

  • mfillpotmfillpot Posts: 2,180
    alias IPADDRESSES="ip addr|grep 192;curl -s http://checkip.dyndns.org/ | grep -o '[[:digit:].]\+'"

    This command sets up an alias command to display your internal ip address(es) and display your external ip address using dyndns.

    You only need to supplement the 192 with the first octet of you internal network subnet.
  • melikmelik Posts: 6
    #!/bin/bash
    IP=$(curl http://www.slurpware.org)
    echo $IP
    exit 0
    

    Simple external IP checker.
  • mfillpotmfillpot Posts: 2,180
    Ubucleaner seems to be a good tool for ubuntu users, thank you for sharing it.

    Also the ip script is good, it shows that there are mutliple ways in Linux to accomplish a single task.
  • weibullguyweibullguy Posts: 5
    PackManUtil for managing package installation on a Cross Linux from Scratch system.
  • adrianadrian Posts: 6
    #! /bin/bash
    
    exe=`basename $1 .c`
    gcc $1 -o $exe
    

    Will compile source.c and the output file will be source.
    I use it along with a bash alias.
  • Script to upload your screenshot to my screenshot gallery

    http://kporter.homelinux.com/~kaleb/screenup.sh

    usage:
    ./screenup.sh filename.jpg
    

    script to set your wallpaper no matter what

    http://kporter.homelinux.com/~kaleb/setwall.sh

    usage:
    ./setwall.sh filename.jpg
    
  • david_edavid_e Posts: 1
    Here is mine:

    http://omploader.org/vMXE0Zw/permfix.sh

    this script is used to change all the permissions on a directory tree: it is possible to set different permissions for regular files and folders. So for example I use it for my "Music" folder:

    ./permfix.sh -f 640 -d 750 $HOME/Music

    in this way I have the right permissions for the files and folders (the latter need a +x for "browse permission").

    There is also a "pretend mode" in which the scripts just prints what it would have done in "standard mode" without actually touching any file.

    Use it at your own risk. :)
  • #!/bin/bash
    #test ulimit
    me=/tmp/me
    doit ()
    {
    /bin/sh $me
    }
    echo foo ; doit
    exit 0
  • http://www.tuxopia.net/Script_to_Download_lyrics_from_command_line

    My Script to Download Lyrics in Command Line as Plain Text.
  • filenames="file1 file2 file3 file4 file5 file6 file7"


    target="everything" # target filename for full ZIP archive + .zip
    searchdb="search-database" # target filename for search db ZIP archive

    newestfile="$(ls -t *xml | head -1)"

    if [ $newestfile -nt $target.zip ] ; then
    # time to rebuild the archive
    zip $target *xml
    fi
  • gomergomer Posts: 158
    Here are a couple I use at work a lot.

    This one will identify the manufacturer of a NIC card based on the most current published list of OUIs. It takes the MAC address as the argument and is forgiving of the format (e.g. ifconfig, windows ipconfig, or cisco style)

    #!/bin/bash

    OUI=$(echo ${1//[:.-]/} | tr "[a-f]" "[A-F]" | egrep -o "^[0-9A-F]{6}")
    lynx -dump standards.ieee.org/regauth/oui/oui.txt | grep $OUI


    Here's one I use to mount the file system inside my Virtual Box .vdi disk image when I need to grab a file, but do not need to otherwise fireup the virtual machine:

    #!/bin/bash

    if [ -f ~/.VirtualBox/VDI/$1 ]
    then
    MOUNT=`sudo mount -o loop,umask=0000,offset=0x$(hd -n 1000000 ~/.VirtualBox/VDI/$1 | grep "eb 52 90 4e 54 46 53" | cut -c 1-8) ~/.VirtualBox/VDI/$1 /mnt 2>&1`
    if [ "$?" -ne "0" ]
    then
    echo -e "Mount Failed!!!!\n"
    OUT=`echo $MOUNT | grep "indicates unclean shutdown" 2>&1`
    if [ "$?" -eq "0" ]
    then
    echo "NTFS was not cleanly unmounted"
    fi
    sudo losetup -d /dev/loop0
    exit 0
    fi
    else
    echo "$1 - files not found"
    fi
Sign In or Register to comment.