A wave of practical bash shell finishing _linux shell

Source: Internet
Author: User
Tags aliases bz2 curl rar sprintf uncompress strong password egrep

As a command line seeker, you may find yourself repeating the same commands over and over again. If you always use SSH to access the same computer, if you always connect a chain of commands, if you always run a program with the same parameters, you may want to save your life for a few seconds in this constant repetition.

The solution is to use one alias (alias). As you may know, aliases use a way to let your shell remember a particular command and give it a new name. In any case, the alias has some limitations, it's just a shortcut to the shell command, and it can't pass or control its parameters. So as a supplement, Bash also allows you to create your own functions, which may be longer and more complex, and it allows any number of arguments.

Of course, when you have food, such as some kind of soup, you have to share it for everyone. I have a list here that lists some of the most useful bash aliases and functions. Note that "most useful" is just a saying, whether the alias is useful depends on whether you need to use it in the shell every day.

Before you start your alias experience trip, here's a handy tip: If your alias is the same as the original command name, you can access the original command with the following tips (LCTT: You can access it directly from the full path of the original command). )

  \command 

For example, if there is an alias LS that replaces the LS command. If you want to use the original LS command instead of an alias, call it:

  \ls 

Increase productivity

These aliases are really simple and really short, but most of them are saving a few seconds for your life and may eventually save a few years for your lifetime.

  Alias ls= "LS--color=auto"

Simple but very important. Make the LS command come with color output.

  Alias ll= "LS--color-al"

Lists all the files in the directory in a colorful list.

  Alias grep= ' grep--color=auto '

Similarly, the output is only colored in grep.

  MCD () {mkdir-p "$"; CD "$";} 

One of my favorites. Create a directory and enter the directory: MCD [directory name].

  CLS () {CD "$"; ls;}

Like the previous function, enter a directory and list its contents: cls[directory name.

  Backup () {CP ' $ ' {,. bak};}

Simply create a backup of the file: backup [file] will be created in the same directory [file].bak.

  Md5check () {md5sum "$" | grep "$";}

Because I hate it when you compare a file's MD5 checksum by hand, this function calculates it and compares it: md5check[file [checksum].

  Alias makescript= "FC-RNL | Head-1 > " 

It's easy to use your last command to create a script: makescript [script name. Sh]

  Alias genpasswd= "Strings/dev/urandom | Grep-o ' [[: Alnum:]] ' | Head-n 30 | Tr-d ' \ n '; Echo 

Just a moment to produce a strong password.

  Alias c= "Clear"

Is it easier to clear your terminal screen?

  Alias histg= "History | grep

Quick Search Your command input history: HISTG [keywords]

  Alias.. = ' CD ... '

Do I need to enter a CD back to the upper directory?

  Alias ... = ' CD ... /..'

Naturally, go to the two-tier directory.

 Extract () { 
    if [F $]; then case 
     $ in 
      *.tar.bz2)  tar xjf $ 
      ; *.tar.gz)  tar xzf $   ; 
      *.BZ2)    bunzip2 $   ; 
      *.rar)    Unrar e $   ;; 
      *.gz)    gunzip $   ; 
      *.tar)    Tar xf $   ; 
      *.TBZ2)   tar xjf $   ; 
      *.tgz)    tar xzf $   ; 
      *.zip)    unzip $    ; 
      *. Z)     uncompress $ 
      ; *.7z)    7z x $    ;; 
      *)   echo "' cannot be extracted via extract ()";; 
       Esac 
     Else 
       echo "' is not a valid file" 
     fi 
  }

It's long, but it's also the most useful. Extract any document type: extract: [Compress file]
System Information

Want to know all the information about your system as soon as possible?

  Alias cmount= "Mount | Column-t "

Formats output mount information by column.

  Alias tree= "Ls-r | grep ": $" | Sed-e ' s/:$//'-e ' s/[^-][^\/]*\//--/g '-e ' s/^/  /'-E ' s/-/|/' 

Recursively displays the directory structure in a tree structure.

  SBS () {du-b--max-depth 1 | sort-nr | perl-pe ' s{([0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10? ($1/2**10, "K"): ($, "")}e ';} 

The installation file is sorted by the size of the disk storage, displaying a list of files in the current directory.

  Alias intercept= "sudo strace-ff-e trace=write-e write=1,2-p" 

Take over standard output and standard errors for a process. Note that you need to install the strace.

  Alias meminfo= ' Free-m-l-t '

See how much memory you have left.

  Alias PS? = "PS aux | grep

can easily find the pid:ps of a process? [Name].

  Alias Volume= "Amixer Get Master | Sed ' 1,4 d ' | cut-d [F 2 | cut-d]-F 1 "

Displays the current volume settings.

Internet

For all commands used on the Internet and local networks, there are also some magical aliases for them.

  Alias websiteget= "wget--random-wait-r-p-e robots=off-u Mozilla"

Download the entire Web site: websiteget [URL].

  Alias listen= "Lsof-p-i-n" 

Shows which application is connected to the network.

  Alias port= ' NETSTAT-TULANP '

Displays the active port.

  Gmail () {curl-u "$"--silent "Https://mail.google.com/mail/feed/atom" | sed-e ' s/<\/fullcount.*/\n/' | sed-e ' s/.* fullcount>//'}

Probably show the number of unread emails in your Google email: gmail [username]

  Alias ipinfo= "Curl ifconfig.me && Curl Ifconfig.me/host"

Get your public network IP address and host name.

  GetLocation () {lynx-dump http://www.ip-adress.com/ip_tracer/? Qry=$1|grep address|egrep ' city|state|country ' |awk ' {print $3,$4,$5,$6,$7,$8} ' |sed ' S\IP address flag \ ' |sed ' s\My\\ ';} 

Returns the location of your current IP address.
maybe useless .

So, what if some aliases aren't all of use value? They may still be interesting.

  Kernelgraph () {lsmod | perl-e ' print ' digraph \ lsmod\ ' {'; <>;while (<>) {@_=split/\s+/; print "\" $_[0]\ "-> \" $_\ "\ n" for Split/,/,$_[3]}print "}" | Dot-tpng | Display-;}

Draw the kernel module dependency graph. You need to be able to view pictures.

  Alias busy= "Cat/dev/urandom | hexdump-c | grep ' CA fe ' 

You seem to be always so busy and mysterious in the eyes of non-technical people.

As a reward, here are the plain text versions of all the aliases and functions I mentioned, and can be copied and pasted into your. BASHRC. (If you have a line of copy here, haha, you find you waste a few seconds of life ~)

#Productivity alias ls= "ls--color=auto" alias ll= "ls--color-al" Alias grep= ' grep--color=auto ' mcd () {mkdir- P "$";
  CD "$";}
  CLS () {CD "$"; ls;}
  Backup () {CP ' $ ' {,. bak};}
  Md5check () {md5sum "$" | grep "$";} Alias makescript= "FC-RNL | Head-1 > "Alias genpasswd=" Strings/dev/urandom | Grep-o ' [[: Alnum:]] ' | Head-n 30 | Tr-d ' \ n '; echo "Alias c=" clear "Alias histg=" History | grep "Alias".
  = ' CD ... ' Alias ... = ' CD ...
  /..'
      Extract () {if [F $]; then case $ in *.tar.bz2) tar XJF $;
      *.tar.gz) tar Xzf $;
      *.BZ2) BUNZIP2 $;
      *.rar) Unrar e $;;
      *.gz) Gunzip $;
      *.tar) Tar XF $;
      *.TBZ2) tar XJF $;
      *.TGZ) tar Xzf $;
      *.zip) unzip $; *.
      Z) Uncompress $;
      *.7z) 7z x $;;
       *) echo "' cannot be extracted via extract ()";;
  Esac else echo "' is not a valid file" fi#System info alias cmount= "Mount | Column-t "Alias tree=" Ls-r | grep ": $" | Sed-e ' s/:$//' e ' s/[^-][^\/]*\//--/g '-e ' s/^//'-e ' s/-/|/' ' SBS () {du-b--max-depth 1 | sort-nr | perl-pe ' s{( [0-9]+)}{sprintf "%.1f%s", $1>=2**30? ($1/2**30, "G"): $1>=2**20? ($1/2**20, "M"): $1>=2**10?
  ($1/2**10, "K"): ($, "")}e ';} Alias intercept= "sudo strace-ff-e trace=write-e write=1,2-p" Alias meminfo= ' Free-m-l-t ' alias ps?= "ps aux | grep "Alias Volume=" Amixer Get Master | Sed ' 1,4 d ' | cut-d [F 2 | cut-d]-F 1 "#Network alias websiteget=" wget--random-wait-r-p-e robots=off-u Mozilla Ali As listen= "Lsof-p-i-n" Alias port= ' Netstat-tulanp ' Gmail () {curl-u "$--silent" https://mail.google.com/mail/f Eed/atom "| Sed-e ' s/<\/fullcount.*/\n/' | Sed-e ' s/.*fullcount>//'} alias ipinfo= "Curl ifconfig.me && Curl Ifconfig.me/host" getlocation () {lynx-d UMP http://www.ip-adress.com/ip_tracer/? Qry=$1|grep Address|egreP ' city|state|country ' |awk ' {print $3,$4,$5,$6,$7,$8} ' |sed ' S\IP address flag \ ' |sed ' s\my\\ ';} #Funny kernelgraph () {lsmod | perl-e ' print ' digraph \ lsmod\ ' {'; <>;while (<>) {@_=split/\s+/; print "\" $_[0]\ "-> \" $_\ "\ n" for Split/,/,$_[3]}print "}" | Dot-tpng |
  Display-;} Alias busy= "Cat/dev/urandom | hexdump-c |
 grep \ "Ca fe\"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.