# Linux Command Line 学习笔记1

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

• The File System Tree

• Current Working Directory
pwd

• Listing The Contents Of A Directory
ls

通常当我要查看哪些文件占用了大量空间时会使用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

remember: less is more!

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

• linux文件系统

• 链接

• 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.

• 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

• 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》 原版书籍下载地址