The linux command line--part one(二) Learing Shell

6.Redirection

    cat - concatenate files

      read one or more files and copy them to stdout

      cat [file...]

      we can use it join file

      eg.  movie.mpeg.001 movie.mpeg.002 ... movie.mpeg.099

      cat movie.mpeg.0* > movie.mpeg

      cat     when not given any arguments ,it reads from stdin and wait for (EOF) ctrl + d

               copies stdin to stdout

    sort - sort lines of text

    uniq - report or omit repeated lines

    grep - Print lines matching a pattern

        a powerful program used to find text patterns within files.

        grep pattern [file ....]

        ls /bin /usr/bin | sort | uniq | grep

       option '-i'  ignore case

    wc - print newline,word, and byte counts for each file

    head - output the first part of a file

       by default 10 lines print  can be adjust with '-n' option

       head -n 5 filename

       tail -n 5 filename

    tail - output the last part of a file

       tail -f filename       watch the files in real-time

    tee - read from standard input and write to standard output and files

 Standard Input,Output, and Error

   stdout, stderr, stdin

Redirecting Standard Output

  use '>' redirection operator followed by the name of the file   rewrite the file

  > output.txt           empty or create a new file

  '>>'  append redirected output

Redirecting Standard Error

  ls -l 2>error.txt

Redirect stdout and stderr to one file

  ls -l /bin/usr >output.txt 2>&1

first stderr then stdout

  2>&1 >output.txt

more streamlined method

  ls -l /bin/usr &> output.txt

  ls -l /bin/usr &>> output.txt

Disposing of unwanted output

  ls -l /bin/usr 2> /dev/null

  because /dev/null is a read only file .you can't write.

Redirecting standard input

  cat

Pipelines

 use "|" the std output of one command can be piped into the std input of anther:

   command1 | command2

Filters

  ls /bin /usr/bin | sort | less

 uniq - Report Or Omit Repeated Lines

  see the list of duplicates instead use '-d'

  ls /bin /usr/bin | sort | uniq -d | less

 wc - Print line, word, and byte counts

   wc (word count)

   wc filename

7.Seeing the world as the shell sees it

  echo - Display a line of text

 Expansion

   echo this is a test

   echo *

 Pathname Expansion

  ls

  echo D*

  echo *s

  echo [[:upper:]]*

  echo /usr/*/share

 Tilde Expansion

   echo ~

 Arithmetic Expansion

  echo $((2+2))

  $((expresssion))

  + - * / % **(Exponentiation)

  echo $(($((5**2)) * 3))       75

  echo $(((5**2) *3))            75

 Brace Expansion

   echo Front-{A,B,C}-Back

   echo number_{1..5}

   echo {01..15}

   echo {001..15}

   echo {Z..A}

   echo a{A{1,2},B{3,4}}b

 Parameter Expansion

   echo $USER

   printenv | less

 Command Substitution

   echo $(ls)

   ls -l $(which cp)

   file $(ls -d /usr/bin/* | grep zip)

   ls -l `which cp`

 Quoting

   echo this is a       test

   echo the total is $100.00

  Double Quotes

   ls -l "two words.txt"

   echo "$USER $((2+2)) $(cal)"

   echo "this is a     test"

   echo $(cal)

   echo "$(cal)"

  Single Quotes

  

 Escaping Characters

8 - Advanced Keyboard Tricks

    clear - Clear the screen

    history - Display the contents of the history list

 Command Line Editing

   Cursor Movement

  

 Modifying Text

   

  I try these , all the alt+sth don't  work.

Cutting And Pasting(Killing and Yanking) Text

 

 Completion

   Tab

  Using history

    Searching History

     history | less

     history | grep /usr/bin

     !88

   History Expansion

    

  script   used to record an entire shell session and store it in a file.

     script [file]

    if no file is specified ,the file typescript is used.

9 - Permissions

   id - Display user identity

       the Ubuntu user belong to a lot more groups.

       /etc/shadow holds information about the user's password.

       /etc/passwd define the user (login) name,uid,gid,the account's real name,home directory,and login shell.

   chmod - Change a file's mode

    octal notation:

      chmod 600 foo.txt

      r-4 w-2 x-1

   symbolic notation:

      chmod ug=rwx filename      u-user  g- group owner  o-others  a-all  

     

     Symbolic notation does offer the advantage of allowing you to set a single attribute without disturbing any of the others.

     option "--recursive" it acts on both files and directories ,we rarely want files and directories to have the same permissions.

   umask - Set the default file permissions

   su - Run a shell as another user

      Run a shell with substitute user and group ids

      su [-[l]] [user]

   sudo - Execute a command as another user

      one difference between su and sudo is that sudo does not start a new shell, nor does it load another user's envir

   chown - Change a file's owner

     chown [owner][:[group]] file...

     chown Argument Examples

      

   chgrp - Change a file's group ownership

      In older version of Unix, the chown command only changed file ownership,not group ownership.

   passwd - change a user's password

 Owners,Group Members, And Everybody Else

 Reading,Writing,And Executing

   file types

  

 

 Permission Attribute Examples

 

  Changing Identities

      some commands:adduser,useradd,groupadd

10.Processes

    multitasking

    available commands let us examine what programs are doing.

   ps - Report a snapshot of current processes

   top - Display tasks

   jobs - List active jobs

   bg - Place a job in the background

   fg - Place a job in the foreground

   kill - Send a signal to process

   killall - Kill processes by name

   shutdown - Shutdown or reboot the system

 How A Process Works

   init scripts start all the system services. Many of these services are implement

 View Processes

   ps  

   by default,  ps doesn't show us very much.

   TTY is short for "Teletype"

   STAT is short for "state".

   process states

 

   ps aux

   displays the processes belonging to every user

    BSD style ps Column Headers


 Viewing Processes Dynamically With top

   top

   displays a continuously updating (by default,every 3 seconds)

   top information fields

  

  

 Controlling Processes

 Interrupting A Process

 Put A Process In The Background

 Returning A Process To The Foreground

 Signals

 Sending Signals To Processes With Kill

  kill [-signal] PID

  Common signals

 


  kill -1 13323

  kill -INT 12132

  kill -SIGINT

 Sending Signals To Multiple Processes with killall

   killall [-u user] [-signal] name...

 Shutting Down The System

   sudo reboot

   sudo shutdown -h now

   sudo shutdown -r now

 More Process Related Commands

   pstree

   vmstat

   xload

   tload

 


  

  

 

 

   

 



  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值