Linux Command Line 学习笔记1

Linux Command Line 学习笔记1

说明;写Linux Command Line 学习笔记系列文章本意只是记录自己学习 《Linux Command Line 》 这本书的过程中看到的一些自己没有留意到的地方,因此绝大多数内容只是记录了相关知识点而没有实际扩展内容,纯粹是为了自己后期回顾时有迹可循。另外,因为直接看的是原版书,所以很多地方中英混杂。更详细地学习建议去阅读原书即可。

关于为什么应该学习linux或者说ubuntn,因为ubuntn的中文名字叫做“有盼头”,学了它,你才真正有可能成为计算机的主人,才可能自由地使用你的电脑。

所谓自由,解释如下:

Freedom is the power to decide what your computer does, and the only way to have this freedom is to know what your computer is doing. Freedom is a computer that is without secrets, one where everything can be known if you care enough to find out.

关于为什么要学习命令行操作而非使用图形界面,解释如下:

graphical user interfaces make easy tasks easy, while command line interfaces make difficult tasks possible
图形用户界面让简单的任务更容易完成,而命令行界面使完成复杂的任务成为可能。

What Is The Shell

一个程序,它接受从键盘输入的命令,然后把命令传递给操作系统去执行。

一个可以让我们访问shell的东西,也叫做终端

  • The File System Tree

  • Current Working Directory
    pwd

  • Listing The Contents Of A Directory
    ls

    -a 列出所有文件
    -d 查看目录信息
    -F 添加指示符
    -h 人类可读
    -r 相反顺序显示
    -l 详细信息
    -t 按照修改时间排序
    -S 按照文件大小排序

    通常当我要查看哪些文件占用了大量空间时会使用ls -alhS |less;当我要看看最近修改过哪些文件时会使用ls -alht |less

    关于详细格式,需要注意第二行显示的文件硬连接数目,显示的时间如果太久远会有年份信息,如果很近就只有月份信息了。而这个时间日期是上次修改的时间,不是文件创建时间。

  • Changing The Current Working Directory

    • Absolute Pathnames
      绝对路径开始于根目录,紧跟着目录树的一个个分支,一直到达所期望的目录或文件。
    • Relative Pathnames
      相对路径开始于工作目录。符号“.” 指的是工作目录,“..” 指的是工作目录的父目录。
  • Shortcuts

    • cd 进入home
    • cd -先前目录
    • cd ~foo 进入foo的home

Exploring The System

  • uname -a

  • 内核 cat /proc/version

  • linux版本 lsb_release -a

  • 系统位数 file /bin/ls

  • the amount of free memory

    free

  • current amount of free space on your disk drives

    df

  • 查看文件类型

    file

    Linux没有文件后缀的概念,后缀往往只是让用户易于理解

    Linux的宗旨是一切皆文件

  • 查看文本内容

    less

    img

    remember: less is more!

    一个小小的复制粘贴技巧,鼠标左键双击文件名会自动复制,在需要的地方单击鼠标中间就可以直接黏贴刚才复制过的文件名了。

  • linux文件系统

    img

  • 链接

    • Symbolic Links
      • the same way as a Windows shortcut though of course, they predate the Windows feature by many years
      • when we create a symbolic link, we are creating a text description of where the target file is relative to the symbolic link.
    • hard links

      • every file has a single hard link that gives the file its name
      • When we create a hard link, we create an additional directory entry for a file

        • a link cannot reference a file that is not on the same disk partition as the link itself
        • may not reference a directory
        • -rw-r--r-- 4 me me 1650 2008-01-10 16:33 fun

        a “4” which is the number of hard links that now exist for the file

Manipulating Files And Directories

  • 通配符

    * Matches any characters

    ? Matches any single character

    [characters] Matches any character that is a member of the set characters

    [!characters] Matches any character that is not a member of the set characters

    [[:class:]] Matches any character that is a member of the specified class

    [:alnum:] Matches any alphanumeric character

    [:alpha:] Matches any alphabetic character

    [:digit:] Matches any numeral

    [:lower:] Matches any lowercase letter

    [:upper:] Matches any uppercase letter

    [abc]* Any file beginning with either an “a”, a“b”, or a“c”

    BACKUP.[0-9][0-9][0-9] Any file beginning with “BACKUP.”followed by exactly three numerals

    [[:upper:]]* Any file beginning with an uppercase letter

    [![:digit:]]* Any file not beginning with a numeral

    *[[:lower:]123] Any file ending with a lowercase letter or the numerals “1”, “2”, or “3”

  • cp – Copy files and directories

    -a 全部拷贝包括权限此参数的效果和同时指定"-dpR"参数相同
    -d:当复制符号连接时,把目标文件或目录也建立为符号连接,并指向与源文件或目录连接的原始文件或目录
    -f:强行复制文件或目录,不论目标文件或目录是否已存在
    -i:覆盖既有文件之前先询问用户
    -l:对源文件建立硬连接,而非复制文件
    -p:保留源文件或目录的属性
    -R/r:递归处理,将指定目录下的所有文件与子目录一并处理
    -s:对源文件建立符号连接,而非复制文件
    -u:使用这项参数后只会在源文件的更改时间较目标文件更新时或是名称相互对应的目标文件并不存在时,才复制文件
    -S:在备份文件时,用指定的后缀“SUFFIX”代替文件的默认后缀
    -b:覆盖已存在的文件目标前将目标文件备份
    -v:详细显示命令执行的操作
  • mv – Move/rename files and directories

  • mkdir – Create directories

  • rm – Remove files and directories

    • 务必小心 Be Careful With rm
    • Be particularly careful with wildcards. Consider this classic example. Let’s say you want to delete just the HTML files in a directory. To do this, you type: rm *.html
    • which is correct, but if you accidentally place a space between the “” and the“.html” like so: `rm .html`
    • the rm command will delete all the files in the directory and then complain that there is no file called “.html”.
    • Here is a useful tip. Whenever you use wildcards with rm (besides carefully checking your typing!), test the wildcard first with ls. This will let you see the files that will be deleted. Then press the up arrow key to recall the command and replace the ls with rm.
  • ln – Create hard and symbolic links

《The Linux Command Line》 原版书籍下载地址


本文作者:思考问题的熊

版权声明:本博客所有文章除特别声明外,均采用 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议 (CC BY-NC-ND 4.0) 进行许可。

# linux
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×