You've experienced the shiny, point-and-click surface of your Linux computer-now dive below and explore its depths with the power of the command line. The Linux Command Line takes you from your very first terminal keystrokes to writing full programs in Bash, the most popular Linux shell. Along the way you'll learn the timeless skills handed down by generations of gray-bearded, mouse-shunning gurus: file navigation, environment configuration, command chaining, pattern matching with regular expressions, and more. In addition to that practical knowledge, author William Shotts reveals the philosophy behind these tools and the rich heritage that your desktop Linux machine has inherited from Unix supercomputers of yore. As you make your way through the book's short, easily-digestible chapters, you'll learn how to: * Create and delete files, directories, and symlinks * Administer your system, including networking, package installation, and process management * Use standard input and output, redirection, and pipelines * Edit files with Vi, the world's most popular text editor * Write shell scripts to automate common or boring tasks * Slice and dice text files with cut, paste, grep, patch, and sed Once you overcome your initial "shell shock," you'll find that the command line is a natural and expressive way to communicate with your computer. Just don't be surprised if your mouse starts to gather dust.
Part 1 – Introduction.........................................................................1
1 – Introduction................................................................................................2
Why Use The Command Line?.......................................................................................2
What This Book Is About.................................................................................................3
Who Should Read This Book..........................................................................................3
What's In This Book.........................................................................................................4
How To Read This Book..................................................................................................5
Prerequisites...............................................................................................................5
Why I Don't Call It “GNU/Linux”.............................................................................5
Acknowledgments...........................................................................................................6
Your Feedback Is Needed!..............................................................................................7
Further Reading...............................................................................................................7
Colophon.........................................................................................................................7
Part 2 – Learning The Shell..............................................................9
2 – What Is The Shell?...................................................................................10
Terminal Emulators........................................................................................................10
Your First Keystrokes....................................................................................................10
Command History.....................................................................................................11
Cursor Movement.....................................................................................................11
A Few Words About Mice And Focus...................................................................11
Try Some Simple Commands........................................................................................12
Ending A Terminal Session............................................................................................13
The Console Behind The Curtain........................................................................13
Further Reading.............................................................................................................13
3 – Navigation.................................................................................................14
Understanding The File System Tree............................................................................14
The Current Working Directory......................................................................................14
Listing The Contents Of A Directory..............................................................................15
Changing The Current Working Directory.....................................................................16
Absolute Pathnames................................................................................................16
Relative Pathnames.................................................................................................16
Some Helpful Shortcuts............................................................................................18
Important Facts About Filenames........................................................................18
4 – Exploring The System.............................................................................20
More Fun With ls...........................................................................................................20
Options And Arguments............................................................................................21
A Longer Look At Long Format.................................................................................22
Determining A File's Type With file................................................................................23
Viewing File Contents With less....................................................................................24
What Is “Text”?.....................................................................................................24
Less Is More........................................................................................................26
A Guided Tour................................................................................................................26
Symbolic Links...............................................................................................................29
Hard Links.....................................................................................................................30
Further Reading.............................................................................................................30
5 – Manipulating Files And Directories........................................................31
Wildcards.......................................................................................................................31
Character Ranges................................................................................................33
Wildcards Work In The GUI Too..........................................................................33
mkdir – Create Directories.............................................................................................34
cp – Copy Files And Directories....................................................................................34
Useful Options And Examples..................................................................................35
mv – Move And Rename Files......................................................................................36
Useful Options And Examples..................................................................................36
rm – Remove Files And Directories...............................................................................37
Useful Options And Examples..................................................................................37
Be Careful With rm!.............................................................................................38
ln – Create Links............................................................................................................39
Hard Links................................................................................................................39
Symbolic Links..........................................................................................................40
Let's Build A Playground................................................................................................40
Creating Directories..................................................................................................40
Copying Files............................................................................................................41
Moving And Renaming Files.....................................................................................42
Creating Hard Links..................................................................................................43
Creating Symbolic Links...........................................................................................44
Removing Files And Directories...............................................................................45
Creating Symlinks With The GUI.........................................................................47
Summing Up.............................................................................................................47
6 – Working With Commands........................................................................48
What Exactly Are Commands?......................................................................................48
Identifying Commands...................................................................................................49
type – Display A Command's Type...........................................................................49
which – Display An Executable's Location...............................................................49
Getting A Command's Documentation..........................................................................50
help – Get Help For Shell Builtins............................................................................50
--help – Display Usage Information..........................................................................51
man – Display A Program's Manual Page................................................................51
apropos – Display Appropriate Commands..............................................................53
whatis – Display A Very Brief Description Of A Command.......................................53
The Most Brutal Man Page Of Them All..............................................................53
info – Display A Program's Info Entry.......................................................................54
README And Other Program Documentation Files................................................55
Creating Your Own Commands With alias....................................................................56
Revisiting Old Friends...................................................................................................58
Further Reading.............................................................................................................58
7 – Redirection................................................................................................59
Standard Input, Output, And Error.................................................................................59
Redirecting Standard Output.........................................................................................60
Redirecting Standard Error............................................................................................61
Redirecting Standard Output And Standard Error To One File................................62
Disposing Of Unwanted Output................................................................................63
/dev/null In Unix Culture......................................................................................63
Redirecting Standard Input............................................................................................63
cat – Concatenate Files............................................................................................63
Pipelines........................................................................................................................65
Filters........................................................................................................................66
uniq - Report Or Omit Repeated Lines....................................................................66
wc – Print Line, Word, And Byte Counts..................................................................67
grep – Print Lines Matching A Pattern......................................................................67
head / tail – Print First / Last Part Of Files................................................................68
tee – Read From Stdin And Output To Stdout And Files..........................................69
Summing Up..................................................................................................................70
Linux Is About Imagination..................................................................................70
8 – Seeing The World As The Shell Sees It..................................................72
Expansion......................................................................................................................72
Pathname Expansion...............................................................................................73
Pathname Expansion Of Hidden Files.................................................................74
Tilde Expansion........................................................................................................74
Arithmetic Expansion................................................................................................75
Brace Expansion......................................................................................................76
Parameter Expansion...............................................................................................77
Command Substitution.............................................................................................78
Quoting..........................................................................................................................79
Double Quotes..........................................................................................................79
Single Quotes...........................................................................................................81
Escaping Characters................................................................................................82
Backslash Escape Sequences............................................................................82
Summing Up..................................................................................................................83
Further Reading.............................................................................................................83
9 – Advanced Keyboard Tricks.....................................................................84
Command Line Editing..................................................................................................84
Cursor Movement.....................................................................................................84
Modifying Text...........................................................................................................85
Cutting And Pasting (Killing And Yanking) Text........................................................85
The Meta Key......................................................................................................86
Completion....................................................................................................................86
Programmable Completion..................................................................................88
Using History.................................................................................................................88
Searching History.....................................................................................................89
History Expansion.....................................................................................................91
script....................................................................................................................91
Summing Up..................................................................................................................92
Further Reading.............................................................................................................92
10 – Permissions............................................................................................93
Owners, Group Members, And Everybody Else............................................................94
Reading, Writing, And Executing...................................................................................95
chmod – Change file mode.......................................................................................97
What The Heck Is Octal?.....................................................................................98
Setting File Mode With The GUI.............................................................................100
umask – Set Default Permissions..........................................................................101
Some Special Permissions................................................................................103
Changing Identities......................................................................................................104
su – Run A Shell With Substitute User And Group IDs..........................................105
sudo – Execute A Command As Another User.......................................................106
Ubuntu And sudo...............................................................................................107
chown – Change File Owner And Group................................................................107
chgrp – Change Group Ownership.........................................................................109
Exercising Our Privileges............................................................................................109
Changing Your Password.............................................................................................111
Further Reading...........................................................................................................112
11 – Processes..............................................................................................113
How A Process Works.................................................................................................113
Viewing Processes......................................................................................................114
Viewing Processes Dynamically With top...............................................................116
Controlling Processes..................................................................................................118
Interrupting A Process.............................................................................................119
Putting A Process In The Background....................................................................119
Returning A Process To The Foreground...............................................................120
Stopping (Pausing) A Process................................................................................121
Signals.........................................................................................................................122
Sending Signals To Processes With kill.................................................................122
Sending Signals To Multiple Processes With killall................................................125
More Process Related Commands.............................................................................125
Part 3 – Configuration And The Environment.............................127
12 – The Environment..................................................................................128
What Is Stored In The Environment?..........................................................................128
Examining The Environment..................................................................................128
Some Interesting Variables.....................................................................................130
How Is The Environment Established?.......................................................................131
What's In A Startup File?........................................................................................132
Modifying The Environment.........................................................................................134
Which Files Should We Modify?.............................................................................134
Text Editors.............................................................................................................134
Using A Text Editor.................................................................................................135
Why Comments Are Important..........................................................................138
Activating Our Changes..........................................................................................139
Summing Up................................................................................................................139
Further Reading..........................................................................................................139
13 – A Gentle Introduction To vi.................................................................140
Why We Should Learn vi.............................................................................................140
A Little Background ....................................................................................................141
Starting And Stopping vi..............................................................................................141
Compatibility Mode............................................................................................142
Editing Modes..............................................................................................................143
Entering Insert Mode..............................................................................................144
Saving Our Work....................................................................................................144
Moving The Cursor Around.........................................................................................145
Basic Editing................................................................................................................146
Appending Text.......................................................................................................146
Opening A Line.......................................................................................................147
Deleting Text...........................................................................................................148
Cutting, Copying And Pasting Text.........................................................................149
Joining Lines...........................................................................................................151
Search And Replace....................................................................................................151
Searching Within A Line..........................................................................................151
Searching The Entire File.......................................................................................151
Global Search And Replace...................................................................................152
Editing Multiple Files...................................................................................................154
Switching Between Files.........................................................................................155
Opening Additional Files For Editing......................................................................155
Copying Content From One File Into Another........................................................156
Inserting An Entire File Into Another.......................................................................157
Saving Our Work.........................................................................................................158
Further Reading..........................................................................................................159
14 – Customizing The Prompt.....................................................................160
Anatomy Of A Prompt..................................................................................................160
Trying Some Alternate Prompt Designs......................................................................162
Adding Color................................................................................................................163
Terminal Confusion............................................................................................163
Moving The Cursor......................................................................................................166
Saving The Prompt......................................................................................................167
Summing Up................................................................................................................167
Further Reading..........................................................................................................168
Part 4 – Common Tasks And Essential Tools.............................169
15 – Package Management..........................................................................170
Packaging Systems.....................................................................................................170
How A Package System Works...................................................................................171
Package Files.........................................................................................................171
Repositories............................................................................................................171
Dependencies.........................................................................................................172
High And Low-level Package Tools........................................................................172
Common Package Management Tasks.......................................................................173
Finding A Package In A Repository........................................................................173
Installing A Package From A Repository.................................................................173
Installing A Package From A Package File.............................................................174
Removing A Package.............................................................................................174
Updating Packages From A Repository..................................................................175
Upgrading A Package From A Package File...........................................................175
Listing Installed Packages......................................................................................176
Determining If A Package Is Installed.....................................................................176
Displaying Info About An Installed Package...........................................................177
Finding Which Package Installed A File.................................................................177
Summing Up................................................................................................................177
The Linux Software Installation Myth.................................................................178
Further Reading..........................................................................................................179
16 – Storage Media.......................................................................................180
Mounting And Unmounting Storage Devices..............................................................180
Viewing A List Of Mounted File Systems................................................................182
Why Unmounting Is Important...........................................................................185
Determining Device Names....................................................................................186
Creating New File Systems.........................................................................................189
Manipulating Partitions With fdisk..........................................................................189
Creating A New File System With mkfs..................................................................192
Testing And Repairing File Systems............................................................................193
What The fsck?..................................................................................................193
Formatting Floppy Disks..............................................................................................193
Moving Data Directly To/From Devices.......................................................................194
Creating CD-ROM Images..........................................................................................195
Creating An Image Copy Of A CD-ROM.................................................................195
Creating An Image From A Collection Of Files.......................................................195
A Program By Any Other Name.........................................................................196
Writing CD-ROM Images.............................................................................................196
Mounting An ISO Image Directly............................................................................196
Blanking A Re-Writable CD-ROM...........................................................................197
Writing An Image....................................................................................................197
Further Reading..........................................................................................................197
E
在电商两极化趋势越来越明显的当下,中小店主们该如何从重重包围中突围而出?如何在店铺包装上一鸣惊人?爆款已死,唯有真正小而
3天学会电脑组装-(附赠多媒体光盘1张) 本书特色 为避免电脑入门者学习电脑的盲目性,编者在大量实践的基础上总结自己的学习经验并经过精心设计,将组装电脑的整个过...
《元宇宙超入门》内容简介:我们每天都在数字化生活之中。元宇宙,是数字化经济与生活的终极形态。元宇宙=实体世界数字世界。临界点
全国计算机等级考试教程二级公共基础知识 本书特色 《全国计算机等级考试教程——二级公共基础知识》依据教育部考试中心*新发布的《全国计算机等级考试大纲》以及作者多...
《知道点世界名人》内容简介:谁是撬起地球的人?谁是推动地球旋转的人?恺撒为什么被尊称为战神?莎士比亚是怎样写出千古不朽的名
《呵护女性生殖健康》内容简介:妇科、产科误区和疾病无声无息地困扰着广大女性朋友,严重伤害了女性健康,甚至损害了女性的生殖能
Thisbookoffersastep-by-stepguidetotheexperimentalplanningprocessandtheensuingana...
AlcAnderson感谢家人对他写作的支持.a他觉得与Ryan合作是件幸运的事.aAl是萨利什库特奈大学的学术IT服务主任,1教授网络服务、网络
《约翰·托兰自传》内容简介:★普利策奖得主、知名二战历史学者、《希特勒传》作者约翰·托兰封笔之作。★亲历20世纪影响世界格局
《你好,乳房:塑造乳房健康美》内容简介:提到乳房疾病,只有极少数人有关注意识,而这少数人几乎把所有焦点都放在乳腺癌上,对其
数位达尔文主义 本书特色 在这本书中,作者对高度竞争的网络经济进行了前所未有的深入考察,概括出立足网络的企业在形形色色的网上市场中生存与发展的7个关键战略。通过...
埋弧焊X射线焊缝图像缺陷检测算法研究 本书特色 1)基于x射线焊缝图像的埋弧焊焊缝缺陷自动检测研究现状;2)基于射线缺陷检测的概念、焊缝缺陷检测中常用的特征值,...
《设计,无处不在》从早餐时喝粥用的汤勺到救人性命的医疗设备,设计无处不在。设计不仅涵盖了风格和品味,还融入了文化与个性的影
数据驱动的金融时间序列预测模型研究 本书特色 以非线性动力学的观点看来,现代金融理论中金融系统的不确定性恰恰源于其自身就是一个受多种因素综合影响的具有开放性质的...
《中国零售业发展监测与分析报告(2014)》内容简介:本书按年度全面监测中国零售业发展情况,分析中国零售业发展脉络,重点是中国
錢研發的高科技產品,為何九五%都是賠錢貨?錢景?還是陷阱?九組關鍵準則,判讀最值得投資的高科技產業。對創造、投資新科技的
《JSP应用开发详解》(第3版)结合JSP和Servlet的最新规范,从基本的语法和规范入手,以经验为后盾,以实用为目标,以实例为导向,
图像分割的认知物理学方法 内容简介 《图像分割的认知物理学方法》在深入研究认知物理学理论的基础上,探索了图像分割的粒度原理,建立了图像分割的认知物理学粒计算框架...
ProgrammingontheWebtodaycaninvolveanyofseveraltechnologies,buttheCommonGatewayIn...
国内首部复杂网络专著【图书目录】第1章引论1.1引言1.2复杂网络研究简史1.3基本概念1.4本书内容简介参考文献第2章网络拓扑基