The Linux Command Line
Total Page:16
File Type:pdf, Size:1020Kb
The Linux Command Line Third Internet Edition William Shotts A LinuxCommand.org Book Copyright ©2008-2016, William E. Shotts, Jr. This work is licensed under the Creative Commons Attribution-Noncommercial-No De- rivative Works 3.0 United States License. To view a copy of this license, visit the link above or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042. A version of this book is also available in printed form, published by No Starch Press. Copies may be purchased wherever fine books are sold. No Starch Press also offers elec- tronic formats for popular e-readers. They can be reached at: https://www.nostarch.com. Linux® is the registered trademark of Linus Torvalds. All other trademarks belong to their respective owners. This book is part of the LinuxCommand.org project, a site for Linux education and advo- cacy devoted to helping users of legacy operating systems migrate into the future. You may contact the LinuxCommand.org project at http://linuxcommand.org. Release History Version Date Description 16.07 July 28, 2016 Third Internet Edition. 13.07 July 6, 2013 Second Internet Edition. 09.12 December 14, 2009 First Internet Edition. Table of Contents Introduction....................................................................................................xvi Why Use The Command Line?.....................................................................................xvi What This Book Is About..............................................................................................xvii Who Should Read This Book.......................................................................................xvii What's In This Book.....................................................................................................xviii How To Read This Book..............................................................................................xviii Prerequisites............................................................................................................xix Why I Don't Call It “GNU/Linux”...........................................................................xix Acknowledgments..........................................................................................................xx First Internet Edition..................................................................................................xx Second Internet Edition.............................................................................................xx Third Internet Edition................................................................................................xxi Your Feedback Is Needed!............................................................................................xxi What's New In The Third Internet Edition.....................................................................xxi Further Reading............................................................................................................xxi Colophon.......................................................................................................................xxi Part 1 – Learning The Shell..............................................................1 1 – What Is The Shell?.....................................................................................2 Terminal Emulators..........................................................................................................2 Your First Keystrokes......................................................................................................2 Command History.......................................................................................................3 Cursor Movement.......................................................................................................3 A Few Words About Mice And Focus....................................................................3 Try Some Simple Commands..........................................................................................4 Ending A Terminal Session..............................................................................................5 The Console Behind The Curtain..........................................................................5 Summing Up....................................................................................................................5 Further Reading...............................................................................................................6 2 – Navigation...................................................................................................7 Understanding The File System Tree..............................................................................7 The Current Working Directory........................................................................................7 Listing The Contents Of A Directory................................................................................8 Changing The Current Working Directory.......................................................................9 Absolute Pathnames..................................................................................................9 i Relative Pathnames...................................................................................................9 Some Helpful Shortcuts............................................................................................11 Important Facts About Filenames........................................................................11 Summing Up..................................................................................................................12 3 – Exploring The System.............................................................................13 More Fun With ls...........................................................................................................13 Options And Arguments............................................................................................14 A Longer Look At Long Format.................................................................................16 Determining A File's Type With file................................................................................17 Viewing File Contents With less....................................................................................17 What Is “Text”?.....................................................................................................17 Less Is More........................................................................................................19 A Guided Tour................................................................................................................19 Symbolic Links...............................................................................................................23 Hard Links.....................................................................................................................24 Summing Up..................................................................................................................24 Further Reading.............................................................................................................24 4 – Manipulating Files And Directories........................................................25 Wildcards.......................................................................................................................25 Character Ranges................................................................................................27 Wildcards Work In The GUI Too..........................................................................27 mkdir – Create Directories.............................................................................................28 cp – Copy Files And Directories....................................................................................28 Useful Options And Examples..................................................................................29 mv – Move And Rename Files......................................................................................30 Useful Options And Examples..................................................................................30 rm – Remove Files And Directories...............................................................................31 Useful Options And Examples..................................................................................32 Be Careful With rm!.............................................................................................32 ln – Create Links............................................................................................................33 Hard Links................................................................................................................33 Symbolic Links..........................................................................................................34 Let's Build A Playground................................................................................................34 Creating Directories..................................................................................................34 Copying Files............................................................................................................35 Moving And Renaming Files.....................................................................................36 Creating Hard Links..................................................................................................37