分类 标签 存档 订阅 搜索

The Linux Common Command Line

114 浏览0 评论

The Linux Common Command Line

Reference

  1. TLCL
  2. linux命令大全

Command

shell

  • date : show time
  • cal : show calander
  • df : show amount of free space on disk
  • free : show free memory
  • ctrl-alt-f2 : virtual terminal no gui
  • ctrl-alt-f1 : gui

file system

  • pwd : print current working directory
  • cd : change directory
  • ls : list current directory
  • cd - : changes to previrous directory
  • cd ~ : chanage to home

operation system

  • file : determine file type
  • less : browser file content
  • more : browser file content
  • head : browser file content
  • tail : browser file content
  • ln : create a link to file

Using Commands

  • type : indicate how to command name is interpreted
  • which : display which executable program will be excute
  • man : display a command's manual page
  • apropos : display a list of appropriate commands
  • info : display a command's info entry
  • whatis : display a very breif description of command
  • alias : creae an alias for a command

I/O Redirection

  • cat : concatenate files and print on the standard output
  • sort : sort lines of text files
  • uniq : report or omit repeated lines
  • grep : print lines matching a pattern
  • wc : print newline, word, and byte counts for each file
  • head : output the first part of files
  • tail : output the last part of files
  • tee : read from standard input and write to standard ...
  • '>' : redirect the output
  • '>>' : append content
  • '2>' : redirect the error output usage : > ls-output.txt 2>&1 or &>
  • '|' : pipe
  • 将文件流操作称作标准输入、输出和错误,shell 内部分别将其称为文件描述符0、1和2
  • echo : display a line of text
  • clear : clear the screen
  • history : display the contents of the history list

Bash Editor

Key Action
Ctrl-a Move cursor to the beginning of the line.
Ctrl-e Move cursor to the end of the line.
Ctrl-f Move cursor forward one character;same as the right arrow key.
Ctrl-b Move cursor backward one character;same as the left arrow key.
Alt-f Move cursor forward one word.
Alt-b Move cursor backward one word.
Ctrl-l Clear the screen and move the cursor to the top left corner. The clear command does the same thing.

History Command

Sequence Action
!! Repeat the last command. It is probably easier to press up arrow and enter.
!number Repeat history list item number.
!string Repeat last history list item starting with string.
!?string Repeat last history list item containing string.

Permission

  • id – Display user identity
  • chmod – Change a file’s mode
  • umask – Set the default file permissions
  • su – Run a shell as another user
  • sudo – Execute a command as another user
  • chown – Change a file’s owner
  • chgrp – Change a file’s group ownership
  • passwd – Change a user’s password

Process

  • 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 a process
  • killall – Kill processes by name
  • shutdown – Shutdown or reboot the system

Shell Environment

  • printenv – Print part or all of the environment
  • set – Set shell options
  • export – Export environment to subsequently executed programs
  • alias – Create an alias for a command

File Location

  • locate – Find files by name
  • find – Search for files in a directory hierarchy
  • touch – Change file times

Archival Backup

  • gzip – Compress or expand files
  • bzip2 – A block sorting file compressor
  • tar – Tape archiving utility
  • zip – Package and compress files
  • rsync – Remote file and directory synchronization

Storage Devices

  • mount – Mount a file system
  • umount – Unmount a file system
  • fsck – Check and repair a file system
  • fdisk – Partition table manipulator
  • mkfs – Create a file system
  • fdformat – Format a floppy disk
  • dd – Write block oriented data directly to a device
  • genisoimage (mkisofs) – Create an ISO 9660 image file
  • wodim (cdrecord) – Write data to optical storage media
  • md5sum – Calculate an MD5 checksum

Networking

  • ping - Send an ICMP ECHO_REQUEST to network hosts
  • traceroute - Print the route packets trace to a network host
  • netstat - Print network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
  • netstat - 打印网络连接,路由表,接口统计数据,伪装连接,和多路广播成员
  • ftp - Internet file transfer program
  • wget - Non-interactive network downloader
  • ssh - OpenSSH SSH client (remote login program)

Build

  • make

Format Output

  • nl – Number lines
  • fold – Wrap each line to a specified length
  • fmt – A simple text formatter
  • pr – Prepare text for printing
  • printf – Format and print data
  • groff – A document formatting system

Sed

  • http://linux.51yip.com/search/sed

  • 用法: sed [选项]... {脚本(如果没有其他脚本)} [输入文件]...

  • 测试 文件:awk.txt

    • 例a,这个例子,把test文件中的root替换成jasonhaven,只不过只替换一次及终止在这一行的操作,转到下一行

       sed 's/root/jasonhaven/' awk.txt
      
    • 例b,这个例子,用tankzhang把文件test中的root全部替换掉,请注意g这个字母,global的缩写

      sed 's/root/tankzhang/g' awk.txt |grep zhang
      
    • 例c,加了-n p后表示只打印那些发生替换的行(部分替换),上面的例子,我并没有加上grep

      # sed -n 's/root/tankzhang/p' awk.txt
      
    • 例e,在第二行,到第八行之间,替换以zhang开头的行,用ying来替换,并显示替换的行

      cat awk.txt |sed -ne '2,8s/^zhang/ying/gp'
      

Awk

  • http://linux.51yip.com/search/awk

  • 用法:awk [POSIX 或 GNU 风格选项] -f 脚本文件 [--] 文件 ...

  • 用法:awk [POSIX 或 GNU 风格选项][--] '程序' 文件 ...

  • 测试 文件 : awk.txt

    • awk -F: '{mat=match($1,/^[a-zA-Z]+$/);print mat,RSTART,RLENGTH}' test
      
    • awk '{print NR;print FNR;print $0;}' test 
      
    • shuf test
      

我想要的东西太多,想买的东西太贵,喜欢的人太优秀!

评论  
留下你的脚步
推荐阅读