基础 Bash命令 | Bash与Python脚本编程(英文)

Bash In Linux

Command Line Shell

A. Files and Directories
  1. new directory: mkdir {mynewdir}

  2. go to directory: cd {mynewdir}

  3. show present working directory: pwd

  4. delete empty directory: rmdir {mynewdir}

  5. current directory: .

  6. parent directory: ..

  7. create file: touch {new.txt}

  8. copy file: cp {../my.txt} {.}, cp {my.txt} {my2.txt}

  9. move/rename file: mv {my.txt} {empty.txt}

  10. delete file: rm *, rm *.txt, rm {empty.txt}

  11. change permissions: chmod {+x} {test.py}

  12. change owner: chown {user} {filename} chown {user1} {test.py}

  13. change group: chgrp {group} {filename} chgrp {user1} {test.py}

  14. list entires in directory: ls, ls {mynewdir}

    Add arguments (can join multiple, e.g. -la ):

    • list all (inc. hidden) files -a
    • list directory entries only -d
    • human-readable format -h
    • print index number -i
    • long listing format -l
    • sort in reverse order -r
    • print size -s
    • sort by size -S
    • sort by modification time -t
    • list entries by lines -x
    • sort alphabetically by extension -X

    {permission} {no. of inodes} {owner} {group} {size} {date of mod} {filename}

    -rwxrwxrwx 1 user1 user1 107 Jul 29 22:01 test.py

B. File Operations
  1. show content in std output: cat {new.txt}

  2. write file: nano/vim etc. {filename} nano {new.txt}

  3. count no. of characters, words, lines: wc {new.txt}

  4. text type: file {test.py}

    test.py: ASCII text, with no line terminators

  5. print first 10 lines: head {new.txt}

  6. print last 10 lines: tail {new.txt}

  7. translate: tr {' '} {'\n'}

  8. sort: sort (alphabetically), sort {-nr} (numerically reversed)

  9. terminal paging program (scroll through contents): less (quit with q)

  10. Extract parts each line (by separator after -d) and print the field (of no. after -f): cut -d{' '}, -f{1-} {new.txt} (field counts from 1) (1-: from 1 onwards)

C. Additional Commands
  1. show manual of a command: man {echo} (quit with q)
  2. print to std output: echo {Hello}, echo {"Hello"}
  3. globally search for regular expression and print out: grep {true}
  4. current date: date
  5. list of logged in users: who
  6. computer running duration: uptime
  7. unused memory: free
D. Redirect I/O Streams
  1. redirect std output to new file or overwrite: >

    • {./hello.py} > {hello.txt}, {python hello.py} > {hello.txt}
  2. redirect std output to new file or append: >>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值