Metacharacter: Meaning of UNIX

Recognizing metacharacters

~  Home directory
`  Command substitution(old style)
# Command
$ Variable expression
& Background job
* String wildcard
(  Start of subshell
)  End of subshell
\  Escape next character
|  Pipe
[  Start of wildcard set
]  End of wildcard set
{ Start of command block
} End of command block
;  Pipeline command separator
'  Quote mark (strong)
" Quote mark (weak)
< Redirect input
> Redirect output
/  Pathname address separator
?  Single-character wildcard
!  Pipeline logical  NOT
----------------------------------------
ps $$
bash --version
whoami
type clear
type exit
echo  $SHELL
echo $BASH_VERSION
pwd
ls
-------------------
Dealing wildcard
Wildcard   Matches
?                Any single character                 ls  doc.?     ls *.c   ls *.[a-c]
*                Any string of character
[set]           Any character in set
[!set]         Any character not in set
---------------------------------------------------------
help echo                help | more
man    ps       man -f ps
-------------------------------------------
2. Managing files
-------------------------------------------
basename $SHELL
dirname  $SHELL
mkdir rmdir    mv    cp    ls ~    ls -i
ln sample.txt sample.hardlink      ln  -s  sample.txt  sample.softlink
--------------------------------------------------
2.1 Examining properties
  cat -n hello.sh
  stat hello.sh
  wc  hello.sh
  file  hello.sh
  touch  -t  12011200.00 hello.sh
  touch -d "2018-04-04 14:24" hello.sh

2.2 Comparing files
 cat -n abc.txt
 cmp  abc.txt acd.txt
comm  abc.txt acd.txt

diff abc.txt acd.txt
md5sum  abc.txt        to create a checksum number for that file
cksum abc.txt

2.3 Finding files
find ~ -type  f -name hello*
find  -L  ~  -type  f  -name *word*
find  foldername  -type f -name hello*
touch -t 18040430 temp

2.4 compressing files
du -k ballad.txt
gzip  ballad.txt        to create a compressed ballad.txt.gz
gunzip  ballad.txt.gz

bzip2     ballad.txt
bunzip2 ballad.txt.bz2

zip      ballzd.zip  ballad.txt
unzip  ballad.zip

2.5 Making backups
ls | cpio -o > ../archive.cpio
rm *; ls
cpio -i < ../archive.cpio

tar   -cf  ../archive.tar *
rm  *; ls
tar  -xf  ../archive.tar

tar  -czf ../archive.tar.gz *
tar  -xzf ../archive.tar.gz

3 Handing text
cat; >>; more;less;head; tail; grep; sort;tee; paste \t;cut; tr; sed ; nano ; vi;
4 Editing commands
5 Customizing environment
sudo;su;exit;groupadd;groupdel;chmod;chon;chgrp; ls --color noclobber;globstar;
6 Controlling behavior
7 Performing operations
8 Directing flow
9 Employing functions
9.1 Creating scripts

 function.sh   // #!bin/bash  // chmod +x   ./
 function first {echo 'Hello world from the first function!'}
 cube5(){echo "5*5*5=$((5*5*5))"}
 first 

source function.sh    //run the script using source to see output from the first function. Once a script has been executed using the source command any functions defined there are stored in the shell's memory for the duration of that shell session. This means they can be called by name from a command prompt at any time until the user ends the shell session.  unset -f
declare -F        //to see all defined functions in shell memory
declare -f cube5
declare -f first
cube5
5*5*5=125
 --------------
9.2  Displaying variable
 vars.sh  //#!/bin/bash
var='Unix in easy steps'
arr=(Alpha Bravo Charlie)
function show_vars{
  echo $var
  echo ${arr[@]}
  var=' Displaying variable'
}
show_vars
function show_params{
  str=$@
  echo $str
}
show_params $var

--------------------
>./vars.sh              //As usual, scripts must be made executable with chmod +x then executed by prefixing the script name with ./ at the command line.
Unix in easy steps
Alpha Bravo Charlie
Displaying variable
>
---------------
bubble.sh  //#!bin/bash
function bubble_sort{
  arr=$@
  for((i=0;i<${#arr[@]}-1;i++))
  do
     for((j=0;j<${#arr[@]}-1;j++))
     do
        if((${arr[j]}>${arr[j+1]}))
        then
            tmp=${arr[$j]}
            arr[$j]=${arr[$j+1]}
            arr[$j+1]=$tmp
        fi
     done
  done
  echo "Original Order:${nums[@]}"
  echo "Sorted Order: ${arr[@]}"
}
nums=(3 8 20 25 12 7 32 1 22)       //The $@ parameter reproduces the spaces as it creates a values list.
> ./bubble.sh

for i in ${nums[@]}
do echo $i
done | sort -n
 ----------------
9.3 Inputting values



10 Handy reference

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE