Page 1 of 11 123 ... LastLast
Results 1 to 10 of 107

Thread: Post your bash scripts and aliases!

  1. #1
    Join Date
    Nov 2006
    Beans
    136

    Post your bash scripts and aliases!

    I have gotten into bash scripting and am having a blast.

    I am curious of what others have created.


    Here are my scripts (some may need some personalizing tweaks):

    info.sh screenshot script (not mine; from http://ubuntukids.org/blog/?page_id=25), I modded it to display Beryl theme, font, and conky font

    conky-pack creates a conky startup script, tars it and my conky(rc) files, and deletes the newly created script.

    febe-sort sorts the files exported by FEBE (Firefox extension), placing them in separate directories.

    port-stylishrdf copies the file, stylish.rdf, to another directory as a backup method. (is in my crontab file)

    port-searchp ports the Firefox's searchplugins folder as a means of backup

    ls2 modifies sort order of 'ls' to: directories (numbers, capital, lowercase), files (numbers, capital, lowercase). ...serves as one of my aliases.

    ls2a like ls2, but also lists hidden files.

    aliases:
    ls2=$HOME/scripts/ls2

    lsa=$HOME/scripts/ls2a

    updatedb='sudo updatedb -v'

    ytdl='youtube-dl -t'

    srmn='apropos'


    Cronjobs are welcome.
    Attached Files Attached Files
    Last edited by Interestedinthepenguin; August 9th, 2008 at 01:23 AM.
    Blue Ubuntu forums: http://userstyles.org/styles/2455 | Grey Ubuntu forums: http://userstyles.org/styles/3440 | Black Ubuntu forums: http://userstyles.org/styles/3992
    Windows free since: 6/15/07

  2. #2
    Join Date
    Nov 2005
    Location
    Northern Ohio
    Beans
    89
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Post your bash scripts and aliases!

    One of my most useful scripts is a bash script that provides a neat and orderly way to mount to CIFS shares (Windows network shares). You place a simple client script in ~/bin/. along with the smb_net include script. The client script contains the user, server, share, domain, and includes (by reference) the smb_net script. The smb_net script contains all of the logic for using the client information and attaching to a CIFS network. smb_net creates a ~/mnt directory and attaches the CIFS share beneath the user account. Once you get your client scripts set up, it makes mounting to specific network shares a breeze! I use this very often.

    I attached a tar file that contains several sample client scripts and the smb_net script that is included in each of the clients scripts. Make sure to follow the instructions in the smb_net. You must make sure user account is a member of the "users" group and provide the documented users sudo entry. This needs to be done only once for everything to work properly.
    Attached Files Attached Files
    Thanks,
    Ken
    Linux is really for everyone.

  3. #3
    Join Date
    Jul 2007
    Location
    /earth/USA/WA/Spokane
    Beans
    299
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Post your bash scripts and aliases!

    I made a small bash that preloads a hack for Urban Terror then runs the game.
    Though I don't think it's really worth attaching to my post.
    Ubuntu User # 17031
    Quote Originally Posted by RAV TUX View Post
    who needs support when you use Linux.
    Quote Originally Posted by asjdfwejqrfjcvm msz34rq33 View Post
    Open-Source: The power to create completely useless, but extremely cool, programs.

  4. #4
    Join Date
    Aug 2005
    Beans
    462

    Re: Post your bash scripts and aliases!

    i got loads of stuff, most i got from the internet and maybe changed a bit.

    here's a clock

    Code:
    # clock - A bash clock that can run in your terminal window. 
    clock () 
    { 
    while true;do clear;echo "===========";date +"%r";echo "===========";sleep 1;done 
    }
    network info
    Code:
    netinfo ()
    {
    echo "--------------- Network Information ---------------"
    /sbin/ifconfig | awk /'inet addr/ {print $2}'
    echo ""
    /sbin/ifconfig | awk /'Bcast/ {print $3}'
    echo ""
    /sbin/ifconfig | awk /'inet addr/ {print $4}'
    
    # /sbin/ifconfig | awk /'HWaddr/ {print $4,$5}'
    echo "---------------------------------------------------"
    }
    define a word
    Code:
    # Define a word - USAGE: define dog
    define ()
    {
    lynx -dump "http://www.google.com/search?hl=en&q=define%3A+${1}&btnG=Google+Search" | grep -m 3 -w "*"  | sed 's/;/ -/g' | cut -d- -f1 > /tmp/templookup.txt
    			if [[ -s  /tmp/templookup.txt ]] ;then	
    				until ! read response
    					do
    					echo "${response}"
    					done < /tmp/templookup.txt
    				else
    					echo "Sorry $USER, I can't find the term \"${1} \""				
    			fi	
    \rm -f /tmp/templookup.txt
    }
    here's a find function
    Code:
    function    ff               { find . -name $@ -print; }
    here's a welcome message for when i open my terminal
    Code:
    clear
    
    echo -ne "${LIGHTGREEN}" "Hello, $USER. today is, "; date
    echo -e "${WHITE}"; cal ;  
    echo -ne "${CYAN}";
    echo -ne "${LIGHTPURPLE}Sysinfo:";uptime ;echo ""
    here are some colour definitions for the above message
    Code:
    # Define a few Colours
    BLACK='\e[0;30m'
    BLUE='\e[0;34m'
    GREEN='\e[0;32m'
    CYAN='\e[0;36m'
    RED='\e[0;31m'
    PURPLE='\e[0;35m'
    BROWN='\e[0;33m'
    LIGHTGRAY='\e[0;37m'
    DARKGRAY='\e[1;30m'
    LIGHTBLUE='\e[1;34m'
    LIGHTGREEN='\e[1;32m'
    LIGHTCYAN='\e[1;36m'
    LIGHTRED='\e[1;31m'
    LIGHTPURPLE='\e[1;35m'
    YELLOW='\e[1;33m'
    WHITE='\e[1;37m'
    NC='\e[0m'              # No Color
    some aliases
    Code:
    # screenshots
    alias screenshot='import -window root ~/Desktop/`date +%Y%m%d%H%M`.png'
    
    # System info
    alias cpuu="ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'"
    alias memu='ps -e -o rss=,args= | sort -b -k1,1n | pr -TW$COLUMNS'
    alias pg='ps aux | grep'  #requires an argument
    
    # interactive
    alias cp='cp -vi'
    alias mv='mv -vi'
    alias rm='mv --target-directory=$HOME/.Trash/'
    
    # Directory navigation aliases
    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    alias .....='cd ../../../..'
    
    # display facts of the day
    alias today='grep -h -d skip `date +%m/%d` /usr/share/calendar/*'
    
    # network
    alias net1='watch --interval=2 "sudo netstat -apn -l -A inet"'
    alias net2='watch --interval=2 "sudo netstat -anp --inet --inet6"'  
    alias net3='sudo lsof -i'
    alias net4='watch --interval=2 "sudo netstat -p -e --inet --numeric-hosts"'
    alias net5='watch --interval=2 "sudo netstat -tulpan"'
    alias net6='sudo netstat -tulpan'
    alias net7='watch --interval=2 "sudo netstat -utapen"'
    alias net8='watch --interval=2 "sudo netstat -ano -l -A inet"'
    alias netl='sudo nmap -sT -O localhost'
    alias ping='ping -c 10'
    alias currports='wine /home/iceni60/Desktop/Desktop_Folder/Network_Tools/currports/cports.exe'
    alias winwhois='wine /home/iceni60/Desktop/Desktop_Folder/Network_Tools/win32whois_0_9_13/win32whois.exe'
    alias xnews='wine /home/iceni60/Desktop/Desktop_Folder/Network_Tools/XNews/XNEWS.EXE'
    alias whois='whois -H'
    
    # listings
    alias ls='ls --color=auto'
    alias lh='ls -lah'                # human readable (sizes) long and all ;-)
    alias lls='ls -l -h -g -F --color=auto'
    alias lc='ls -aCF'
    alias lsam='ls -am'               # List files horizontally
    alias lr='ls -lR'                 # recursive
    alias lsx='ls -ax'                # sort right to left rather then in columns
    alias lss='ls -shaxSr'            # sort by size
    alias lt='ls -latr'               # sort by date
    alias lm='ls -al |more'           # pipe through 'more'
    
    # scripts
    alias calc='sh /home/iceni60/scripts/calc.sh'
    alias whatsmyip='/home/iceni60/scripts/whatsmyip.sh'
    alias unpack='/home/iceni60/scripts/unpack2dir.sh'
    
    # chmod and permissions commands
    alias mx='chmod a+x'
    alias 000='chmod 000'
    alias 644='chmod 644'
    alias 755='chmod 755'
    alias perm='stat --printf "%a %n \n "' # requires a file name e.g. perm file
    
    # weather
    alias weather='/home/iceni60/scripts/conky_scripts/weather.sh UKXX0085'
    
    # Music
    alias ncmpc='ncmpc -cm'
    i added the scripts for the weather, whatsmyip, unpack and calculator. probably no one will use them, but if i ever lose everything i can come to this thread lol

    MD5 794730399e2acdf0e5983f90a53632cf scripts.tar.gz
    Attached Files Attached Files
    Last edited by ice60; November 19th, 2007 at 06:18 PM. Reason: added the checksum 8)
    Thanks to the forums staff for your dedication and hard work
    (the admins changed my sig to that lol )

  5. #5
    Join Date
    Apr 2007
    Location
    Derby, UK
    Beans
    228

    Re: Post your bash scripts and aliases!

    I've only made one script which deleted all the images from my Music folder, but I lost it when I reinstalled.

    I'm cutting back on using aliases cuz I'm getting too dependant
    Here they are:
    Code:
    #aliases
    alias aliases='(gedit ~/.bash_aliases &)'
    
    #remote desktop
    alias school='(rdesktop [School IP] &)'
    
    #cd
    alias m='cd ~/Music'
    alias i='cd ~/Pictures'
    alias h='cd ~/Homework'
    alias ..='cd ..'
    alias ...='cd ../..'
    alias ....='cd ../../..'
    alias .....='cd ../../../..'
    
    #ls
    alias ll='ls -l'
    alias la='ls -A'
    alias l='ls -CF'
    alias ldir='ls -p | grep \/'
    
    #delete
    alias del='mv --target-directory=~/.Trash/'
    
    #apt
    alias install='sudo apt-get install'
    alias remove='sudo apt-get remove'
    alias purge='sudo apt-get remove --purge'
    alias update='sudo apt-get update && sudo apt-get upgrade'
    alias upgrade='sudo apt-get upgrade'
    alias clean='sudo apt-get autoclean && sudo apt-get autoremove'
    alias search='apt-cache search'
    alias show='apt-cache show'
    alias sources='(gksudo gedit /etc/apt/sources.list &)'
    
    #ln
    alias ln='ln -s'
    
    #df
    alias dfh='df -h'
    
    #wc
    alias count='wc -l'
    
    #tar
    alias tarz='tar -xvzf'
    alias tarb='tar -xvjf'
    
    #xorg
    alias xorg='(gksudo gedit /etc/X11/xorg.conf &)'
    
    #compiz
    alias c='(compiz --replace &)'
    
    #conky
    alias conkyreset='killall -SIGUSR1 conky'
    alias conkyrc='(gedit ~/.conkyrc ~/.conkyrc4 &)'
    alias conkyall='conky -c ~/.conkyrc && conky -c ~/.conkyrc4'
    
    #on this day
    alias today='grep -h -d skip `date +%m/%d` /usr/share/calendar/*'
    
    #folding@home
    alias fahstart='sudo /etc/init.d/foldingathome start'
    alias fahstop='sudo /etc/init.d/foldingathome stop'
    alias fahrestart='sudo /etc/init.d/foldingathome restart'
    alias fahsend='sudo /etc/init.d/foldingathome send'
    alias fahstatus='sudo /etc/init.d/foldingathome status'
    alias fah='ps -ef | grep -i fah'
    
    #fluxbox
    alias fluxmenu='gedit ~/.fluxbox/menu &'
    alias fluxkeys='gedit ~/.fluxbox/keys &'
    alias fluxstart='gedit ~/.fluxbox/startup &'
    alias fluxstyle='gedit ~/.fluxbox/styles/Modified\ Nyz &'
    Last.fm | Linux User#449102 | Ubuntu User#15213
    NEVER type a command you don't understand eg. sudo rm -rf / or something similar
    Learn about them here or here.

  6. #6
    Join Date
    Aug 2005
    Beans
    462

    Re: Post your bash scripts and aliases!

    i have got some more too, below.

    but, i was wondering if this alias could cause problems -
    Code:
    alias d='cd /home/iceni60/Desktop'
    because i remember having it in the past and i removed it for some reason, i can't remember why. also, i'd think it's quite an obvious alias to have, but no one else seems to have it??

    Code:
    # General
    alias df='df -h'
    alias h='history'
    alias d='cd /home/iceni60/Desktop'
    alias duck='du -skc * | sort -rn'
    alias open='gnome-open'
    alias chm='kchmviewer'
    alias nb='nano ~/.bashrc'
    
    # lynx web browser
    alias bbc='lynx http://news.bbc.co.uk/text_only.stm'
    alias nytimes='lynx http://nytimes.com'
    alias google='lynx http://google.co.uk'
    
    #################
    ### FUNCTIONS ###
    #################
    
    function    ff               { find . -name $@ -print; }
    
    function    rmd              { rm -fr $@; }
    
    function    osr              { shutdown -r now; }
    function    osh              { shutdown -h now; }
    
    function    mfloppy          { mount /dev/fd0 /mnt/floppy; }
    function    umfloppy         { umount /mnt/floppy; }
    
    function    mdvd             { mount -t iso9660 -o ro /dev/dvd /mnt/dvd; }
    function    umdvd            { umount /mnt/dvd; }
    
    function    mcdrom           { mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom; }
    function    umcdrom          { umount /mnt/cdrom; }
    
    function    psa              { ps aux $@; }
    function    psu              { ps  ux $@; }
    
    function    dub              { du -sclb $@; }
    function    duk              { du -sclk $@; }
    function    dum              { du -sclm $@; }
    
    function    dfk              { df -PTak $@; }
    function    dfm              { df -PTam $@; }
    function    dfh              { df -PTah $@; }
    function    dfi              { df -PTai $@; }
    and i made these for my prompt, i really like the way my prompt is 8) can anyone see any problems with them? some i got off the internet and i made the others, those are the ones that might have some mistakes

    Code:
    ############################## ##################################
    # ##### PROMPT SECTION ##### ####################################
    ############################## ##################################
    
    ##PS1="\[\]\u:\w > \[\]"
    ##PS1="\[\][\[\]\u\[\]]\[\]\w > \[\]"
    #PS1="\[\][\[\]\u\[\]]\[\]\w > \[\]"
    #PS1="\[\][\[\]\[\]\u\[\]\[\]]\[\]\w > \[\]"
    ##PS1="\[\][\[\]\u\[\]]\[\]\w > \[\]"
    #PS1="\[\]\u \[\]\$\[\] \w \[\]"
    
    ###################### the above are separate prompts which can be used instead of below. NOTE: only ONE line at a time should be uncommented. so there are 6 different prompts above!!!!!
    
    # color_name='\[\033[ color_code m\]'
    
    rgb_restore='\[\033[00m\]'
    rgb_black='\[\033[00;30m\]'
    rgb_firebrick='\[\033[00;31m\]'
    rgb_red='\[\033[01;31m\]'
    rgb_forest='\[\033[00;32m\]'
    rgb_green='\[\033[01;32m\]'
    rgb_brown='\[\033[00;33m\]'
    rgb_yellow='\[\033[01;33m\]'
    rgb_navy='\[\033[00;34m\]'
    rgb_blue='\[\033[01;34m\]'
    rgb_purple='\[\033[00;35m\]'
    rgb_magenta='\[\033[01;35m\]'
    rgb_cadet='\[\033[00;36m\]'
    rgb_cyan='\[\033[01;36m\]'
    rgb_gray='\[\033[00;37m\]'
    rgb_white='\[\033[01;37m\]'
    
    rgb_std="${rgb_white}"
    
    if [ `id -u` -eq 0 ]
    then
        rgb_usr="${rgb_red}"
    else
        rgb_usr="${rgb_green}"
    fi
    
    [ -n "$PS1" ] && PS1="${rgb_usr}`whoami`${rgb_std} \W ${rgb_usr}\\\$${rgb_restore} "
    
    unset   rgb_restore   \
            rgb_black     \
            rgb_firebrick \
            rgb_red       \
            rgb_forest    \
            rgb_green     \
            rgb_brown     \
            rgb_yellow    \
            rgb_navy      \
            rgb_blue      \
            rgb_purple    \
            rgb_magenta   \
            rgb_cadet     \
            rgb_cyan      \
            rgb_gray      \
            rgb_white     \
            rgb_std       \
            rgb_usr
    i took a picture showing the welcome message with some of the aliases
    Attached Images Attached Images
    Thanks to the forums staff for your dedication and hard work
    (the admins changed my sig to that lol )

  7. #7
    Join Date
    Jan 2007
    Location
    Houston, TX
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Post your bash scripts and aliases!

    A lot of my scripts apply to network environments, thus wouldn't be much good to people without a lot of modification.

    I will share a goodie though, for those of you who support or use AMD (AutoMounter Daemon, not Advanced Micro Devices)
    Code:
    alias up 'cd $cwd:h/\!*'  #<-- traverse up one logical directory path as opposed to an exported physical path, remounting if necessary.
    "Its easy to come up with new ideas, the hard part is letting go of what worked for you two years ago, but will soon be out of date." -Roger von Oech

  8. #8
    Join Date
    Jan 2007
    Location
    Houston, TX
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Post your bash scripts and aliases!

    [QUOTE=toupeiro;3802415]A lot of my scripts apply to network environments, thus wouldn't be much good to people without a lot of modification.

    I will share a goodie though, for those of you who support or use AMD (AutoMounter Daemon, not Advanced Micro Devices)
    [CODE]
    alias up 'cd $cwd:h/\!*' #<-- traverse up one logical directory path as opposed to an exported physical path, remounting if necessary.
    "Its easy to come up with new ideas, the hard part is letting go of what worked for you two years ago, but will soon be out of date." -Roger von Oech

  9. #9
    Join Date
    Nov 2006
    Beans
    136

    Re: Post your bash scripts and aliases!

    @ice60

    Nothing appears to be wrong with the cd-to-desktop alias.

    Quote Originally Posted by ice60 View Post
    ...i'd think it's quite an obvious alias to have, but no one else seems to have it??
    It wasn't an obvious alias to me. ...I don't change to that directory often enough.

    Nice prompt. ...but some of the code came out as odd characters.

    Here's mine:

    Code:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[36;1m\](\l)\[\033[01;32m\]\u@\h:\[\033[37;1m\]\$\[\033[01;34m\]\w/\[\033[00m\]'
    I just changed it yesterday.

    The fun part about it is that it shows which terminal I'm in.
    Attached Images Attached Images
    Last edited by Interestedinthepenguin; November 20th, 2007 at 12:55 AM.
    Blue Ubuntu forums: http://userstyles.org/styles/2455 | Grey Ubuntu forums: http://userstyles.org/styles/3440 | Black Ubuntu forums: http://userstyles.org/styles/3992
    Windows free since: 6/15/07

  10. #10
    Join Date
    Aug 2005
    Beans
    462

    Re: Post your bash scripts and aliases!

    Quote Originally Posted by Interestedinthepenguin View Post
    @ice60

    Nothing appears to be wrong with the cd-to-desktop alias.



    It wasn't an obvious alias to me. ...I don't change to that directory often enough.

    Nice prompt. ...but some of the code came out as odd characters.

    Here's mine:

    Code:
    PS1='${debian_chroot:+($debian_chroot)}\[\033[36;1m\](\l)\[\033[01;32m\]\u@\h:\[\033[37;1m\]\$\[\033[01;34m\]\w/\[\033[00m\]'
    I just changed it yesterday.

    The fun part about it is that it shows which terminal I'm in.
    i'll keep the d alias then, thanks

    i always forget most people use their home directory for a lot of their work whereas i use the desktop
    Thanks to the forums staff for your dedication and hard work
    (the admins changed my sig to that lol )

Page 1 of 11 123 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •