grep,壓縮歸檔,shell提示符

先留個坑,配合着正則表達式一起在linux中的運用會好很多吧。

格式是    grep [options] pattern [file]

--------------

GREP(1)                                                                GREP(1)

NAME
       grep, egrep, fgrep - print lines matching a pattern

SYNOPSIS
       grep [OPTIONS] PATTERN [FILE...]
       grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

DESCRIPTION
       grep  searches the named input FILEs (or standard input if no files are named, or if a single
       hyphen-minus (-) is given as file name) for lines containing a match to  the  given  PATTERN.
       By default, grep prints the matching lines.

       In  addition,  two  variant  programs  egrep  and  fgrep are available.  egrep is the same as
       grep -E.  fgrep is the same as grep -F.  Direct  invocation  as  either  egrep  or  fgrep  is
       deprecated,  but  is  provided  to  allow  historical  applications  that rely on them to run

       unmodified.

------------


[oh@localhost manlist]$ grep one grep.md
	      Obtain patterns  from  FILE,  one	 per  line.   The  empty  file
	      output,  grep  ensures  that the standard input is positioned to
	      Suppress error messages about nonexistent or  unreadable	files.
	      there is more than one file to search.
	      default  when there is only one file (or only standard input) to
	      TYPE  is	binary,	 and  grep  normally outputs either a one-line
       A regular expression may be  followed  by  one  of  several  repetition
       +      The preceding item will be matched one or more times.
       is  used	 if none of these environment variables are set, if the locale
	      operand  of  grep to be an option, even if it appears to be one.
       require	exponential  time  and space, and may cause grep to run out of
       Back-references are very slow, and may require exponential time.
[oh@localhost manlist]$ grep -n one grep.md
59:	      Obtain patterns  from  FILE,  one	 per  line.   The  empty  file
116:	      output,  grep  ensures  that the standard input is positioned to
136:	      Suppress error messages about nonexistent or  unreadable	files.
152:	      there is more than one file to search.
156:	      default  when there is only one file (or only standard input) to
232:	      TYPE  is	binary,	 and  grep  normally outputs either a one-line
377:       A regular expression may be  followed  by  one  of  several  repetition
381:       +      The preceding item will be matched one or more times.
435:       is  used	 if none of these environment variables are set, if the locale
589:	      operand  of  grep to be an option, even if it appears to be one.
622:       require	exponential  time  and space, and may cause grep to run out of
625:       Back-references are very slow, and may require exponential time.
[oh@localhost manlist]$ 

grep有好多個衍生版本:  egrep支持POSIX擴展正則表達式     fgrep大型文件中搜索字符串。

 

壓縮工具。bzip2,gzip,zip

歸檔工具:tar



--------------------

shell提示符

[oh@localhost manlist]$ echo $PS1
[\u@\h \W]\$
[oh@localhost manlist]$ echo $PS2
>
[oh@localhost manlist]$ 

倆個環境變量:

   PS1:控制默認命令提示符的格式。

   PS2:控制後續命令行提示符的格式。

也就是說對環境變量的賦值,來控制bash shell的命令提示符顯示格式,那麼,怎麼賦值?

  bash shell提示符字符:

[u@]PS1="\u"
oh
ohPS1="[\u]"
[oh]PS1=\u
u

特別注意的是,賦值時沒加“”,被理解爲命令了

uPS1=[ \u \t ]
bash: u: command not found
u



參見:

https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html

So when executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:

  • \a : an ASCII bell character (07)
  • \d : the date in “Weekday Month Date” format (e.g., “Tue May 26”)
  • \D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required
  • \e : an ASCII escape character (033)
  • \h : the hostname up to the first ‘.’
  • \H : the hostname
  • \j : the number of jobs currently managed by the shell
  • \l : the basename of the shell’s terminal device name
  • \n : newline
  • \r : carriage return
  • \s : the name of the shell, the basename of $0 (the portion following the final slash)
  • \t : the current time in 24-hour HH:MM:SS format
  • \T : the current time in 12-hour HH:MM:SS format
  • \@ : the current time in 12-hour am/pm format
  • \A : the current time in 24-hour HH:MM format
  • \u : the username of the current user
  • \v : the version of bash (e.g., 2.00)
  • \V : the release of bash, version + patch level (e.g., 2.00.0)
  • \w : the current working directory, with $HOME abbreviated with a tilde
  • \W : the basename of the current working directory, with $HOME abbreviated with a tilde
  • \! : the history number of this command
  • \# : the command number of this command
  • \$ : if the effective UID is 0, a #, otherwise a $
  • \nnn : the character corresponding to the octal number nnn
  • \\ : a backslash
  • \[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
  • \] : end a sequence of non-printing characters

Let us try to set the prompt so that it can display today’d date and hostname:
PS1="\d \h $ "


來個中文的。

https://billie66.github.io/TLCL/book/chap14.html

表14-1: Shell 提示符中用到的轉義字符
序列顯示值
\a以 ASCII 格式編碼的鈴聲 . 當遇到這個轉義序列時,計算機會發出嗡嗡的響聲。
\d以日,月,天格式來表示當前日期。例如,“Mon May 26.”
\h本地機的主機名,但不帶末尾的域名。
\H完整的主機名。
\j運行在當前 shell 會話中的工作數。
\l當前終端設備名。
\n一個換行符。
\r一個回車符。
\sshell 程序名。
\t以24小時制,hours:minutes:seconds 的格式表示當前時間.
\T以12小時製表示當前時間。
\@以12小時制,AM/PM 格式來表示當前時間。
\A以24小時制,hours:minutes 格式表示當前時間。
\u當前用戶名。
\vshell 程序的版本號。
\VVersion and release numbers of the shell.
\w當前工作目錄名。
\W當前工作目錄名的最後部分。
\!當前命令的歷史號。
\#當前 shell 會話中的命令數。
\$這會顯示一個"$"字符,除非你擁有超級用戶權限。在那種情況下, 它會顯示一個"#"字符。
\[標誌着一系列一個或多個非打印字符的開始。這被用來嵌入非打印 的控制字符,這些字符以某種方式來操作終端仿真器,比方說移動光標或者是更改文本顏色。
\]標誌着非打印字符序列結束。

oh
ohPS1="[\u]"
[oh]PS1=\u
uPS1=[ \u \t ]
bash: u: command not found
uPS1="[\u \t]:"
[oh 17:03:59]:

當然這樣只是當前登錄shell有效。
































發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章