Jump to content

Scripts, Tips And Tricks


tomuchrice

Recommended Posts

Hello everybody

I would like to start a scripts, trips and tricks tread.

If you use some nice little helper to help you do some tasks please paste them here. Please also state what kind of linux you run, because not every script might work on every box.

I would like to start the thread with pasting some of my alias from .bashrc

I am using debian/sid

Here my sysinfo:

Host/Kernel/OS "dellbox" running Linux 2.6.39-1.slh.1-aptosid-amd64 x86_64 [ aptosid 2011-01 Γῆρας - kde-full - (201102052200) ]

CPU Info 4x Intel Core i5 M 520 @ 3072 KB cache flags( sse3 ht nx lm vmx ) clocked at [ 1199.000 MHz ]

Videocard ATI M92 [Mobility Radeon HD 4500/5100 Series] [ ]

Network cards Broadcom NetLink BCM57780 Gigabit PCIe

Processes 238 | Uptime 1day | Memory 1982.7/3829.6MB | HDD WDC WD5000BEVT-7 Size 500GB (82%used) | Client Shell | Infobash v3.36

here my aliases:

# Easy extract

extract () {

if [ -f $1 ] ; then

case $1 in

*.tar.bz2) tar xvjf $1 ;;

*.tar.gz) tar xvzf $1 ;;

*.bz2) bunzip2 $1 ;;

*.rar) rar x $1 ;;

*.gz) gunzip $1 ;;

*.tar) tar xvf $1 ;;

*.tbz2) tar xvjf $1 ;;

*.tgz) tar xvzf $1 ;;

*.zip) unzip $1 ;;

*.Z) uncompress $1 ;;

*.7z) 7z x $1 ;;

*) echo "don't know how to extract '$1'..." ;;

esac

else

echo "'$1' is not a valid file!"

fi

}

# Makes directory then moves into it

function mkcdr {

mkdir -p -v $1

cd $1

}

# Creates an archive from given directory

mktar() { tar cvf "${1%%/}.tar" "${1%%/}/"; }

mktgz() { tar cvzf "${1%%/}.tar.gz" "${1%%/}/"; }

mktbz() { tar cvjf "${1%%/}.tar.bz2" "${1%%/}/"; }

### ALIASES

## Keeping things organized

alias ls='ls -hF --color' # add colors for filetype recognition

alias lx='ls -lXB' # sort by extension

alias lk='ls -lSr' # sort by size

alias la='ls -Al' # show hidden files

alias lr='ls -lR' # recursice ls

alias lt='ls -ltr' # sort by date

alias lm='ls -al |more' # pipe through 'more'

alias tree='tree -Cs' # nice alternative to 'ls'

alias ll='ls -l' # long listing

alias l='ls -hF --color' # quick listing

alias lsize='ls --sort=size -lhr' # list by size

alias lsd='ls -l | grep "^d"' #list only directories

## Moving around & all that jazz

alias back='cd $OLDPWD'

alias ..="cd .."

alias ...="cd ../.."

alias ....="cd ../../.."

alias .....="cd ../../../.."

alias ......="cd ../../../../.."

## Misc

alias edit='nano'

alias rm='mv -t ~/.local/share/Trash/files'

alias cp='cp -i'

alias mv='mv -i'

alias mkdir='mkdir -p -v'

alias df='df -h'

alias du='du -h -c'

alias reload='source ~/.bashrc'

alias biggest='BLOCKSIZE=1048576; du -x | sort -nr | head -10'

alias xpclean='find \( -iname '*ini' -o -iname '*db' \) -exec rm -f {} \;'

## App-specific

alias nano='nano -W -m'

alias wget='wget -c'

## Sudo fixes

alias install='sudo apt-get install'

alias remove='sudo apt-get remove'

## empty trash

alias trash="rm -fr ~/.Trash"

#du in init3

alias xdu='/etc/init.d/kdm stop; apt-get dist-upgrade'

Link to comment
Share on other sites

alias back='cd $OLDPWD'

$ cd -

will do the same thing.

some nice bash tricks:

ctrl-r will let you search your history. just type what you're looking for and if there's any match, it will show up. hit ctrl-r again to go back deeper in history.

putting a ! in front of a command will re-execute this command. as it could be dangerous (think rm for example), you can do:

$ !command:p

to print it first.

still in bash, ctrl-a will bring you at the beginning of the line, ctrl-e, at the end. ctrl-w will delete the word at the left of the cursor. ctrl-u will delete everything at the left of the cursor, ctrl-k will delete everything at the right of the cursor.

Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.



×
×
  • Create New...