Get Started with Ubuntu 19.04

1,019 102 37MB

English Pages [629]

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Get Started with Ubuntu 19.04

  • Commentary
  • Let’s download books from mobilism.org and upload them to libgen

Table of contents :
Table of Contents
1. Introduction
2. Installing Ubuntu
3. The Ubuntu Desktop
4. Updating and Securing Ubuntu
5. File Manager
6. System Settings
7. Network Configuration
8. Installing Software
9. E-mail
10. Backups
11. Using the Terminal or Command Line Interface (CLI)
12. Working with Files and Directories
13. Working with Users and Groups
14. Working with commands
15. Working with Processes and Services
16. Editing files
17. Processing text files
18. Networking
19. Installing software
20. Working with disks
21. Working with removable media
22. SSH
23. Sharing files
24. Installing Alternate Desktops
25. Ubuntu Recovery Mode
26. Manual Disk Provisioning
27. Windows and Ubuntu Dual Boot
Final Thoughts
About the Author

Citation preview

Get Started with Ubuntu 19.04 “Disco Dingo”

Get Started with Ubuntu ® 19.04 “Disco Dingo” Copyright © 2019 Matthew Vogel Ubuntu ® is a registered trademark of Canonical Ltd. Linux ® is a registered trademark of Linus Torvalds All other trademarks used in this book are the property of their respective holders. Use of any trademark in this book does not constitute an affiliation with/or an endorsement from the trademark holder. The use of the Ubuntu trademark does not constitute an affiliation with/or endorsement by Canonical or the Ubuntu project. Rather than put a trademark symbol after every occurrence of a trademark name, we use names in an editorial fashion only, and to benefit the trademark holder, with no intention of infringement of the trademark. All information in this book is presented on an “as-is” basis. No warranty or guarantee is provided and the author and/or publisher shall not be held liable for any loss or damage.

TABLE OF CONTENTS

Table of Contents 1. Introduction 1.1 What this book is 1.2 What this book is not 1.3 What is Ubuntu 1.4 Why I like Ubuntu 1.5 Getting Ubuntu 1.6 How are you going to install Ubuntu 1.6.1 Live DVD or USB 1.6.2 Install to the hard drive 1.6.3 Virtualization 1.6.4 UEFI Secure Boot 1.7 Long Term Support (LTS) 2. Installing Ubuntu 2.1 Booting Ubuntu 2.2 Preparing to Install Ubuntu 2.2.1 Language 2.2.2 Keyboard Layout 2.2.3 Updates and other Software 2.2.4 Installation Type 2.2.5 Where are you? 2.2.6 Who Are You? 2.2.7 Installation Complete 2.2.8 Login Screen 3. The Ubuntu Desktop 3.1 Gnome Desktop 3.1.1 Dock 3.1.1.1 Firefox

3.1.1.2 Thunderbird 3.1.1.3 File Manager 3.1.1.4 Rhythmbox 3.1.1.5 LibreOffice Writer 3.1.1.6 Ubuntu Software 3.1.1.7 Help 3.1.1.6 Amazon 3.1.2 Activities 3.1.3 Searching for Applications 3.1.4 The Upper Right Hand Corner 3.1.4.1 Volume Slider 3.1.4.2 Brightness Slider 3.1.4.3 Network Menu 3.1.4.4 Bluetooth Menu 3.1.4.5 Battery Menu 3.1.4.6 User Menu 3.1.4.7 Settings Button 3.1.4.8 Lock Button 3.1.4.9 Power Button 3.1.5 Trash 3.1.6 Applications 3.1.7 Open Windows 3.1.8 Calendar 3.1.8.1 Calendar Edit 3.1.8.2 Add Event 3.1.8.2 Edit Details 3.1.8.3 Delete Event 3.1.8.4 Week View 3.1.8.5 Month View 3.1.8.6 Year View 3.1.8.7 Search

3.1.8.8 Calendar Settings 3.1.9 Workspaces 4. Updating and Securing Ubuntu 4.1 Software Updater 4.2 apt 4.2.1 apt update 4.2.2 apt upgrade 4.2.2 apt dist-upgrade 4.2.3 Autoremove 4.3 Firewall 5. File Manager 5.1 Grid and List Views 5.2 Search 5.2.1 When 5.2.2 What 5.3 File Manager Menu 5.3.1 Right File Manager Menu 5.3.1.1 New File Manager Window 5.3.1.2 New Tab 5.3.1.3 New Folder 5.3.1.5 Edit 5.3.1.6 Select All 5.3.1.7 Show Hidden Files 5.3.1.8 Sidebar 5.3.1.9 Preferences 5.3.1.9.1 Views 5.3.1.9.1.1 General 5.3.1.9.1.2 Sort 5.3.1.9.1.3 List View 5.3.1.9.1.4 Icon View Captions 5.3.1.9.2 Behavior

5.3.1.9.2.1 Open Action 5.3.1.9.2.2 Link Creation 5.3.1.9.2.3 Executable Text Files 5.3.1.9.2.4 Trash 5.3.1.9.3 List Columns 5.3.1.9.4 Search & Preview 5.3.1.9.4.1 Search 5.3.1.9.4.1.1 Search in subfolders 5.3.1.9.4.1.2 Full text search 5.3.1.9.4.2 Thumbnails 5.3.1.9.4.3 File Count 5.3.1.10 Keyboard Shortcuts 5.3.1.11 Help 5.3.1.12 About 5.3.2 Left File Manager Menu 5.3.2.1 Grid View Menu 5.3.2.1.1 Zoom 5.3.2.1.2 Undo 5.3.2.1.3 Redo 5.3.2.1.4 Sort 5.3.2.1.4.1 A-Z 5.3.2.1.4.2 Z-A 5.3.2.1.4.3 Last Modified 5.3.2.1.4.4 First Modified 5.3.2.1.4.5 Size 5.3.2.1.4.6 Type 5.3.2.1.5 Reload 5.3.2.2 List View Menu 5.4 Navigation 5.5 Right Click - Empty Space 5.5.1 New Folder

5.5.2 Paste 5.5.3 Select All 5.5.4 Properties 5.5.4.1 Basic Tab 5.5.4.2 Permissions Tab 5.5.4.3 Local Network Share Tab 5.5.5 Restore Missing Files 5.5.6 Open in Terminal 5.6 Right Click - Directory 5.6.1 Open 5.6.2 Open In New Tab 5.6.3 Open in New Window 5.6.4 Open With Other Application 5.6.5 Cut 5.6.6 Copy 5.6.7 Paste Into Folder 5.6.8 Move to 5.6.9 Copy to 5.6.10 Move to Trash 5.6.11 Rename 5.6.12 Compress 5.6.13 Right Click on Compressed File 5.6.13.1 Open With Archive Manager 5.6.13.1.1 New Archive 5.6.13.1.2 Open 5.6.13.1.3 Save As 5.6.13.1.4 Password 5.6.13.1.5 Test Integrity 5.6.13.1.6 Properties 5.6.13.1.7 View All Files 5.6.13.1.8 View as a Folder

5.6.13.1.9 Sidebar 5.6.13.1.10 Help 5.6.13.1.11 About Archive Manager 5.6.13.2 Extract Here 5.6.13.3 Extract to 5.6.14 Local Network Share 5.6.15 Revert to Previous Version 5.6.16 Open in Terminal 5.6.17 Send to 5.6.18 Star 5.6.19 Unstar 5.6.20 Properties 5.6.20.1 Basic Tab 5.6.20.2 Permissions Tab 5.6.20.3 Local Network Share Tab 5.7 Right Click - File 5.7.1 Open With Text Editor 5.7.2 Open With Other Application 5.7.3 Cut 5.7.4 Copy 5.7.5 Move To 5.7.6 Copy To 5.7.7 Move to Trash 5.7.8 Rename 5.7.9 Compress 5.7.10 Revert to Previous Version 5.7.11 Send to 5.7.12 Properties 5.7.12.1 Basic Tab 5.7.12.2 Permissions Tab 5.7.12.3 Open With Tab

5.8 Files Menu 5.8.1 New Window 5.8.2 Show Details 5.8.3 Quit 6. System Settings 6.1 Wi-Fi 6.2 Bluetooth 6.3 Background 6.3.1 Wallpapers 6.3.2 Pictures 6.3.3 Colors 6.4 Dock 6.5 Notifications 6.6 Search 6.7 Region & Language 6.7.1 Language 6.7.2 Formats 6.7.3 Input Sources 6.7.4 Options 6.7.5 Install and Remove Input Sources 6.7.6 Manage Installed Languages 6.8 Universal Access 6.8.1 Seeing 6.8.1.1 High Contrast 6.8.1.2 Large Text 6.8.1.3 Cursor Size 6.8.1.4 Zoom 6.8.1.4.1 Magnifier 6.8.1.4.2 Crosshairs 6.8.1.4.3 Color Effects 6.8.1.5 Screen Reader

6.8.1.6 Sound Keys 6.8.2 Hearing 6.8.3 Typing 6.8.3.1 Screen Keyboard 6.8.3.2 Repeat Keys 6.8.3.3 Cursor Blinking 6.8.3.4 Typing Assistant 6.8.4 Pointing and Clicking Tab 6.8.4.1 Mouse Keys 6.8.4.2 Click Assist 6.8.4.3 Double-Click Delay 6.9 Online Accounts 6.10 Privacy 6.10.1 Screen Lock 6.10.2 Location Services 6.10.3 Usage & History 6.10.4 Purge Trash & Temporary Files 6.10.5 Problem Reporting 6.10.6 Network Connectivity Checking 6.11 Applications 6.12 Sharing 6.13 Sound 6.13.1 System Volume 6.13.2 Volume Levels 6.13.3 Output 6.13.4 Input 6.13.5 Alert Sound 6.14 Power 6.14.1 Battery 6.14.2 Power Saving 6.14.3 Suspend & Power Button

6.15 Network 6.16 Devices 6.16.1 Displays 6.16.2 Keyboard 6.16.3 Mouse & Touchpad 6.16.3.1 General 6.16.3.2 Touchpad 6.16.4 Printers 6.16.5 Removable Media 6.16.6 Thunderbolt 6.16.7 Color 6.17 Details 6.17.1 About 6.17.2 Date & Time 6.17.3 Users 6.17.3.1 Change Password 6.17.3.2 Set Account Type 6.17.3.3 Language 6.17.3.4 Automatic Login 6.17.3.5 Last Login 6.17.3.6 Add User Account 6.17.3.7 Setting a User Picture 6.17.3.8 Renaming a User 6.17.3.9 Removing a User 6.17.4 Default Applications 7. Network Configuration 7.1 Wired (Ethernet) 7.1.1 Details 7.1.2 Identity 7.1.3 IPv4 7.1.3.1 Automatic (DHCP)

7.1.3.2 Manual 7.1.3.3 Link-Local Only 7.1.3.4 Disable 7.1.4 IPv6 7.1.4.1 Automatic 7.1.4.2 Automatic DHCP Only 7.1.4.3 Link-Local Only 7.1.4.4 Manual 7.1.4.5 Disable 7.1.5 Security 7.2 Wireless 7.2.1 Details 7.2.2 Identity 7.2.3 Authentication 7.2.4 Hidden Network 7.2.5 Wi-Fi Hotspot 7.2.6 Known Wi-Fi Networks 7.3 VPN 7.4 Network Proxy 8. Installing Software 8.1 Ubuntu Software 8.1.1 All Tab 8.1.2 Installed Tab 8.1.3 Updates Tab 8.2 Installing Software 8.3 Removing Software 8.4 apt 9. E-mail 10. Backups 10.1 Overview 10.1.1 Restore

10.1.2 Back Up Now 10.2 Folders to Save 10.3 Folders to Ignore 10.4 Storage Location 10.5 Scheduling 11. Using the Terminal or Command Line Interface (CLI) 11.1 Text only please 11.2 Bash 11.3 The Terminal Basics 11.3.1 echo 11.3.2 cat 11.3.3 history 11.3.4 help 11.3.5 date 11.3.6 cal 11.4 Moving around on the CLI 11.5 Tab Autocomplete 12. Working with Files and Directories 12.1 The Linux file system 12.2 Linux File Types 12.3 Moving around the file system 12.3.1 Where am I? 12.3.2 pwd 12.3.3 cd 12.3.4 Filesystem shortcuts 12.3.4.1 Going Home 12.3.4.2 Root 12.3.4.3 Go back from where you came 12.3.4.4 Moving Back 12.3.4.5 Stay right here 12.4 Listing Files

12.4.1 Basic list 12.4.2 Long list 12.4.3 List all files 12.5 Making Files and Directories 12.5.1 touch 12.5.2 mkdir 12.5.2 Redirection 12.6 Removing Files and Directories 12.6.1 rm 12.6.2 Wildcards 12.6.3 Ranges 12.6.4 rm -r 12.6.5 rmdir 12.7 File Permissions 12.7.1 Sticky Bit 12.7.2 Changing Permissions 12.7.2.1 chmod 12.7.2.2 Setting the Sticky Bit 12.7.3 Changing the owner 12.7.4 Changing the group 12.8 Copying and Moving Files and Directories 12.8.1 cp 12.8.1.1 Copy a file to the same directory 12.8.1.2 Copy a file to a different directory 12.8.1.3 Copy a file from one directory to another 12.8.1.4 Copy a directory 12.8.2 mv 12.8.2.1 Move a file 12.8.2.2 Move a directory 12.9 Finding Files and Directories 12.9.1 find

12.9.2 locate 12.9.3 locate versus find 12.9.4 which 12.10 Zipping and Unzipping Files 12.10.1 tar 12.10.2 gzip 12.10.3 zip 12.10.4 gunzip 12.10.5 unzip 12.10.6 tar to unzip 12.11 Links 12.11.1 Inodes 12.11.2 Hard Link 12.11.3 Soft Link 12.12 File information 12.12.1 file 12.12.2 stat 13. Working with Users and Groups 13.1 Users 13.2 Root User 13.2.1 sudo 13.2.2 su 13.2.3 Using su 13.3 Users 13.3.1 useradd 13.3.2 userdel 13.3.3 passwd 13.3.4 passwd file 13.3.5 shadow file 13.4 Groups 13.4.1 groupadd

13.4.2 groupdel 13.4.3 group file 13.5 Modifying Users 13.5.1 usermod 13.5.1.1 -c Comment 13.5.1.2 -d Modify Home Directory and -m Move home directory 13.5.1.3 -e Expiration date 13.5.1.4 -f Inactivate an account 13.5.1.5 -g Logon Group 13.5.1.6 -G Supplemental groups 13.5.1.7 -l Rename user 13.5.1.8 -L Lock Account 13.5.1.9 -U Unlock Account 13.5.2 chage 13.5.2.1 -l List 13.5.2.2 -d Last day since password change 13.5.2.3 -E Expiration date 13.5.2.4 -m Minimum number of days between password changes 13.5.2.5 -M Maximum number of days password is valid 13.5.2.6 -I Inactive number of days after password expires account becomes inactive 13.5.2.7 -W Warn days 13.5.2.8 Interactive mode 14. Working with commands 14.1 Identifying commands 14.1.1 type 14.1.2 which 14.2 Getting help 14.2.1 man 14.2.2 apropos 14.2.3 help

14.2.4 info 14.3 Aliases 14.3.1 alias 14.3.2 unalias 14.4 Redirection 14.4.1 Standard Out 14.4.2 Standard In 14.4.3 Standard Error 14.4.4 Pipes 14.5 Quotes 14.6 Expansion 14.6.1 Arithmetic Expansion 14.6.2 Brace Expansion 14.6.3 Variable Expansion 14.6.4 Command Expansion 14.7 Escaping 14.8 Controlling commands 14.8.1 Ctrl+C 14.8.2 Ctrl+Z 14.8.3 jobs 14.8.4 fg 14.8.5 bg 15. Working with Processes and Services 15.1 Processes 15.1.1 ps 15.1.2 top 15.1.3 kill 15.1.4 killall 15.2 Services 15.2.1 systemctl 15.2.1.1 status

15.2.1.2 start 15.2.1.3 stop 15.2.1.4 restart 15.2.1.5 enable 15.2.1.6 is-enable 15.2.1.7 disable 16. Editing files 16.1 nano 16.1.1 Starting nano 16.1.2 Editing a file 16.1.3 Getting Help 16.1.4 Reading Files 16.1.4.1 Get Help 16.1.4.2 Cancel 16.1.4.3 Execute Command 16.1.4.4 New Buffer 16.1.4.5 To Files 16.1.5 Write Out 16.1.5.1 Get Help 16.1.5.2 Cancel 16.1.5.3 DOS Format 16.1.5.4 Mac Format 16.1.5.5 Append 16.1.5.6 Prepend 16.1.5.7 Backup File 16.1.5.8 To Files 16.1.6 Where Is 16.1.7 Replace 16.1.8 Cut Text 16.1.9 Uncut Text 16.1.10 Justify

16.1.11 To Spell 16.1.12 Cur Pos 16.1.13 Go To Line 16.2 vi 16.2.1 What is vi 16.2.2 Starting vi 16.2.3 Vi Modes 16.2.3.1 Vi Mode 16.2.3.2 Insert Mode 16.2.3.3 Replace Mode 16.2.3.4 Ex Command Mode 16.2.3.5 Search Mode 16.2.4 Opening a file 16.2.4.1 Opening a file from the command line 16.2.4.2 Opening a file from inside vi 16.2.4.3 Problems with opening an existing file 16.2.5 Saving a file 16.2.5.1 :w filename 16.2.5.2 Saving lines to a new file 16.2.6 Quitting vi 16.2.6.1 :q 16.2.6.2 :wq 16.2.6.3 Shift ZZ 16.2.7 Vi compatible mode 16.2.7.1 Creating a .vimrc file 16.2.8 Autosave (sort of) 16.2.9 Moving Around Vi 16.2.9.1 Moving around with the arrow keys 16.2.9.2 Moving around with h j k l 16.2.9.3 w - Beginning of the next word or punctuation mark 16.2.9.4 W - Beginning of the next word ignoring punctuation

mark 16.2.9.5 b - Beginning of the previous word or punctuation 16.2.9.6 B - Beginning of the previous word ignoring punctuation marks 16.2.9.7 e - End of the next word or punctuation mark 16.2.9.8 E - End of the next word ignoring punctuation marks 16.2.9.9 $ - End of the current line 16.2.9.10 0 - Start of the current line 16.2.9.11 :set nu 16.2.9.12 G - Last line in the file 16.2.9.13 [line number x]G - Move to line number x 16.2.9.15 H - Move the cursor to the top of the screen 16.2.9.17 L - Move the cursor to the bottom of the screen 16.2.9.18 Ctrl+f - Move forward one screen 16.2.9.19 Ctrl+b - Move backward one screen 16.2.9.21 Ctrl+u -Move backward one half screen 16.2.9.22 Ctrl+g - Show the current cursor position 16.2.10 Editing Files 16.2.10.1 i - Insert text at current location 16.2.10.2 I - Insert text at the beginning of the line 16.2.10.3 a - Insert after current location 16.2.10.4 A - Insert after end of the current line 16.2.10.5 x - Delete text at the cursor 16.2.10.6 u - Undo the last change 16.2.10.7 Ctrl+r - Redo 16.2.10.8 dd - Delete the current line 16.2.10.9 D - Delete the to the end of the current line 16.2.10.10 Delete Command Combinations 16.2.10.11 p - Put text from the buffer after the current line 16.2.10.12 P - Put text from the buffer before the current line 16.2.10.13 yy - Copy current line (also known as yank)

16.2.10.14 Yank Command Combinations 16.2.10.15 r - Replace a single character 16.2.10.16 R - Replace text until Esc 16.2.10.17 o - Open a line below and enter insert mode 16.2.10.18 O - Open a line above and enter insert mode 16.2.10.19 cc - Change the current line 16.2.10.20 ~ to change the case 16.2.10.21 J - Join lines 16.2.11 Searching in a file 16.2.11.1 Search forward 16.2.11.2 n - Go to the next instance 16.2.11.3 N - Go to the previous instance 16.2.11.4 Search backward in a file 16.2.11.5 Ctrl o - Return to previous position 16.2.11.6 Ctrl i - Go back forward again 16.2.11.7 Up and down arrows to search again 16.2.11.8 % to find matching brackets 16.2.12 Search and replace 16.2.13 Marking Text 16.2.13.1 v - Mark visually with arrow keys 16.2.13.2 Saving marked text 16.2.14 Merging files 16.2.15 Split screen 16.2.15.1 Switching between windows 16.2.15.2 Resizing the window 16.2.15.3 Copy and paste between windows 16.2.15.4 Closing split windows 16.2.16 Named buffers 16.2.17 Markers 16.2.18 Vimtutor 16.2.19 Help

17. Processing text files 17.1 Viewing text files 17.1.1 cat 17.1.2 head 17.1.3 tail 17.1.4 more 17.1.5 less 17.2 wc - Word Count 17.3 diff - Compare files 17.4 grep 17.5 sort 17.6 paste 17.7 nl 17.8 uniq 18. Networking 18.1 Network manager 18.1.1 Disabling the Network Manager 18.1.2 Enabling the Network Manager 18.2 Configure Networking 18.2.1 ifconfig 18.2.2 List all interfaces 18.2.3 Configure a static IPv4 address 18.2.4 Configure a static IPv6 address 18.2.5 dhclient 18.2.6 Wireless Networks 18.2.6.1 Finding Wireless Interface 18.2.6.2 ip link 18.2.6.3 Locating a Wireless Network 18.2.6.4 Connecting to a Wireless Network with WPA 18.2.6.5 Connecting to a Wireless Network with WEP 18.2.6.6 Connecting to a Wireless Network without security

18.2.7 Configuring Interfaces on Boot 18.2.8 ifup 18.2.9 ifdown 18.3 Testing Network Connectivity 18.3.1 ping 18.3.1.1 Loopback 18.3.1.2 Default Gateway 18.3.1.3 IP 18.3.1.4 Hostname 18.3.2 traceroute 18.4 Name Resolution 18.4.1 /etc/hosts 18.4.2 DNS 18.4.2.1 nslookup 18.4.2.2 dig 18.5 route 19. Installing software 19.1 apt-get 19.1.1 apt-get update 19.1.2 apt-get upgrade 19.1.3 apt-get dist-upgrade 19.1.4 apt-get install 19.1.5 apt-get cache 19.1.6 apt-get remove 20. Working with disks 20.1 df 20.2 lshw 20.3 fdisk 20.3.1 Listing partitions 20.3.2 fdisk menu 20.3.3 Create a new partition

20.3.4 Set partition type 20.4 Create the filesystem 20.4.1 Create a Linux filesystem 20.4.2 Create an NTFS filesystem 20.4.3 Create a FAT32 filesystem 20.5 Mounting a disk 20.5.1 Create a mount point 20.5.2 Mount the partition 20.5.3 Test the new mounted partition 20.6 Unmounting a disk 20.7 /etc/fstab 21. Working with removable media 21.1 CD/DVD 21.2 USB Disk 22. SSH 22.1 SSH Server 22.1.1 Installing SSH Server 22.2 SSH Client 22.3 Connecting to SSH Server 22.3.1 Linux, Unix, and Mac 22.3.2 Windows 22.3.3 Firewalls 23. Sharing files 23.1 FTP 23.1.1 FTP Server Install 23.1.2 Firewalls 23.1.4 FTP Client 23.1.4.1 Connecting to a server 23.1.4.2 Passive Mode 23.1.4.3 Help 23.1.4.4 List Remote Files

23.1.4.5 List Local Files 23.1.4.6 Current Remote Directory 23.1.4.6 Current Local Directory 23.1.4.7 Change Remote Directory 23.1.4.8 Change Local Directory 23.1.4.9 Get Files 23.1.4.10 Put Files 23.1.4.11 Exit FTP 23.2 SFTP 23.3 HTTP/HTTPS 23.4 NFS 23.4.1 Installing NFS 23.4.2 Firewalls 23.4.3 /etc/exports 23.4.4 NFS Client 23.4.4.1 mount 23.5 Samba 23.5.1 Installing Samba 23.5.3 Firewalls 23.5.4 Configure a Samba Password 23.5.5 Edit /etc/samba/smb.conf 23.5.6 Connecting to a Samba Server 23.5.6.1 Linux 23.5.6.2 Fstab 23.5.6.2.1 User File 23.5.6.3 Windows 24. Installing Alternate Desktops 24.1 GNOME Flashback 24.2 KDE 25. Ubuntu Recovery Mode 26. Manual Disk Provisioning

26.1 Installation Types 26.2 Create a New Partition 26.3 Free Space 26.4 Swap Area 26.5 Root Partition 26.6 Other Partition Types 27. Windows and Ubuntu Dual Boot 27.1 Dual Boot Preparations 27.2 Ubuntu Installation 27.3 Sharing Files Between Operating Systems Final Thoughts About the Author

1. INTRODUCTION

1. Introduction 1.1 What this book is This book is a beginner’s guide to installing and using Ubuntu 19.04 “Disco Dingo”, the newest version of the popular Linux distribution. This book was written for a new Linux or Ubuntu user. This book is an update from my previous book covering Ubuntu 18.10 released earlier this year.

1.2 What this book is not This book is not an exhaustive guide to the Linux operating system. I do not want to overload a new user to Linux so my goal is to keep this book relatively simple and geared toward the new Linux user and tackle more advanced topics in other books. This book is not professionally edited. I am basically a one man show with a full time job in the Network Security field, a part time job teaching Network Security at night, a part time photographer, and part time writer. While I have done my best to find my mistakes, this book will have spelling and grammar errors, I promise. If you find one let me know and I will make sure to fix the problem in the next edition. You can email issues to [email protected].

1.3 What is Ubuntu I am not going to waste a lot of time explaining what Ubuntu is and where it comes from. You can read all about Ubuntu on their Wikipedia page at http://en.wikipedia.org/wiki/Ubuntu_(operating_system). I will tell you that Ubuntu is a form of Linux which is a free operating system that is Unix-like. My guess is that you already know that or you would not be reading this book.

1.4 Why I like Ubuntu I have been using Linux for about 16 years and using Ubuntu for about 9

years. I really like Ubuntu's ease of installation and ease of use once installed. Ubuntu also tends to include a lot of leading edge technology in their releases which means that it runs on a lot of the newer hardware without having to worry about installing special drivers. For a beginning Linux user you cannot go wrong with Ubuntu.

1.5 Getting Ubuntu You can download Ubuntu directly from their website at http://www.ubuntu.com. On the main page click on the download tab and then click on Ubuntu Desktop. You can also download a Server version and a Cloud version but these versions are outside of the scope of this book so I suggest you stick with the Desktop version. You will be downloading an ISO file which is a DVD image file.

1.6 How are you going to install Ubuntu There are many ways to use Ubuntu. Some of the options are: LiveDVD LiveUSB Install to the hard drive Virtualization 1.6.1 Live DVD or USB If you are going to use the Live DVD then you will have to burn the ISO to a DVD, not a CD as the ISO is too large for a CD. If you are going to use the Live USB you will need an 8GB or bigger USB thumb drive and a utility to create the Live USB. There are several utilities on the Internet for burning an ISO to a DVD or USB Thumb Drive. Some operating systems come with utilities that allow you to burn an ISO image to a DVD or create a bootable USB from an ISO image. Figure 1-1 shows the Startup Disk Creator that comes with Ubuntu. You have to provide a source ISO and a USB device to burn the image to.

Figure 1-1. Startup Disk Creator

The Live DVD or Live USB allows you to boot into Ubuntu without installing the operating system to your hard drive, sort of like try before you buy. You will have the option to install the operating system from the Live DVD or Live USB once the operating system boots. In order to boot from a Live DVD or Live USB you need to adjust the boot sequence in the BIOS to allow booting from the DVD or USB device. For most systems you will need to interrupt the boot process by pressing F2 or F12 on your keyboard to enter the BIOS. There will be a message that is displayed for a few seconds right at the start of the boot sequence that will tell you which key to push. Some BIOS also allow you to choose the boot device without editing the BIOS. Once you are in the BIOS look for a tab or section labeled Boot. This is where you will be able to change the boot options. Be sure to save your changes before you exit the BIOS. Figure 1-2 shows the Boot tab of a system BIOS utility. Depending on your system you may have to rearrange the boot order to get the DVD or USB to boot.

Figure 1-2. Bios Boot Order

1.6.2 Install to the hard drive If you install the operating system to your hard drive you can either use the whole hard drive for Ubuntu or you can dual boot between Windows and Ubuntu or Ubuntu and another flavor of Linux. In order to install a dual boot system with Windows and Ubuntu you should install Windows first and then install Ubuntu. You also need to have enough unallocated space on the hard drive to hold the Ubuntu system. Dual boot configurations are covered in Chapter 25. 1.6.3 Virtualization Virtualization is an option that allows you to keep your existing operating system and run Ubuntu in a Virtual Machine (VM). This is the method that I recommend for beginning Linux users unless you have an older laptop or PC that you do not use as your primary desktop. I personally run Ubuntu in a VM at home and at school when I teach. I also have a dedicated Ubuntu laptop. If you want to use Virtualization I recommend using VirtualBox, Figure 13. You can download VirtualBox for free from their website

https://www.virtualbox.org. If you are going to use Ubuntu in a VM you do not need to burn the ISO to a DVD or USB thumb drive. You only need to download the ISO and point the VM at the ISO as the boot media and off you go.

Figure 1-3. VirtualBox

1.6.4 UEFI Secure Boot When using installing Ubuntu on a system that supports UEFI Secure Boot, it is recommended that you disable Secure Boot. Some software will not work properly with UEFI Secure Boot enabled.

1.7 Long Term Support (LTS) Ubuntu 19.04 is not a Long Term Support (LTS) version. Ubuntu 18.04 was the last LTS version. A new version of Ubuntu is released every 6 months with an LTS version released every 2 years. A non LTS version will be supported with updates and security patches for 9 months and an LTS version will be supported for 5 years. For businesses using the Ubuntu LTS version on servers and desktops the longer support removes the need to upgrade every 6 to 9 months. I upgrade my laptop with each release of Ubuntu regardless of the LTS status but my laptop is not as important as a server or business desktop.

2. INSTALLING UBUNTU

2. Installing Ubuntu 2.1 Booting Ubuntu 2.2 Preparing to Install Ubuntu

2.1 Booting Ubuntu Now that you have your ISO downloaded and burned to a DVD, USB Thumb Drive, or loaded into a VM, you are ready to start installing Ubuntu by booting into Ubuntu. Figure 2-1 shows the initial Ubuntu boot screen. The screen includes a status indicator of 4 dots that shows you the boot progress.

Figure 2-1. Install - Initial Ubuntu boot screen

Once the LiveDVD, LiveUSB, or ISO in a VM boots you will have the option to Try Ubuntu in Live Mode or Install Ubuntu, Figure 2-2. If you opt to try the Live Mode you will not need to follow the installation steps and can skip to Chapter 3. Just remember that the next time you boot into Live

Mode any changes you have made will be lost.

Figure 2-2. Install - Try Ubuntu or Install Ubuntu

If you are using Live Mode and decide to install Ubuntu, you can start the install by clicking the Install Ubuntu 18.10 icon in the upper left hand corner of the desktop, Figure 2-3.

Figure 2-3. Install Ubuntu 18.04 LTS

2.2 Preparing to Install Ubuntu The following subsection are covered in this section:

2.2.1 Language 2.2.2 Keyboard Layout 2.2.3 Updates and other Software 2.2.4 Installation Type 2.2.5 Where are you? 2.2.6 Who Are You? 2.2.7 Installation Complete 2.2.8 Login Screen 2.2.1 Language The first step of the installation process is selecting your language, Figure 24. Once you select your language click Continue to proceed with the installation.

Figure 2-4. Install - Language

2.2.2 Keyboard Layout On the next screen, Figure 2-5, you will be asked to choose a keyboard layout. The installation should have already detected your keyboard version so you will most likely not need to change the default. Choose your keyboard layout and click Continue.

Figure 2-5. Install - Keyboard Layout

2.2.3 Updates and other Software On the next install screen, Figure 2-6, you will have the option to choose a Normal installation or a Minimal installation. A Normal installation will install all of the normal software installed with an Ubuntu desktop system. A Minimal installation will install only a web browser and some basic utilities, however, additional software can be added as needed. Be sure to check the boxes Download updates while installing and Install third-party software. Checking the first checkbox will speed up the installation of Ubuntu by downloading updates in the background while the installation is taking place. The second checkbox will allow Ubuntu to play various media like MP3 files. Click Continue to proceed with the installation.

Figure 2-6. Install - Updates and other software

2.2.4 Installation Type Next you will need to choose your installation type, Figure 2-7. The default option is to erase the entire disk and install Ubuntu. For most Ubuntu installations this will be the best choice.

Figure 2-7. Install - Installation type

The second choice will encrypt the Ubuntu installation and require a security key or password to unlock the system during the system boot. Encryption is

a good option for laptops if you want to protect sensitive data. If someone were to steal your laptop they would not be able to access the system without the security key or password. The third option installs Ubuntu using Logical Volume Management (LVM). LVM is a more advanced way of partitioning a disk that makes working with partitions easier. LVM is an advanced topic that will not be covered in this book. There is no danger in choosing this option. If you choose to encrypt the hard drive the LVM option will automatically be selected. The fourth option, Something else, is for those users that want to perform their own partitioning. This is an advanced topic that will be covered in more detail in Chapter 24. Manual partitioning is not recommended for for new Linux users so choose this option at your own risk. Once you choose your option click Install Now to continue the installation. If you choose to encrypt the hard drive you will be required to provide a security key twice, Figure 2-8. This key will be required each time your system boots. The password strength meter on the right hand side of the window will tell you how strong your password is and if both of your passwords match.

Figure 2-8. Install - Choose a security key

You will be asked to confirm your choice, Figure 2-9. Click Continue to continue the installation. If you want to make changes you can click Go Back.

Figure 2-9. Install - Write the changes to disks?

2.2.5 Where are you? On the next screen, Figure 2-10, you will be asked to choose your time zone. You can choose a time zone by simply clicking a location on the map. Once you select a location, click Continue to continue the installation.

Figure 2-10. Install - Time Zone

2.2.6 Who Are You? The next screen, Figure 2-12, will ask you to enter your name, your computer name, pick a username, and set your password. You can also choose to have Ubuntu log you in automatically when the system boots or require a password to login and to encrypt your home folder. Choosing to require a password and to encrypt your home folder is the most secure method to use so I highly recommend these options for any system that you are going to use outside of a lab or testing environment. You should not use the automatic logon option as it is very insecure. Anyone with access to your system will be able to login without a password. When entering your password, the password strength meter on the right hand side of the window will tell you how strong your password is and if both of your passwords match. Click Continue once you have entered all of the required information.

Figure 2-12. Install - Setting up a username and password

The system installation will now commence with the copying of the files to the hard drive, Figure 2-13.

Figure 2-13. Install - Copying files

2.2.7 Installation Complete You have finished the Ubuntu installation, Figure 2-14. Click Restart Now to restart and boot into your new Ubuntu system.

Figure 2-14. Installation Complete - Restart Now

2.2.8 Login Screen Once the reboot is complete you will be presented with the Ubuntu Login screen, Figure 2-15, unless you have an encrypted hard drive in which case you will have to provide your security key to decrypt the hard drive first, Figure 2-16. At the login screen, the account you created during the installation process will be highlighted. Use the password you set during the installation process to login.

Figure 2-15. Ubuntu - Login Screen

Figure 2-16. Ubuntu - Encrypted hard drive

3. THE UBUNTU DESKTOP

3. The Ubuntu Desktop Now that your Ubuntu system has been installed or you have booted into the LiveDVD mode we will explore the Ubuntu Gnome Desktop.

3.1 Gnome Desktop Figure 3-1 shows the Ubuntu Gnome desktop right after the first boot. Gnome is now the default Ubuntu desktop manager.

Figure 3-1. The Ubuntu Gnome Desktop

There are other desktop managers that can be used with Ubuntu. Alternate desktop managers will be covered in Chapter 22. The following subsections are covered in this section: 3.1.1 Dock 3.1.2 Activities 3.1.3 Searching for Applications 3.1.4 The Upper Right Hand Corner 3.1.5 Trash 3.1.6 Applications 3.1.7 Open Windows

3.1.8 Calendar 3.1.9 Workspaces 3.1.1 Dock The Ubuntu Gnome desktop features a Dock on the left hand side of the desktop, Figure 3-2, which allows you to launch some of the most common applications such as the Firefox web browser, Thunderbird email client, File Manager, Ubuntu Software Center, Help, and Amazon by just clicking on the icon for the corresponding application.

Figure 3-2. The Ubuntu Desktop - Gnome Dock

3.1.1.1 Firefox 3.1.1.2 Thunderbird 3.1.1.3 File Manager 3.1.1.4 Rhythmbox 3.1.1.5 LibreOffice Writer

3.1.1.6 Ubuntu Software 3.1.1.7 Help 3.1.1.6 Amazon 3.1.1.1 Firefox The first icon on the Dock is the Firefox icon which will launch the Firefox web browser, Figure 3-3.

Figure 3-3. Firefox web browser

3.1.1.2 Thunderbird The next icon on the Dock is the Thunderbird icon which will launch the Thunderbird email client, Figure 3-4.

Figure 3-4. Thunderbird email client

The Thunderbird email client will be covered in more detail in Chapter 9. 3.1.1.3 File Manager The next icon on the Dock is the File Manager icon which will launch the File Manager application, Figure 3-5.

Figure 3-5. File Manager

The File Manager lists the location of files on the left and the actual files in

the selected location on the right. The default location when the File Manager is launched is the current user's home folder. The File Manager works much like file managers in most other operating systems. The File Manager will be covered in more detail in Chapter 5. 3.1.1.4 Rhythmbox The next icon on the Dock is the Rhythmbox icon which will launch the Rhythmbox music player, Figure 3-6.

Figure 3-6. Rhythmbox music player

3.1.1.5 LibreOffice Writer The next icon on the Dock is the LibreOffice Writer icon which will launch the LibreOffice Writer word processing program, Figure 3-7.

Figure 3-7. LibreOffice Writer

3.1.1.6 Ubuntu Software The next icon on the Dock is the Ubuntu Software application icon. The Ubuntu Software application allows you to install software, view installed software, remove software, and install updates. Software is grouped into categories or can be located by using the search function located at the top of the Ubuntu Software application window, Figure 3-8.

Figure 3-8. Ubuntu Software application

The Ubuntu Software application will be covered in more detail in Chapter

8. 3.1.1.7 Help The next icon on the Dock is the Help icon. Clicking the Help icon will bring up the Ubuntu Desktop Guide, Figure 3-9, which is a hyperlinked guide to the Ubuntu Desktop.

Figure 3-9. Ubuntu Desktop Guide

3.1.1.6 Amazon The next icon in the Launcher is the Amazon icon. The Amazon icon will open a web browser and take you directly to the Amazon.com website. 3.1.2 Activities In the top left hand corner of the Desktop you will find the Activities link. When you click on Activities the Desktop will show all currently open applications in small windows and the current workspaces on the left hand side of the Desktop, Figure 3-10. Workspaces will be covered later in this chapter.

Figure 3-10. The Ubuntu Desktop - Activities

When you select an application in the Activities Desktop it will be highlighted, Figure 3-11. You can close the application by clicking the X in the upper right hand corner, or bring the focus to the application by clicking on the application.

Figure 3-11. The Ubuntu Desktop - Activities - Selected Application

3.1.3 Searching for Applications In the center of the Activities Desktop is a search box that will let you search for any application installed on your Ubuntu system, Figure 3-12.

Figure 3-12. Search

You can also bring up the search box by pressing, not holding, the Super key which is also known as the Windows key. Typing Firefox in the search box will bring up the Firefox application which can then be launched by clicking on the Firefox icon, Figure 3-13.

Figure 3-13. Searching for Firefox Application

3.1.4 The Upper Right Hand Corner In the upper right hand corner of the desktop you will find several system status icons. The icons that are displayed will depend upon your system and the type of hardware installed. In Figure 3-14 the Wired Network icon, the Volume Status icon, and the Battery Status icon are displayed. Figure 3-15 shows the same menu with a wireless network connection. Clicking on any icon or the down arrow all the way to the right will bring up a drop down menu.

Figure 3-14. Upper Right Hand Corner - Wired network

Figure 3-15. Upper Right Hand Corner - Wireless network

The following subsections are covered in this section:

3.1.4.1 Volume Slider 3.1.4.2 Brightness Slider 3.1.4.3 Network Menu 3.1.4.4 Bluetooth Menu 3.1.4.5 Battery Menu 3.1.4.6 User Menu 3.1.4.7 Settings Button 3.1.4.8 Lock Button 3.1.4.9 Power Button 3.1.4.1 Volume Slider The Volume Slider allows you to control the system volume. You can either click and hold on the slider to move it back and forth or click on the location on the slider where you want to set the volume. 3.1.4.2 Brightness Slider The Brightness Slider allows you to control the screen brightness. You can either click and hold on the slider to move it back and forth or click on the location on the slider where you want to set the brightness. 3.1.4.3 Network Menu The next menu item is either Wired or Wireless depending upon what your system is using. Figure 3-16 shows the menu with a wired connection. Clicking the down arrow to the right will expand the menu. The additional options will allow you to turn the network on or off, and access the network settings. Network Settings will be covered in more detail in Chapter 7.

Figure 3-16. Wired Network

3.1.4.4 Bluetooth Menu If your system is equipped with Bluetooth, the next menu item will be the Bluetooth represented by the Bluetooth icon, Figure 3-17. From the Bluetooth drop down menu you can turn Bluetooth on and off and access the Bluetooth settings. Bluetooth settings will be covered in more detail in Chapter 6.

Figure 3-17. VPN

3.1.4.5 Battery Menu If your system is a laptop with a battery, the next menu item will be the Battery Status, Figure 3-18. The Battery Status drop down menu allows you to show the amount of time left on the battery and the battery percentage in the menu bar as well as access the Power Settings which will be covered in more detail in Chapter 6.

Figure 3-18. Battery

3.1.4.6 User Menu The next menu item is the current user, Figure 3-19. The User item has two options if there is only one user account on the system, Log Out and Account Settings.

Figure 3-19. User - One user

If there is more than one user account on the system the Switch User menu option will be available, Figure 3-20. Selecting Switch User will take you back to the main logon screen.

Figure 3-20. User - Multiple users

Selecting Log Out will open the Log Out window, Figure 3-21. You will have 60 seconds to choose Cancel or Log Out. After 60 seconds you will be logged out of the system.

Figure 3-21. Log Out

Selecting Account Settings will take you to the Users settings, Figure 3-22, which will be covered in Chapter 6.

Figure 3-22. Users

3.1.4.7 Settings Button At the bottom of the menu are three icons, Figure 3-23.

Figure 3-23. Menu icons

The first icon from the left to right is the System Settings icon. Clicking the System Settings icon will bring up the System Settings window, Figure 324. System Settings will be covered in Chapter 6.

Figure 3-24. System Settings

3.1.4.8 Lock Button The middle icon is the Lock icon, Figure 3-25. Clicking on the Lock icon will immediately lock the system without any confirmation.

Figure 3-25. Lock

All open programs and windows will remain in the background. To unlock the screen swipe up on the lock screen with your mouse or trackpad and enter your password. 3.1.4.9 Power Button The Power icon is the leftmost icon, Figure 3-25.

Figure 3-25. Power

Clicking the Power icon will bring up the Power Off window, Figure 3-26. You will be given the option to Cancel, Restart, or Power Off the system. If updates are available for your system you can install the updates before powering off by clicking the Install pending software updates checkbox Install pending software updates

Figure 3-26. Power Off

3.1.5 Trash Next to the Dock on the Desktop is the Trash icon, Figure 3-27. Files that are deleted via the File Manager are sent to the trash where the files can be retrieved later until the Trash is emptied.

Figure 3-27. Trash

When there are items in the Trash, there will be virtual paper in the trash can icon, Figure 3-28.

Figure 3-28. Full Trash

Clicking the Trash icon will bring up the Trash in a File Manager window, Figure 3-29.

Figure 3-29. File Manager - Trash

In the Trash File Manager window you will have the option to restore a file or folder to the original location by selecting the file or folder and clicking the Restore button in the upper right hand corner. You can empty the Trash by clicking on the Empty button in the upper right hand corner. Once you perform this action the files and folders will no longer be recoverable without using special tools. You can also empty the Trash by right clicking on the Trash icon and selecting Empty Trash. 3.1.6 Applications The Show Applications icon is located in the bottom left hand corner of the desktop, Figure 3-30.

Figure 3-31. Show Applications

Clicking on the Show Applications icon will bring up the Applications window, Figure 3-32.

Figure 3-32. Show Applications - Frequently used applications

At the bottom of the Applications windows you can switch to frequently used application by clicking Frequent or all applications by clicking All. The Applications window will list most of the applications on your system but not all. If there is more than one page of applications, there will be dots on the right hand side of the window that will let you choose the page to view by clicking on the dots. Right clicking on an application will bring up an application menu, Figure 333. Selecting New Window will start a new instance of the application. Selecting Add to Favorites will add the application to the Dock which will make the application easier to start. I normally put my most used applications on the Dock. Selecting Show Details will show information about the application.

Figure 3-33. Show Applications - Right click

3.1.7 Open Windows When an application is open there will be a dot next to the application on the Dock, Figure 3-34.

Figure 3-34. Open Window

When multiple instances of the same application are open there will be a multiple dots next to the application on the Dock, Figure 3-35.

Figure 3-35. Open Windows

When multiple instances of the same application are open clicking on the application on the Dock which will bring up a thumbnail version of each instance, Figure 3-36. Clicking on the X in the upper right hand corner of an instance will close that instance.

Figure 3-36. Multiple application instances

3.1.8 Calendar The Ubuntu Desktop includes a Calendar which can be accessed by clicking the day and time in the top middle of the desktop, Figure 3-37. The left side of the Calendar will display alerts and the right side will display the current month. The current day will be designated by a circle over the day. You can change the displayed month by using the arrows to the left and right of the month.

Figure 3-37. Desktop Calendar

Choosing a day other than the current day will display the day and date on the left hand side, Figure 3-38.

Figure 3-38. Desktop Calendar - Events

The following subsections are covered in this section: 3.1.8.1 Calendar Edit 3.1.8.2 Add Event

3.1.8.2 Edit Details 3.1.8.3 Delete Event 3.1.8.4 Week View 3.1.8.5 Month View 3.1.8.6 Year View 3.1.8.7 Search 3.1.8.8 Calendar Settings 3.1.8.1 Calendar Edit Clicking on the day at the top of the left side of the window will bring up an editable calendar, Figure 3-39. You can also access the calendar by clikcing on Activities in the upper left hand corner of the desktop and searching for the Calendar application. By default the calendar will be in the Month view.

Figure 3-39. Desktop Calendar - Week

3.1.8.2 Add Event

You can add an event to the calendar by clicking on any day in the calendar, Figure 3-40.

Figure 3-40. Desktop Calendar - Week - New Event

You will have to provide an event name. You can add the event with minimal details by clicking Add and the new event will appear on the calendar, Figure 3-41.

Figure 3-41. Desktop Calendar - Week - New Event

You can also edit the event details before adding the event by clicking Edit Details. 3.1.8.2 Edit Details Once the event has been added to the calendar you can edit the event by clicking on the event. The Edit Details window allows you to edit additional options for the event, Figure 3-42.

Figure 3-42. Desktop Calendar - Week - New Event - Edit details

You can select a start and end date, Figure 3-43.

Figure 3-43. Desktop Calendar - Week - New Event - Edit details - Date

You can select a start and end time, Figure 3-44.

Figure 3-44. Desktop Calendar - Week - New Event - Edit details - Time

If the event is an all day event you can select All Day. The Repeat option allows you to create a recurring event, Figure 3-45.

Figure 3-45. Desktop Calendar - Week - New Event - Edit details - Repeat

The Reminder option allows you to choose how much in advance of the event to receive a reminder, Figure 3-46.

Figure 3-46. Desktop Calendar - Week - New Event - Edit details - Reminder

The Location and Notes are manual options that let your enter whatever information you want. 3.1.8.3 Delete Event If you are editing an event that was already on the calendar, a Delete Event button will be in the bottom left hand corner. 3.1.8.4 Week View Clicking on the Week tab at the top of the calendar will show the Week view, Figure 3-47.

Figure 3-47. Desktop Calendar - Week

3.1.8.5 Month View Clicking on the Month tab at the top of the calendar will show the Month view, Figure 3-48.

Figure 3-48. Desktop Calendar - Month

3.1.8.6 Year View Clicking on the Year tab at the top of the calendar will show the Year view, Figure 3-49.

Figure 3-49. Desktop Calendar - Year

3.1.8.7 Search Clicking on the magnifying glass icon at the top of the window will bring up the search function, Figure 3-50. You can search for a specific event using keywords.

Figure 3-50. Desktop Calendar - Search

3.1.8.8 Calendar Settings Clicking the Calendar icon will bring up the Calendar Settings menu, Figure 3-51.

Figure 3-51. Desktop Calendar - Settings

The current calendars will be listed and can be enabled or disabled. Clicking on the Calendar Settings will bring up the Calendar Settings window, Figure 3-52.

Figure 3-52. Desktop Calendar - Settings

The Online Accounts option will let you configure your calendar to sync with an online calendar. Clicking on the gear icon to the right will take you to the Online Account settings. The Calendars option will allow you to add additional calendars, Figure 353.

Figure 3-53. Desktop Calendar - Settings - Calendars - Add

You can add a calendar from the web, create a local calendar, or add a calendar from a file. 3.1.8.9 Menus

The Calendar application has two menus. The first menu is on the top of the Calendar window, Figure 3-54. From this menu you can Synchronize with an online account if you have configured an online account and add the Weather to the calendar.

Figure 3-54. Desktop Calendar - Add Event

If you select the Weather option, you will be taken to the Weather menu, Figure 3-55. You can turn Show Weather on and off and turn Automatic Location on and off.

Figure 3-55. Desktop Calendar - Weather

If you turn off Automatic Location, you will have to select the location manually, Figure 3-56.

Figure 3-56. Desktop Calendar - Weather - Manual Location

The second menu will be in the top left hand corner of the desktop when the Calendar application is active, Figure 3-57.

Figure 3-57. Desktop Calendar - Calendar Menu

From this menu you can access the Calendars settings, view the Keyboard Shortcuts, Figure 3-58, view the About information, and Quit the application.

Figure 3-58. Desktop Calendar - Shortcuts

3.1.9 Workspaces Workspaces are like virtual desktops. When you enable Workspaces you can have different applications open in different workspaces and switch between the workspaces. Once enabled the Workspaces will appear in the Activities on the left hand side of the desktop, Figure 3-59.

Figure 3-59. Workspaces icon in Activities

Clicking on any of the workspaces will make that workspace the current workspace. When you switch from one workspace to another, applications active in one workspace will stay active on that workspace and the new workspace will only show the applications active in that workspace. Workspaces are a great way to have multiple applications running without cluttering up a single desktop.

4. UPDATING AND SECURING UBUNTU

4. Updating and Securing Ubuntu Now that you have your Ubuntu system installed and you had a little tour of the desktop it is time to get serious. You need to update your system with the latest patches and software updates and enable the host based firewall. The following sections are covered in this chapter: 4.1 Software Updater 4.2 apt-get 4.3 Firewall

4.1 Software Updater Ubuntu comes with a very easy to use software update system that will update all installed software provided it was installed with the Ubuntu Software Center or via apt-get, which is a command line tool to update your Ubuntu system. To update an Ubuntu system you can use the Software Updater. To access the Software Updater click on Activities in the upper left hand corner of the desktop to bring up the search function and type Software Updater, Figure 4-1. To launch the Software Updater just click on the icon.

Figure 4-1. Searching for the Software Updater

Updating software is a multi part process. First the Software Updater has to

update the software sources, Figure 4-2. The software sources contain a list of all the current available software, the latest versions numbers, and where it is located on the Internet. Once the Software Updater has updated the software sources, it compares the currently installed versions of software against the current version list and recommends upgrading any installed software package that has a newer version.

Figure 4-2. Checking for updates

The Software Updater will tell you if new updates are available, Figure 4-3.

Figure 4-3. Software Updater - Updates Available

If you click the Settings button you will be taken to the Software & Updates settings window, Figure 4-4. Software & Updates settings will be covered in more detail in Chapter 6. To install the updates click Install Now.

Figure 4-4. Software Updater - Updates Settings

If you choose to install the updates you may have to provide your password for authentication, Figure 4-5. During the Ubuntu installation, the user account you created was given special privileges that allow your user account to use root level privileges (administrator in Linux speak) by supplying your password.

Figure 4-5. Software Updater - Authentication

Once you authenticate, the update will start. Depending upon the number of updates required, this could take a little while to complete. Make sure not to turn off your system during the update process as it can cause problems with your system. Some updates may require a system restart to take effect. If this is the case, a dialog box at the end of the updates will ask you if you want

to restart now or later, Figure 4-6.

Figure 4-6. Software Updater Restart

You should update your Ubuntu system frequently. I update my system every time I use it which is daily.

4.2 apt Ubuntu can also be updated using the apt command which is used to update and install software from the Command Line Interface (CLI). You can access the CLI by pressing Ctrl+Alt+T or searching for the terminal application. Use of the CLI is covered in more detail in Chapter 11. The apt command is my prefered method for updating my system and installing software. The following subsections are covered in this section: 4.2.1 apt update 4.2.2 apt upgrade 4.2.2 apt dist-upgrade 4.2.3 Autoremove 4.2.1 apt update The apt command with the update option will refresh all of the sources and look for any new software for your system. Figure 4-7 shows the use of the apt update command. Notice in Figure 4-7 that the sudo command is used and a password is required. As with the Software Updater, when using the apt command you have to authenticate to update your system. When you are working in the Linux command line the sudo command will give you the permissions needed to run administrative commands like apt. The sudo command is covered in Chapter 13.

Figure 4-7. apt update

4.2.2 apt upgrade Once the software sources have been updated, you can use the apt command with the upgrade option to install any updates. The apt upgrade command will only update software installed via the package management system, either the GUI version or apt from the command line. Figure 4-8 shows the use of the apt command with the upgrade option. Before software is updated you may have to press y to agree to continue.

Figure 4-8. apt upgrade

4.2.2 apt dist-upgrade The apt command with the dist-upgrade option will update software

dependencies along with new versions of packages. Sometimes the apt upgrade command will not be able to update all software, however the distupgrade option can. Figure 4-9 shows the use of the apt command with the dist-upgrade option. Before software is updated you will may have to press y to agree to continue.

Figure 4-9. apt-get dist-upgrade

4.2.3 Autoremove The apt command with the autoremove option will remove older kernel versions and free up disk space.

4.3 Firewall A host based firewall is a firewall that is configured on a system to protect only the system that it is installed on. A network based firewall, in contrast, is normally placed at the edge of a network and is used to protect an entire network. So if you already have a network based firewall why do you need a host based firewall? The reason is to prevent lateral movement in a network should a compromise of another system occur. A host based firewall can also help you protect against insider threat which is someone on your network attempting to compromise your system. Ubuntu comes with a host based firewall, Uncomplicated Firewall (ufw), that is not enabled by default. You should enable the host based firewall as soon as possible after installing Ubuntu. To view the status and enable the firewall you can use the ufw command. In the example below the ufw command is used to view the status of the firewall, which is inactive, enable the firewall, and then view the status once again.

The default configuration is to deny incoming connections, allow outgoing connections, and disable routing. The default configuration is good for most users.

5. FILE MANAGER

5. File Manager In most operating systems with a graphical user interface (GUI), there is a file manager that can be used to access files and directories, Linux is no different. ●

Note: In Linux, directories are also known as folders. The words directory and folder will be used synonymously in this book.

Figure 5-1 shows the Ubuntu File Manager called Files. The File Manager is used to access files and directories on your Linux system.

Figure 5-1. File Manager

The File Manager window shows the location of files on the left hand side of the window and the actual files in the selected location on the right hand side of the window. The default location when the File Manager is launched is the current user's home directory. The File Manager works much like file managers in most other operating systems.

5.1 Grid and List Views

The default view of the File Manager is the Grid View which shows files and folders in columns and rows, Figure 5-1. You can also switch to List View which will allow you to sort by the file name, file size, or date modified, Figure 5-2.

Figure 5-2. File Manager - List View

To switch between Grid and List view, click on the Grid or List icon, the middle icon in the top right hand corner of the window. As you switch between Grid and List views the middle icon will change. Figure 5-3 shows the Grid View icon and Figure 5-4 shows the List View icon.

Figure 5-3. File Manager - Grid View icon

Figure 5-4. File Manager - List View icon

5.2 Search You can search function of the File Manager to search for a specific file or directory. Clicking on the magnifying glass in the upper right hand corner brings up a search box near the top of the window, Figure 5-5. Typing Desktop in the search box will find any files or directories with Desktop in the name. The search location is the location that was selected in the left pane before the search started. If the Home directory was selected only the Home directory is searched.

Figure 5-5. File Manager - Search

To search the entire file system you have to select Other Locations in the lower left pane, select Computer at the top of the middle pane, and then perform the search, Figure 5-6.

Figure 5-6. File Manager - Search Computer

You can also select date ranges and what to search for, Figure 5-7, by clicking the down arrow on the right hand side of the search box.

Figure 5-7. File Manager - When and What

The following subsections are covered in this section. 5.2.1 When 5.2.2 What 5.2.1 When Clicking on Select Dates will bring up the When settings, Figure 5-8, which allows you to choose a preset time. You can also choose to search for files based upon when the file was Last Modified or Last Used by using the radio buttons at the bottom of the window. Selecting Full Text will search the text inside for a match the file and selecting File Name will search for a filename match only.

Figure 5-8. File Manager - When

Clicking on the calendar icon will switch to a calendar, Figure 5-9, which will allow you to choose a date.

Figure 5-9. File Manager - Calendar

5.2.2 What Clicking on Anything under What will bring up a list of things to search for, Figure 5-10.

Figure 5-10. File Manager - What

Selecting Other Type at the bottom of the list will bring up a more extensive list of file types to search for, Figure 5-11.

Figure 5-11. File Manager - Select type

5.3 File Manager Menu On the right hand side of the File Manager window there are two File Manager Menu icons, Figure 5-12. The icon on the right has three vertical lines and the icon in the right has a triangle pointing down.

Figure 5-12. File Manager - Menu icons

Clicking on the File Manager Menu icon on the right will bring up the File Manager drop down menu shown in Figure 5-13.

Figure 5-13. File Manager -Right Dropdown Menu

The menu for the File Manager icon on the left will be different for Grid and List views. Figure 5-14 shows the menu when the File Manager is in Grid View and Figure 5-15 shows the menu when the File Manager is in List View.

Figure 5-14. File Manager - Left Dropdown Menu - Grid View

Figure 5-15. File Manager - Left Dropdown Menu - List View

5.3.1 Right File Manager Menu Clicking on the File Manager Menu icon on the right will bring up the File Manager drop down menu shown in Figure 5-16.

Figure 5-16. File Manager - Right File Manager Menu

5.3.1.1 New File Manager Window The New File Manager icon, Figure 5-17, allows you to open a new File Manager window.

Figure 5-17. File Manager - New Folder Icon

5.3.1.2 New Tab The New Tab icon, Figure 5-18, will open a new File Manager tab in the current File Manager window. You can also open a new File Manager tab by pressing Ctrl+T when a File Manager window is already open and has focus.

Figure 5-18. File Manager - New Tab Icon

You can switch between tabs by clicking on the tabs at the top of the File Manager window. You can open multiple tabs, Figure 5-19. Each new tab will open on the right hand side of the File Manager window and will open in the same location of the last tab on the right. Each tab can be focused on a different location in the filesystem and files and folders can be easily copied and pasted between tabs.

Figure 5-19. File Manager - 3 tabs

Tabs can be rearranged by clicking and holding a tab then dragging it to the new position. Tabs can be closed by clicking the X in the right hand corner of the tab, Figure 5-20.

Figure 5-20. File Manager - Close tab

5.3.1.3 New Folder The New Folder icon, Figure 5-21, allows you to create a new folder in the current location.

Figure 5-21. File Manager - New Folder Icon

You will have to provide a folder name and click Create, Figure 5-22. When creating a folder name or filename in Linux you can use spaces and certain special characters in the name, however, it is not recommended. You can also create a new folder by pressing Shift+Ctrl+N when the File Manager window is open and has focus.

Figure 5-22. File Manager - New Folder

5.3.1.5 Edit The Edit section, Figure 5-23, allows you to Cut, Copy, and Paste files and folders via the File Manager.

Figure 5-23. File Manager - Edit

5.3.1.6 Select All Select All selects all visible files and folders in the current directory. Once selected, you can perform actions on the files and folders such as Cut, Copy, and Paste. 5.3.1.7 Show Hidden Files

In the Linux file system, hidden files are files with a filename that starts with a . character. Normally hidden files are not visible. To show hidden files in the File Manager, select Show Hidden Files, Figure 5-24.

Figure 5-24. File Manager - Show Hidden Files

Once selected, hidden files will be visible, Figure 5-25.

Figure 5-25. File Manager - Show Hidden Files

5.3.1.8 Sidebar The next option, Sidebar, will turn the sidebar on and off. The Sidebar is located on the left of the File Manager window and shows the various locations in the file system, Figure 5-26. By default the Sidebar is visible.

Figure 5-26. File Manager - Files menu - Sidebar

Figure 5-27 shows the File Manager with the sidebar turned off.

Figure 5-27. File Manager - Files menu - No Sidebar

5.3.1.9 Preferences The Preferences option allows you to control the way that the File Manager looks and behaves. The Preferences window has four tabs, Figure 5-28: 5.3.1.9.1 Views 5.3.1.9.2 Behavior 5.3.1.9.3 List Columns 5.3.1.9.4 Search & Preview

Figure 5-28. File Manager - Files menu - Preferences

5.3.1.9.1 Views The Views tab, Figure 5-28, controls the different views of the File Manager. The Views tab is has four sections: 5.3.1.9.1.1 General 5.3.1.9.1.2 Sort 5.3.1.9.1.3 List View 5.3.1.9.1.4 Icon View Captions 5.3.1.9.1.1 General The General section allows you to turn the File Manager Sidebar on and

off. The Sidebar is located on the left of the File Manager window and shows the various locations in the file system, Figure 5-29. By default the Sidebar is visible.

Figure 5-29. File Manager - Files menu - Sidebar

Figure 5-30 shows the File Manager with the sidebar turned off.

Figure 5-30. File Manager - Files menu - No Sidebar

5.3.1.9.1.2 Sort The Sort folders before files option allows you to control how files and folders are sorted in the File Manager window. The default is for this option to be checked and means that folders are sorted in order first and then the files. 5.3.1.9.1.3 List View The Allowed folders to be expanded option allows you to control how files and folders are displayed in the File Manager window in List View. The default is for this option to not be checked. When this option is checked, each folder in List View will have a triangle to the left of the folder name. Clicking on the triangle will expand the folder and show all of the files and folders in the parent folder, Figure 5-31.

Figure 5-31. File Manager - Files menu - Expanded folder

5.3.1.9.1.4 Icon View Captions The Icon View Captions options allows you to control what is displayed under the filenames in Icon View. There are three positions that can be configured by clicking the triangles to the right of each position, Figure 5-32.

Figure 5-32. File Manager - Files menu - Preferences - Icon View Captions

For each position there are multiple options, Figure 5-33.

Figure 5-33. File Manager - Files menu - Preferences - Icon View Captions

When in Icon View the captions can be seen under the filenames and all captions will be visible when the view is zoomed in, Figure 5-34.

Figure 5-34. File Manager - Icon View Captions

5.3.1.9.2 Behavior The Behavior tab, Figure 5-35, controls the behavior of files in the File

Manager.

Figure 5-35. File Manager - Files menu - Preferences - Behavior

The Behavior tab is has four sections: 5.3.1.9.2.1 Open Action 5.3.1.9.2.2 Link Creation 5.3.1.9.2.3 Executable Text Files 5.3.1.9.2.4 Trash 5.3.1.9.2.1 Open Action The Open Action option allows you to choose between a single and a double click to open items such as files or folders. The default is a double click.

5.3.1.9.2.2 Link Creation The Link Creation option allows you to create a link for files or folders and adds an option to the right click menu, Figure 5-36. You also can perform the Create Link by pressing Shift+Ctrl+M when a file or folder is highlighted.

Figure 5-36. File Manager - Create Link

Figure 5-37 shows the link after it has been created. The link or shortcut can be moved anywhere in the file system and it will still refer back to the original file or directory.

Figure 5-37. File Manager - Link

5.3.1.9.2.3 Executable Text Files The Executable Text Files option allows you to choose how to treat text files that are marked as executable. The default option is to Display Them. You can also choose to Run Them as executable files or Ask what to do. You should be very careful selecting the option to Run Them as executable text files as this presents a security risk. 5.3.1.9.2.4 Trash The Trash option allows you to choose how files are handled when moving them to the Trash. The default is to Ask before emptying the Trash. You can also choose to Show action to permanently delete files and folders which will add a Delete Permanently option to any menu with a Move to Trash option, Figure 5-38.

Figure 5-38. File Manager - Delete Permanently

You also can perform the Delete Permanently function that bypasses the trash at any time by pressing Shift+Delete when a file or folder is highlighted. 5.3.1.9.3 List Columns The List Columns tab, Figure 5-39, controls the columns and the order of the columns in the List View of the File Manager.

Figure 5-39. File Manager - List Columns

All of the column options can be selected or deselected except for the Name column option. You can also reset the List Columns to default by clicking the Reset to Default button in the bottom right hand corner. 5.3.1.9.4 Search & Preview The Search & Preview tab, Figure 5-40, controls the way that files and folders are searched for, how thumbnails are displayed, and controls the file and folder count in the File Manager window. The Search & Preview tab has three sections: 5.3.1.9.4.1 Search 5.3.1.9.4.2 Thumbnails 5.3.1.9.4.3 File Count

Figure 5-40. File Manager - Preferences

5.3.1.9.4.1 Search The search section has two subsections: 5.3.1.9.4.1.1 Search in subfolders 5.3.1.9.4.1.2 Full text search 5.3.1.9.4.1.1 Search in subfolders The Search in subfolders option allows you to control how subfolder are searched. The default is All locations which will enable searching of subfolders in network folders as well as the local filesystem. You can choose On this computer only which means that network folders from other

systems will not be searched. You can also choose Never which disables subfolder searching in any folder. 5.3.1.9.4.1.2 Full text search The Full text search subsection only has one option, Set as default, which allows for searches via the File Manager search function to be conducted on the full text of a file. 5.3.1.9.4.2 Thumbnails The Thumbnails section allows you to configure the use of thumbnails which are small pictures that show a representation of a file or in the case of image files, the actual image. You can choose to show thumbnails for Files on this computer only, All files, or Never. You can also control the size of files that show thumbnails. The default is files smaller than 10 MB. 5.3.1.9.4.3 File Count The File Count section allows you to configure how items in the folder are counted. You can choose to count files only in Folders on this computer only, All folders, or Never. 5.3.1.10 Keyboard Shortcuts The Keyboard Shortcuts option will show you two pages of shortcuts that can be used in the File Manager window, Figures 5-41, 5-42 and 5-43.

Figure 5-41. File Manager - Shortcuts page 1

Figure 5-42. File Manager - Shortcuts page 2

Figure 5-43. File Manager - Shortcuts page 3

5.3.1.11 Help The Help option will open a help browser open to the Ubuntu Desktop Guide, Figure 5-44, which is a web page with hyperlinks that gives you access to all of the Ubuntu help topics. You can also access Help by pressing F1.

Figure 5-44. File Manager - Help

5.3.1.12 About Selecting About will open a window with information about Files, the name of the File Manager program, such a version number and copyright information, Figure 5-45.

Figure 5-45. File Manager - About

5.3.2 Left File Manager Menu On the right hand side of the File Manager window there are two File Manager Menu icons, Figure 5-46. The icon on the right has three vertical lines and the icon in the right has a triangle pointing down.

Figure 5-46. File Manager - Menu icons

Clicking on the File Manager Menu icon on the left will bring up one of two File Manager drop down menus depending on current view selected, Grid View or List View. 5.3.2.1 Grid View Menu 5.3.2.2 List View Menu 5.3.2.1 Grid View Menu When in Grid View the left File Manager Menu will have the following options, Figure 5-47: 5.3.2.1.1 Zoom 5.3.2.1.2 Undo 5.3.2.1.3 Redo 5.3.2.1.4 Sort 5.3.2.1.5 Reload

Figure 5-47. File Manager - Menu icons

5.3.2.1.1 Zoom The Zoom controls, Figure 5-48, allow you to increase and decrease the size of the directory and file icons in Grid view.. The current value will be displayed in the middle.

Figure 5-48. Zoom Controls

5.3.2.1.2 Undo The Undo option will undo the last action taken. Figure 5-49 shows Undo Rename which means that the last action taken was to Rename a file or folder. You can also Undo the previous action by pressing Ctrl+Z when a File Manager window is already open and has focus.

Figure 5-49. File Manager Menu - Undo

5.3.2.1.3 Redo The Redo option will undo the last Undo action taken. Figure 5-50 shows Redo Trash which means that the last action was to Undo a move to the Trash of a file or folder. Clicking Redo Trash will put the file or folder back in the Trash. You can also Redo the previous action by pressing Shift+Ctrl+Z when a File Manager window is already open and has focus.

Figure 5-50. File Manager Menu - Redo

5.3.2.1.4 Sort In the Sort section there are six sort options to choose from, Figure 5-51.

Figure 5-51. File Manager Menu - Sort

5.3.2.1.4.1 A-Z 5.3.2.1.4.2 Z-A 5.3.2.1.4.3 Last Modified 5.3.2.1.4.4 First Modified 5.3.2.1.4.5 Size 5.3.2.1.4.6 Type 5.3.2.1.4.1 A-Z A-Z sorts alphabetically from A-Z. Number are sorted first from 0-9 then lower case letters letters followed by uppercase letters. Figure 5-52 shows several files sorted A-Z.

Figure 5-52. File Manager Menu - Sort - A-Z

5.3.2.1.4.2 Z-A Z-A sorts alphabetically from Z-A. Lower case letters letters are sorted first followed by uppercase then the numbers all in reverse order. Figure 5-53 shows several files sorted Z-A.

Figure 5-53. File Manager Menu - Sort - Z-A

5.3.2.1.4.3 Last Modified Last Modified sorts the files based on the date and time that the file was last modified with the newest date being first from left to right. 5.3.2.1.4.4 First Modified First Modified sorts the files based on the date and time that the file was first modified with the oldest date being first left to right. 5.3.2.1.4.5 Size Size sorts the files based on the size of the file with the largest file being first left to right. 5.3.2.1.4.6 Type Type sorts the files based on the type of the file with file types being grouped together. Within the groups the files are sorted alphabetically. 5.3.2.1.5 Reload Reload will reload and update any changes in the File Manager. 5.3.2.2 List View Menu When in List View the File Manager Menu will have Visible Columns instead of sorting options, Figure 5-54.

Figure 5-54. File Manager - Drop down menu - List View

Selecting Visible Columns will bring up the Visible Columns window, Figure 5-55, which allows you to select which columns are displayed in List View.

Figure 5-55. File Manager - List View menu - Visible Columns

5.4 Navigation

If you click on a directory in the left pane of the File Manager window, the File Manager will display the selected directory in the right pane of the window and the parent or higher level directories at the top of the window in small boxes. You can click on any of the directories listed at the top of the window in the boxes or you can use the back and forward buttons in the upper left hand corner to navigate through the file structure. Figure 5-56 shows the MyNewFolder directory. Since the MyNewFolder directory is located in the Documents directory in Home directory both the Home and Documents directory are displayed at the top of the File Manager window in the boxes to the left of the MyNewFolder directory.

Figure 5-56. File Manager - Documents

5.5 Right Click - Empty Space Right clicking on any empty space in the right pane of the File Manager window will bring up a floating menu, Figure 5-57, that has the following options: 5.5.1 New Folder 5.5.2 Paste 5.5.3 Select All 5.5.4 Properties

5.5.5 Restore Missing Files 5.5.6 Open in Terminal

Figure 5-57. File Manager - Right Click

Whatever directory is the current location has focus in the File Manager so all of the actions in the menu will take effect in the current directory. Starting with Ubuntu 18.04, the default behavior of a touchpad is to use both buttons as a left click and to use a two finger tap on the touchpad as a right click. You can change this behavior by running the following command from the command line: gsettings set org.gnome.desktop.peripherals.touchpad click-method areas 5.5.1 New Folder The New Folder option allows you to create a new folder in the current location. You will have to provide a folder name and click Create, Figure 558. When creating a folder name or filename in Linux you can use spaces and certain special characters in the folder name, however, it is not recommended. It is best to stick to letters, numbers, and the characters - and _. You can also create a new folder by pressing Shift+Ctrl+N when the File Manager window is open and has focus.

Figure 5-58. File Manager - Untitled Folder

5.5.2 Paste The Paste option will only be available if you have performed a cut or copy action first. Selecting Paste will allow you to paste a cut or copied file or folder into the current directory. You can also perform a paste operation by pressing Ctrl+V when the File Manager window is open and has focus. 5.5.3 Select All The Select All option will allow you to select all files and folders in the current File Manager window. Once selected, all of the files and folders will be highlighted. You can then perform an operation on all of the files and folders at the same time such as Cut, Copy, Move to Trash, Compress, etc. You can also perform a Select All operation by pressing Ctrl+A when the File Manager window is open and has focus. 5.5.4 Properties The Properties option shows the properties for the current directory or folder. The directory properties dialog box has three tabs, Figure 5-59: 5.5.4.1 Basic Tab 5.5.4.2 Permissions Tab 5.5.4.3 Local Network Share Tab

Figure 5-59. File Manager - Properties

5.5.4.1 Basic Tab The Basic tab, Figure 5-59, shows the name of the directory, the type, the contents, the location of the directory or parent folder, and the free space of the drive that the directory is located on. The name of the directory can also be changed from the Basic tab. 5.5.4.2 Permissions Tab The Permissions tab, Figure 5-60, shows the various permissions for the current directory.

Figure 5-60. File Manager - Permissions

The permission are broken down into Owner, Group, and Others with each having their own permissions. File and directory permissions are covered in more detail in Chapter 12. The first set of permissions belong to the Owner of the directory which in Figure 5-60 is Me, which means the current user, and from here cannot be changed. Below the Owner label is the access permissions for the owner which by default is Create and delete files. You can change the permissions by clicking the down arrow to the right of the access permissions. The access permission options for the Owner are the following: List files only Access files Create and delete files The second set of permissions belong to the Group. By default the Group is set to the current user’s primary group when a directory is created. The user’s primary group name is normally the same as the user’s username but

do not get them confused. Even though the user and group have the same name they are different objects in the system. You can change the file’s Group assignment by clicking the down arrow to the right of the group name. You can change the group permissions by clicking the down arrow to the right of the access permissions for the Group. The access permission options for the Group are the following: None List files only Access files Create and delete files The third set of permissions belong to Others, which is the same as Everyone in other operating systems. You can change the permissions by clicking the down arrow to the right of the access permissions for Others. The access permission options for Others are the following: None List files only Access files Create and delete files At the bottom of the window is a button, Change Permissions for Enclosed Files, that will allow you to copy the permissions from the current directory to all of the files and folders in the directory. The Change Permissions for Enclosed Files window, Figure 5-61, allows you to change the permissions for both files and folders in the current directory. There are permissions for the Owner, Group, and Others.

Figure 5-61. File Manager - Permissions - Change Permissions for Enclosed Files

The file permission options for the Owner are Read-only and Read and write. The file permission options for the Group and Others are None, Read-only, and Read and write. The folder permission options for the Owner are List files only, Access files, and Create and delete files. The folder permission options for the Group and Others are None, List files only, Access files, and Create and delete files. File and directory permissions will be covered in more detail in Chapter 12. 5.5.4.3 Local Network Share Tab Ubuntu makes the sharing of directories over the network very easy. The Local Network Share tab, Figure 5-62, contains all of the configuration options necessary to share a directory or folder. The first step to sharing a directory is to click the Share This Folder checkbox.

Figure 5-62. File Manager - Properties - Local Network Share

If this is the first time you have shared a folder you will be asked to install the sharing service also known as Samba, Figure 5-63.

Figure 5-63. File Manager - Properties - Local Network Share - Install sharing service

Click Install to install the Samba software package, Figure 5-64. You will be asked to authenticate with your password.

Figure 5-64. File Manager - Properties - Local Network Share - Install sharing service - Samba

Once the install is complete, the Share name and Comment fields, which were greyed out, will become active. You will have to provide the Share name in order to share the folder but the Comment section can be left blank. If you want users to be able to create and delete files and folders in the share you must check the Allow others to create and delete files in this folder checkbox. You can also enable Guest access, however, for security reasons this is not recommended as this means that anyone can access the share. Click the Create Share button to create the share. With Samba shares enabled other operating systems can connect to the share over the network, however, before users can access Samba shares they have to have a Samba password configured. Samba configuration will be covered in more detail in Chapter 23. 5.5.5 Restore Missing Files The Restore Missing Files option allows you restore files from a backup to the current location. Selecting Restore Missing Files will bring up the Restore window, Figure 5-65. Backing up and restoring files will be covered in Chapter 10.

Figure 5-65. File Manager - Restore

5.5.6 Open in Terminal The Open in Terminal option will open the current location in a terminal window, Figure 5-66. The terminal or command line will be covered in Chapter 11.

Figure 5-66. File Manager - Terminal

5.6 Right Click - Directory Right clicking on any folder or directory in the right pane of the File Manager window will bring up a floating menu, Figure 5-67.

Figure 5-67. File Manager - Right click directory

The menu has the following options: 5.6.1 Open 5.6.2 Open In New Tab 5.6.3 Open in New Window 5.6.4 Open With Other Application 5.6.5 Cut

5.6.6 Copy 5.6.7 Paste Into Folder 5.6.8 Move to 5.6.9 Copy to 5.6.10 Move to Trash 5.6.11 Rename 5.6.12 Compress 5.6.13 Right Click on Compressed File 5.6.14 Local Network Share 5.6.15 Revert to Previous Version 5.6.16 Open in Terminal 5.6.17 Send to 5.6.18 Star 5.6.19 Unstar 5.6.20 Properties Starting with Ubuntu 18.04, the default behavior of a touchpad is to use both buttons as a left click and to use a two finger tap on the touchpad as a right click. You can change this behavior by running the following command from the command line: gsettings set org.gnome.desktop.peripherals.touchpad click-method areas 5.6.1 Open The Open option will open the folder in the current File Manager window. You can also Open a folder by highlighting the folder and pressing Ctrl+O. 5.6.2 Open In New Tab The Open In New Tab option will open the folder in a new tab in the current File Manager window. You can also open the folder in a new tab by highlighting the folder and pressing Shift+Ctrl+T. 5.6.3 Open in New Window The Open In New Window option will open the folder in a new File

Manager window. 5.6.4 Open With Other Application The Open With Other Application option allows you to open the folder with another program besides Files. Selecting Open With Other Application will bring up the Select Application window, Figure 5-68. The default application for opening a folder is Files.

Figure 5-68. File Manager - Select Application

To see other applications that can be used to open a folder, click on View All Applications at the bottom of the window. This list will only include applications that have been installed on the system, Figure 5-69.

Figure 5-69. File Manager - Other Applications

To see which applications may be available to install click on Find New Applications, which will open the Ubuntu Software window with inode/directory as the search term, Figure 5-70. You can install other applications from this window. Installing applications will be covered in more detail in Chapter 8.

Figure 5-70. Ubuntu Software

5.6.5 Cut The Cut option allows you to cut and paste a folder into a different location. Once a folder or directory is cut the color will get slightly lighter indicating that the file or directory has been cut and that a paste action is pending. Once a paste action is completed in another location in the file system, the file or directory icon will disappear from the original location and appear in the new location. You can also Cut a folder by highlighting the folder and pressing Ctrl+X If you attempt to paste a cut directory into a new location that already contains a directory with the same name, you will receive a Merge folder error, Figure 5-71. You will be given the details on both the original folder and the replacement folder and given the option to Cancel the action, Skip the action, or Merge the folders. If you are cutting and pasting multiple folders you can apply the action to all folders by selecting the Apply this action to all files checkbox.

Figure 5-71. File Manager - Merge folder

If you do not want to merge the folders you can also choose to Select a new name for the destination, Figure 5-72. You must provide a new name for the folder and click Rename.

Figure 5-72. File Manager - Merge folder - Rename

5.6.6 Copy The Copy option allows you to copy and paste a folder into the same location or a different location. You can also perform a Copy action by pressing Ctrl+C when a folder is highlighted in a File Manager window. If you attempt to paste a copied directory into a new location that already contains a directory with the same name, you will receive a Merge folder error, Figure 5-73. You will be given the details on both the original folder and the replacement folder and given the option to Cancel the action, Skip the action, or Merge the folders. If you are copying and pasting multiple folders you can apply the action to all folders by selecting the Apply this action to all files checkbox.

Figure 5-73. File Manager - Merge folder

If you do not want to merge the folders you can also choose to Select a new name for the destination, Figure 5-74. You must provide a new name for the folder and click Rename.

Figure 5-74. File Manager - Merge folder - Rename

If you copy and paste a folder into the original location the label (copy) will be appended to the new folder. 5.6.7 Paste Into Folder If you have already performed a Copy action, the Paste Into Folder option will be on the menu. This option will allow you to paste whatever you have copied into the highlighted folder. 5.6.8 Move to The Move To option allows you to move a folder to a different location. The Move To option is essential a cut and paste operation. When Move To is selected from the menu, Select Move Destination window will appear, Figure 5-75, which allows you to select a location for the Move To operation. Clicking the + in the upper right hand corner will allow you to create a new folder in the current location.

Figure 5-75. File Manager - Select Move To Destination

Just like with a cut and paste operation, moving a folder to a location that already contains a folder with the same name will cause a Merge folder error. You will be given the details on both the original folder and the replacement folder and given the option to Cancel the action, Skip the action, or Merge the folders. If you are copying and pasting multiple folders you can apply the action to all of the folders by selecting the Apply this action to all files checkbox. If you do not want to merge the folders you can also choose to Select a new name for the destination. 5.6.9 Copy to The Copy To option allows you to copy a folder to a different location. The Copy To option is essential a copy and paste operation. When Copy To is selected from the menu, the Select Copy Destination window will appear, Figure 5-76, which allows you to select a location for the Copy To operation. Clicking the + in the upper right hand corner will allow you to create a new folder in the current location.

Figure 5-76. File Manager - Copy To

Just like with a copy and paste operation, copying a folder to a location that already contains a folder with the same name will cause a Merge folder error. You will be given the details on both the original folder and the replacement folder and given the option to Cancel the action, Skip the action, or Merge the folders. If you are copying and pasting multiple folders you can apply the action to all of the folders by selecting the Apply this action to all files checkbox. If you do not want to merge the folders you can also choose to Select a new name for the destination. 5.6.10 Move to Trash The Move to Trash option allows you to delete folders and save a copy in the Trash for later retrieval just in case. You can also move folders to the Trash by highlighting the folder and pressing the Delete key. 5.6.11 Rename The Rename option allows you to rename a folder. Once you select Rename

the folder name will become editable, Figure 5-77. To rename the folder, type the new folder name and click Rename. You can also rename a folder by highlighting the folder and pressing the F2 key.

Figure 5-77. File Manager - Rename folder

5.6.12 Compress The Compress option allows you to compress folders in order to save space and bundle file and folders together. Selecting Compress brings up the Compress window, Figure 5-78. The Compress window allows you to specify the name of the compressed file that will be created. You can also choose from the different compression types. The default compression type is .zip. The other options are .tar.xz and .7z.

Figure 5-78. File Manager - Compress

The compressed archive will appear in the selected location with the file extension of the compression type you choose. 5.6.13 Right Click on Compressed File Once the compressed file is created you can right click on the file. The menu

looks similar to the menu for a regular file or folder but includes Open With Archive Manager and Extract Here options, Figure 5-79.

Figure 5-79. File Manager - Compressed file - Right click

5.6.13.1 Open With Archive Manager 5.6.13.2 Extract Here 5.6.13.3 Extract to 5.6.13.1 Open With Archive Manager Compressed files can contain more than one file or folder and the contents can be viewed using Archive Manager by selecting Open With Archive Manager from the drop down menu opened by right clicking on a compressed file. The Archive Manager, Figure 5-80, shows the contents of the compressed file and allows you to extract the contents by clicking Extract in the top left hand corner of the window. You can also specify a specific location for the extracted files to be placed. By default the extracted files will be placed in

the same location as the compressed file.

Figure 5-80. File Manager - Compressed file - Extract

Clicking Extract in the upper left hand corner of the window will bring up the Extract location window, Figure 5-81. From this window you can choose the location to extract the files to. Click Extract to extract the files from the archive.

Figure 5-81. File Manager - Compressed file - Extract Location

You can add additional files to a compressed file using the Archive Manager by clicking the + in the upper left hand corner, Figure 5-82.

Figure 5-82. File Manager - Compressed file - Add files

The Add Files window, Figure 5-83, allows you to select files to add to the compressed file. Once selected click Add in the top right hand corner.

Figure 5-83. File Manager - Compressed file - Add files

Clicking on the menu icon in the upper right hand corner will bring up the Archive Manager drop down menu, Figure 5-84, which has the following options. 5.6.13.1.1 New Archive 5.6.13.1.2 Open 5.6.13.1.3 Save As 5.6.13.1.4 Password 5.6.13.1.5 Test Integrity 5.6.13.1.6 Properties 5.6.13.1.7 View All Files 5.6.13.1.8 View as a Folder 5.6.13.1.9 Sidebar 5.6.13.1.10 Help 5.6.13.1.11 About Archive Manager

Figure 5-84. File Manager - Compressed file - Extract - Menu

5.6.13.1.1 New Archive The New Archive option will allow you to create a complete new compressed archive that will be separate from the compressed file that you right clicked on, Figure 5-85.

Figure 5-85. File Manager - Compressed file - New Archive

Once the new archive is created you will have to add files to the archive by clicking the + in the upper left hand corner and adding files to your archive, Figure 5-86.

Figure 5-86. File Manager - Compressed file - New Archive - Add files

5.6.13.1.2 Open The Open option will allow you to open an existing compressed archive that will be separate from the compressed file that you right clicked on, Figure 587.

Figure 5-87. File Manager - Compressed file - Open

5.6.13.1.3 Save As The Save As option will allow you to save the compressed file that you right clicked on with a different name and in a different location, Figure 5-88.

Figure 5-88. File Manager - Compressed file - Save As

5.6.13.1.4 Password The Password option will allow you to password protect the compressed file that you right clicked on, Figure 5-89. Not all types of compressed files can be password protected. If the Password option is greyed out then the file cannot be password protected.

Figure 5-89. File Manager - Compressed file - Password

5.6.13.1.5 Test Integrity The Test Integrity option will allow you verify the integrity of the compressed file, Figure 5-90.

Figure 5-90. File Manager - Compressed file - Test Integrity

5.6.13.1.6 Properties The Properties option will show you the basic properties of the compressed file that you right clicked on, Figure 5-91.

Figure 5-91. File Manager - Compressed file - Properties

5.6.13.1.7 View All Files The View All Files option will allow you to see the names of the files located in the compressed file that you right clicked on, Figure 5-92.

Figure 5-92. File Manager - Compressed file - View All Files

5.6.13.1.8 View as a Folder The View as a Folder option will show you just the archive as a folder, Figure 5-93.

Figure 5-93. File Manager - Compressed file - View as a Folder

5.6.13.1.9 Sidebar The Sidebar option will open a sidebar on the left side of the window and allow you to expand the archive by clicking the arrow on the right of the archive name, Figure 5-94.

Figure 5-94. File Manager - Compressed file - Sidebar

5.6.13.1.10 Help The Help option will open a browser opened to the Archive Manager Help section, Figure 5-95.

Figure 5-95. File Manager - Compressed file - Help

5.6.13.1.11 About Archive Manager

The About Archive Manager option will open a window that shows the version number for Archive Manager, Figure 5-96.

Figure 5-96. File Manager - Compressed file - About Archive Manager

5.6.13.2 Extract Here The Extract Here option extracts the files from an archive to the current location. If a file or folder with the same name already exists in the current location, a number will be appended to the end of the filename, Figure 5-97.

Figure 5-97. File Manager - Compressed file - Duplicate file

5.6.13.3 Extract to The Extract to option extracts the files from an archive a chosen location, Figure 5-98.

Figure 5-98. File Manager - Extract to

5.6.14 Local Network Share Ubuntu makes the sharing of directories over the network very easy. The Local Network Share tab, Figure 5-99, contains all of the configuration options necessary to share a directory or folder. The first step to sharing a directory is to click the Share this Folder checkbox.

Figure 5-99. File Manager - Properties - Local Network Share

If this is the first time you have shared a folder you will be asked to install the sharing service also known as Samba, Figure 5-100.

Figure 5-100. File Manager - Properties - Local Network Share - Install sharing service

Click Install to install the Samba package, Figure 5-101. You will be asked to authenticate with your password.

Figure 5-101. File Manager - Properties - Local Network Share - Install sharing service - Samba

You may be asked to authenticate to complete the installation, Figure 5-102.

Figure 5-102. File Manager - Properties - Local Network Share - Install sharing service Authentication

Once the install is complete, the Share name and Comment fields which were greyed out will become active. You will have to provide the Share name in order to share the folder but the Comment section can be left blank. If you want users to be able to create and delete files and folders in the share you must check the Allow others to create and delete files in this folder checkbox. You can also enable Guest access, however, for security reasons

this is not recommended as this means that anyone can access the share. Click the Create Share button to create the share. With Samba shares enabled other operating systems can connect to the share over the network, however, before users can access Samba shares they have to have a Samba password configured. Samba configuration will be covered in more detail in Chapter 23. 5.6.15 Revert to Previous Version The Revert to Previous Version option allows you to retrieve an older version of a folder from a backup archive. Selecting Revert to Previous Version brings up the Restore window, Figure 5-103. The Restore window lets you choose which backup archive to restore the file from. Backups are covered in more detail in Chapter 10.

Figure 5-103. File Manager - Restore

5.6.16 Open in Terminal The Open in Terminal option will open the current location in the filesystem in a terminal window, Figure 5-104. The terminal or command line will be covered in Chapter 11.

Figure 5-104. File Manager - Terminal

5.6.17 Send to Selecting Send to allows you to attach a folder to an email and will bring up the default email program, which in most cases is Thunderbird. Email is covered in more detail in Chapter 9. If you have not configured an email client, the email client configuration will be presented when you select Send to from the drop down menu. 5.6.18 Star The Star option allows you to mark a folder as a favorite. Starred folders show up as a link in the Starred link on the left hand side of the File Manager window, Figure 5-105.

Figure 5-105. File Manager - Starred

Folders can also be starred by clicking the star on the right hand side of the File Manager window. 5.6.19 Unstar If a folder has been starred the Unstar option will be available. The Unstar option allows you to remove a folder as a favorite. Folders can also be unstarred by clicking the star on the right hand side of the File Manager window 5.6.20 Properties The Properties option shows the properties for the current directory or folder. The directory properties dialog box has three tabs, Figure 5-106: 5.6.20.1 Basic Tab 5.6.20.2 Permissions Tab 5.6.20.3 Local Network Share Tab

Figure 5-106. File Manager - Properties

5.6.20.1 Basic Tab The Basic tab, Figure 5-106, shows the name of the directory, the type, the contents, the location of the directory, and the free space of the partition that the directory is located on. The name of the directory can also be changed from the Basic tab. 5.6.20.2 Permissions Tab The Permissions tab, Figure 5-107, shows the permissions for the current directory.

Figure 5-107. File Manager - Permissions

The permission are broken down into Owner, Group, and Others with each one having their own set of permissions. File and directory permissions are covered in more detail in Chapter 12. The first set of permissions belong to the Owner of the directory which in Figure 5-107 is Me which means the current user and from here cannot be changed. Below the Owner label is the access permissions for the owner which by default is Create and delete files. You can change the permissions by clicking the down arrow to the right of the access permissions. The access permission options for the Owner are the following: List files only Access files Create and delete files The second set of permissions belong to the Group. By default the Group is set to the current user’s primary group when a directory is created. The user’s primary group name is normally the same as the user’s username but

do not get them confused. Even though the user and group have the same name they are different objects in the system. You can change the file’s Group assignment by clicking the down arrow to the right of the group name. You can change the permissions by clicking the down arrow to the right of the access permissions for the Group. The access permission options for the Group are the following: None List files only Access files Create and delete files The third set of permissions belong to Others, which is the same as Everyone in other operating systems. You can change the permissions by clicking the down arrow to the right of the access permissions for Others. The access permission options for Others are the following: None List files only Access files Create and delete files At the bottom of the window, Change Permissions for Enclosed Files, will allow you to copy the permissions from the directory to all of the files and folders in the directory. The Change Permissions for Enclosed Files window, Figure 5-108, allows you to change the permissions for both files and folders in the current folder. There are permissions for the Owner, Group, and Others.

Figure 5-108. File Manager - Permissions - Change Permissions for Enclosed Files

The file permission options for the Owner are Read-only and Read and write. The file permission options for the Group and Others are None, Read-only, and Read and write. The directory permission options for the Owner are List files only, Access files, and Create and delete files. The directory permission options for the Group and Others are None, List files only, Access files, and Create and delete files. File and directory permissions will be covered in more detail in Chapter 12. 5.6.20.3 Local Network Share Tab Ubuntu makes the sharing of directories over the network very easy. The Local Network Share tab, Figure 5-109 contains all of the configuration options necessary to share a directory or folder. The first step to sharing a directory is to click the Share This Folder checkbox.

Figure 5-109. File Manager - Properties - Local Network Share

If this is the first time you have shared a folder you will be asked to install the sharing service also known as Samba, Figure 5-110, which was already covered earlier in this chapter.

Figure 5-110. File Manager - Properties - Local Network Share - Install sharing service

You will have to provide the Share name in order to share the folder but the Comment section can be left blank. If you want users to be able to create and delete files and folders in the share you must check the Allow others to create and delete files in this folder checkbox. You can also enable Guest access, however, for security reasons this is not recommended as this means that anyone can access the share.

Click the Create Share button to create the share. With Samba shares enabled other operating systems can connect to the share over the network, however, before users can access Samba shares they have to have a Samba password configured. Samba configuration will be covered in more detail in Chapter 23.

5.7 Right Click - File Right clicking on a file brings up a different drop down menu from right clicking on a folder, Figure 5-111.

Figure 5-111. File Manager - Right click on a file

The menu has the following options: 5.7.1 Open With Text Editor 5.7.2 Open With Other Application 5.7.3 Cut 5.7.4 Copy 5.7.5 Move To 5.7.6 Copy To

5.7.7 Move to Trash 5.7.8 Rename 5.7.9 Compress 5.7.10 Revert to Previous Version 5.7.11 Send to 5.7.12 Properties Starting with Ubuntu 18.04, the default behavior of a touchpad is to use both buttons as a left click and to use a two finger tap on the touchpad as a right click. You can change this behavior by running the following command from the command line: gsettings set org.gnome.desktop.peripherals.touchpad click-method areas 5.7.1 Open With Text Editor The Open With Text Editor option will open the file with Gedit which is a text editing program that comes installed in Ubuntu and many other flavors of Linux, Figure 5-112. Gedit can be used to edit basic text files but not full document file types. You can also perform an Open With Text Editor action by pressing Ctrl+O when a file is highlighted in a File Manager window that is already open and has focus.

Figure 5-112. File Manager - Gedit

5.7.2 Open With Other Application The Open With Other Application option allows you to open the file with another program such as LibreOffice, which is an office productivity software suite that comes with Ubuntu Linux, Figure 5-113.

Figure 5-113. File Manager - Open WIth

To see other applications that can be used to open a file, click on View All Applications at the bottom of the window. This list will only include applications that have already been installed on the system, Figure 5-114.

Figure 5-114. File Manager - Other Applications

To see which applications may be available to install, click on Find New Applications, which will open the Ubuntu Software application. The Ubuntu Software application will be covered in more detail in Chapter 8. 5.7.3 Cut The Cut option allows you to cut and paste a file or folder into a different location. You can also perform a Cut action by pressing Ctrl+X when a file is highlighted in a File Manager window. Once a file or directory is cut the color will get slightly lighter indicating that the file or directory has been cut and that a paste action is pending. Once a paste action is completed in another location in the file system, the file or directory icon will disappear from the original location and appear in the new location. If you attempt to paste a cut file or directory into the same location that the original file or directory is cut from or if the new location already contains a file or directory with the same name, you will receive a File Conflict error,

Figure 5-115. You will be given the details on both the original file and the replacement file and given the option to Cancel the action, Skip the action, or Replace the file. If you are cutting and pasting multiple files you can apply the action to all files by selecting the Apply this action to all files checkbox. You can also provide a new name for the file.

Figure 5-115. File Manager - File conflict

5.7.4 Copy The Copy option allows you to copy and paste a file or folder into the same location or a different location than the original file or folder. You can also perform a Copy action by pressing Ctrl+C when a file is highlighted in a File Manager window. If you copy and paste into the same location, then a new file with the (copy) tag included in the name will be created. Unlike using cut and paste in the same location, you will not get an error. 5.7.5 Move To The Move To option allows you to move a file or folder to a different location than the original file or folder location. The Move To option is essential a cut and paste operation. Once Move To is selected from the menu, the Select Move Destination window will appear, Figure 5-116, which allows you to select a location for the move operation.

Figure 5-116. File Manager - Select Move To Destination

Clicking the + in the upper right hand corner will allow you to create a new folder in the current location. Just like with a cut and paste operation, moving a file or folder to a location that already contains a file or folder with the same name will cause a File Conflict error, Figure 5-117. You will be given the details on both the original file and the replacement file and given the option to Cancel the action, Skip the action, or Replace the file. If you are moving multiple files you can apply the action to all files by selecting the Apply this action to all files checkbox.

Figure 5-117. File Manager - Move To - File conflict

5.7.6 Copy To The Copy To option allows you to copy a file or folder to a different location than the original file or folder. The Copy To option is essential a copy and paste operation. Once Copy To is selected from the menu, the Select Copy Destination window will appear, Figure 5-118, which allows you to select a location for the move operation.

Figure 5-118. File Manager - Select Copy To Destination

Clicking the + in the upper right hand corner will allow you to create a new folder in the current location. 5.7.7 Move to Trash The Move to Trash option allows you to delete files and save a copy in the Trash for later retrieval just in case. You can also move file to the Trash by highlighting the file and pressing the Delete key. 5.7.8 Rename The Rename option allows you to rename a file. Once you select Rename, the file name will become editable, Figure 5-119. To rename the file, type the new filename and click Rename.

Figure 5-119. File Manager - Rename file

5.7.9 Compress The Compress option allows you to compress files in order to save space and bundle files together. Selecting Compress brings up the Compress window, Figure 5-120. The Compress window allows you to specify the name of the compressed file that will be created. You can also choose from the different compression types. The default compression type is .zip. The other options are .tar.xz and .7z.

Figure 5-120. File Manager - Compress file

Compressing files and folders was covered earlier in this chapter. 5.7.10 Revert to Previous Version The Revert to Previous Version option allows you to retrieve an older version of a file from a backup archive. Selecting Revert to Previous Version brings up the Restore window, Figure 5-121. The Restore window lets you choose which backup archive to restore the file from. Backups are covered in more detail in Chapter 10.

Figure 5-121. File Manager - Restore

5.7.11 Send to Selecting Send to allows you to attach a file to an email and will bring up the

default email program, which in most cases is Thunderbird. Email is covered in more detail in Chapter 9. If you have not configured an email client, the email client configuration will be presented when you select Send to from the drop down menu. 5.7.12 Properties The Properties option brings up the properties window for the selected file. The Properties window for a file, Figure 5-122, has the following tabs: 5.7.12.1 Basic Tab 5.7.12.2 Permissions Tab 5.7.12.3 Open With Tab

Figure 5-122. File Manager - Properties - Basic Tab

5.7.12.1 Basic Tab The Basic tab, Figure 5-122, shows the name of the file, the file type, the file size, the file location, and the last accessed and modified date and time. The

name of the file can also be changed from the Basic tab. 5.7.12.2 Permissions Tab The Permissions tab, Figure 5-123, shows the various permissions for a file. The permissions are broken down into Owner, Group, and Others with each one having their own permissions.

Figure 5-123. File Manager - Properties - Permissions Tab

The first set of permissions belong to the owner of the file, which is Me meaning the current user. Below the Owner label is the access permissions for the owner, which by default is Read and write. You can change the permissions by clicking the down arrow to the right of the access permissions. The access permission options for the Owner include the following: Read-only Read and write

The second set of permissions belong to the Group. By default the Group is set to the current user’s primary group when a file is created. You can change the group by clicking the down arrow to the right of the group name. You can change the permissions by clicking the down arrow to the right of the access permissions for the Group. The access permission options for the Group are the following: None Read-only Read and write The third set of permissions belong to the Others. You can change the permissions by clicking the down arrow to the right of the access permissions for the Others. The access permission options for the Others are the following: None Read-only Read and write At the bottom of the window, the Allow executing file as a program option, allows you to select which files can be run as a program like a script or other executable program. Be careful when using this option. Ensure you have the permissions properly set before selecting this option to prevent users from executing scripts or programs that they are not authorized to execute. 5.7.12.3 Open With Tab The Open With tab, Figure 5-124, shows the various applications that can be used to open the file. The applications groups include Default Application, Recommend Applications, and Other Applications.

Figure 5-124. File Manager - Properties - Open With

You can change the Default Application by selecting an application in the Recommended Applications or Other Applications section and clicking the Set as default button in the bottom right hand corner. The selected application will be moved up to the Default Application and what was the Default Application will be moved down to the Recommended Applications section. You can move applications from the Other Applications section to the Recommended Applications section by selecting an application and clicking the Add button at the bottom of the window. The selected application will be moved up to the Recommended Applications section. You can reset all the settings to default by clicking the Reset button in the lower left hand corner of the window. The Default Application and Recommended Applications will be reset to the default configuration.

5.8 Files Menu

The File Manager has a menu option in the top left hand corner of the window, similar to most operating systems, Figure 5-125. The first item on the menu is the name of the folder currently open in the File Manager window.

Figure 5-125. File Manager - Files menu

The Files menu has the following options: 5.8.1 New Window 5.8.2 Show Details 5.8.3 Quit 5.8.1 New Window The first option, New Window, will open a new File Manager window. You can also open a new File Manager window by pressing Ctrl+N when a File Manager window is already open and has focus. The new File Manager window will open with the Home folder as the focus. 5.8.2 Show Details The next option, Show Details, will open an Ubuntu Software window that will show details about Nautilus, the name of the default File Manager in Ubuntu, Figure 5-126.

Figure 5-126. File Manager - Files menu - Details

5.8.3 Quit The Quit option will close the current File Manager window. You can also close the current File Manager window by pressing Ctrl+Q.

6. SYSTEM SETTINGS

6. System Settings The System Settings can be accessed by clicking on the down arrow in the top right hand corner of the desktop and then clicking on the System Settings icon in the bottom left hand corner of the menu, Figure 6-1.

Figure 6-1. System Settings icon

Figure 6-2 shows the System Settings window.

Figure 6-2. System Settings - Wi-Fi

The Settings window has the settings on the left hand side with the options for the currently selected setting on the right hand side. 6.1 Wi-Fi 6.2 Bluetooth 6.3 Background 6.4 Dock 6.5 Notifications 6.6 Search 6.7 Region & Language 6.8 Universal Access 6.9 Online Accounts 6.10 Privacy 6.12 Sharing

6.13 Sound 6.14 Power 6.15 Network 6.16 Devices 6.17 Details

6.1 Wi-Fi The first option in the setting is Wi-Fi, Figure 6-2. If your system has a wireless card installed then the wireless settings will have options. Wireless settings will be covered in Chapter 7. If your system does not have a wireless card installed then the wireless settings will be missing.

6.2 Bluetooth The Bluetooth settings, Figure 6-3, allow you to control Bluetooth if it is part of your installed hardware. You can turn Bluetooth on and off using the switch in the upper left hand corner. If Bluetooth is on any devices within range the device will be displayed in the middle of the window. For security purposes, I recommend turning off Bluetooth when not needed. You can add Bluetooth devices by clicking on the listed device.

Figure 6-3. System Settings - Bluetooth

If there is no Bluetooth capability on your system there will be No Bluetooth Found message displayed, Figure 6-4.

Figure 6-4. System Settings - No Bluetooth

Clicking on a Bluetooth device will cause your system to attempt to connect

to the device. Some devices will ask for confirmation to connect by showing a PIN on both devices to ensure you are connecting to the correct device, Figure 6-5.

Figure 6-5. System Settings - Bluetooth - PIN

Once connected, clicking on the device name in the main Bluetooth window will bring up the properties for the device, Figure 6-6. From this window you can turn the connection on and off, send files to the device, and remove the device.

Figure 6-6. System Settings - Bluetooth - Device

6.3 Background In the Background settings, Figure 6-7, you can configure both the Background and the Lock Screen. The configuration options are the same for both.

Figure 6-7. System Settings - Background

Clicking on either Background or Lock Screen will bring up the configuration options, Figure 6-8.

Figure 6-8. System Settings - Background - Wallpapers

There will be three tabs: 6.3.1 Wallpapers 6.3.2 Pictures 6.3.3 Colors 6.3.1 Wallpapers Clicking on any of the pictures on the Wallpapers tab will make the selected picture the wallpaper on your desktop. 6.3.2 Pictures Clicking on any of the pictures on the Pictures tab will make the selected picture the wallpaper on your desktop. The pictures shown will be any pictures in your Pictures directory. 6.3.3 Colors Clicking on any of the colors on the Colors tab will make the selected color the wallpaper on your desktop, Figure 6-9.

Figure 6-9. System Settings - Background - Colors

6.4 Dock The Dock settings, Figure 6-10, allow you to control the Dock on the left hand side of the desktop.

Figure 6-10. System Settings - Dock

Enabling Auto-Hide the Dock by switching it On in the top right hand corner will cause the Dock to disappear when not being used. To make the Dock reappear just move your mouse to the left side of the screen. Changing the Icon size changes the size of the icons on the Dock. Increasing the size makes the icons easier to see and use, reducing the size creates more desktop space. The default size is 48. The Position on screen setting has three options, Figure 6-11. Figure 6-12

shows an example of the Dock at the bottom of the screen and Figure 6-13 shows an example of the Dock on the right hand side of the screen.

Figure 6-11. System Settings - Dock - Position

Figure 6-12. System Settings - Dock - Position - Bottom

Figure 6-13. System Settings - Dock - Position - Left

6.5 Notifications The Notifications settings, Figure 6-14, allow you to enable and disable Notifications Popups and Lock Screen Notifications by using the switches at the top of the window. Applications that have notifications are listed in the Applications section.

Figure 6-14. System Settings - Notifications

Clicking on an application will bring up the configuration options for that application. Figure 6-15. The options for all applications are the same.

Figure 6-15. System Settings - Notifications - Settings

6.6 Search The Search settings, Figure 6-16, allow you to configure which applications to include in search results from the Activities screen.

Figure 6-16. System Settings - Search

6.7 Region & Language The Region & Language Support settings, Figure 6-17, allow you to install input languages other than the language that was selected during installation and manage installed languages. The installation of additional languages is a multi-step process. You will have to install additional language support, install the language pack, and configure the language input.

Figure 6-17. System Settings - Region & Language

6.7.1 Language 6.7.2 Formats 6.7.3 Input Sources 6.7.4 Options 6.7.5 Install and Remove Input Sources 6.7.6 Manage Installed Languages 6.7.1 Language The Language option allows you to set which language to use for your system, Figure 6-18.

Figure 6-18. System Settings - Language

When the language has been changed, a restart may be necessary for the changes to take effect, Figure 6-19.

Figure 6-19. System Settings - Language - Restart

6.7.2 Formats The Formats option allows you to set which language format to use for your system, Figure 6-20. A preview of the format will be provided on the right hand side.

Figure 6-20. System Settings - Language - Formats

6.7.3 Input Sources The Input Sources section, Figure 6-21, shows you the currently installed languages. You can set the order that the languages will appear in the language drop down in the upper right hand corner of the desktop, Figure 622, by clicking and dragging the language to the appropriate order.

Figure 6-21. System Settings - Language - Input Sources

Figure 6-22. System Settings - Languages

6.7.4 Options The Options button allows you set Input Source Options, Figure 6-23. The Keyboard Shortcuts for switching between languages are also displayed.

Figure 6-23. System Settings - Language - Input Source Options

6.7.5 Install and Remove Input Sources To install and remove languages you must use the + and - under the list of languages. Clicking the + will bring up the Add an Input Source window, Figure 6-24. To access additional languages click the three vertical dots at the bottom of the list.

Figure 6-24. System Settings - Language - Add an Input Source

You can type the name of the language you are looking for in the search box at the bottom of the window then click Other, Figure 6-25.

Figure 6-25. System Settings - Language - Add an Input Source - Other

Choose the language that you want to add and Click Add in the upper right hand corner, Figure 6-26.

Figure 6-26. System Settings - Language - Add an Input Source - Japanese

6.7.6 Manage Installed Languages The Manage Installed Languages button allows you to complete language installations and manage installed languages. If this is the first time you have accessed this setting you will need to complete the Language Support install as it is not fully installed by default, Figure 6-27. You may have to authenticate to complete the installation.

Figure 6-27 System Settings - Language Support - Install

Once the Language Support is fully installed you can select Install /

Remove Languages to choose the language to install, Figure 6-28.

Figure 6-28. System Settings - Language Support

Select the language you want to add then click Apply Changes, Figure 6-29.

Figure 6-29. System Settings - Language Support - Install/Remove Languages

Once a language is installed you will have to configure the text input settings which will be covered later in this chapter.

6.8 Universal Access The Universal Access settings, Figure 6-30, are for users who require assistive technologies to interact with and control their systems.

Figure 6-30. System Settings - Universal Access

Turning on Always Show Universal Access Menu enables the Universal Access Menu on the Panel at the top of the desktop, Figure 6-31. Each of the main Universal Access options can be enabled and disabled from this menu.

Figure 6-31. System Settings - Universal Access - Desktop Panel

The Universal Access settings, Figure 6-30, has four sections: 6.8.1 Seeing 6.8.2 Hearing 6.8.3 Typing 6.8.4 Pointing and Clicking Tab 6.8.1 Seeing The Seeing section, Figure 6-32, allows you to turn on a High Contrast screen, Large Text, adjust the Cursor Size Screen, configure Zoom, turn on the Screen Reader, and turn on Sound Keys for easier viewing and to assist people who have difficulty viewing the screen.

Figure 6-32. System Settings - Universal Access - Seeing

6.8.1.1 High Contrast 6.8.1.2 Large Text 6.8.1.3 Cursor Size 6.8.1.4 Zoom 6.8.1.5 Screen Reader 6.8.1.6 Sound Keys 6.8.1.1 High Contrast Turning on High Contrast will turn the whole desktop high contrast, Figure 6-35.

Figure 6-35. System Settings - Universal Access - Seeing - High Contrast

6.8.1.2 Large Text Turning on Large Text will increase the font size of all text on the desktop. 6.8.1.3 Cursor Size Selecting Cursor Size will allow you to choose a cursor size to use, Figure 636.

Figure 6-36. System Settings - Universal Access - Seeing - Cursor Size

6.8.1.4 Zoom The Zoom Options has the following tabs:

6.8.1.4.1 Magnifier 6.8.1.4.2 Crosshairs 6.8.1.4.3 Color Effects 6.8.1.4.1 Magnifier The Magnifier tab allows you to enable zooming into the desktop, Figure 637. By default Zoom is turned off.

Figure 6-37. System Settings - Universal Access - Seeing - Zoom Options

The Magnification option will zoom in on the entire desktop. Once you zoom in the edges of the screen will no longer be visible and you will have to move the cursor around to get to the edges of the screen. The Magnifier Position options allow you to configure how the magnifier operates. You can choose to have the screen zoom in and follow the mouse cursor or configure the zoom to effect a certain part of the screen by selecting Screen part and then using the drop down menu to the left to choose an option, Figure 6-38.

Figure 6-38. System Settings - Universal Access - Seeing - Zoom Options - Screen Part

The Full screen option zooms in on the entire screen. The Top half option zooms in on the top half of the screen and the bottom half of the screen remains at normal zoom. The Bottom half option zooms in on the bottom half of the screen and the top half of the screen remains at normal zoom. The Left half option zooms in on the left half of the screen and the right half of the screen remains at normal zoom. The Right half option zooms in on the right half of the screen and the left half of the screen remains at normal zoom. Magnifier extends outside the screen makes the zoomed desktop slightly larger than the screen to provide extra space to move the cursor around the edges of the screen. Keep magnifier cursor centered will hold the cursor in the center of the screen until the edge of the screen is reached and then the mouse will move. Magnifier cursor pushes contents around will move the screen in the same direction as the movement of the cursor when the cursor reaches the edge of the visible screen. Magnifier cursor moves with contents will move the screen in the opposite direction from the movement of the cursor.

6.8.1.4.2 Crosshairs The Crosshairs options, Figure 6-39, allow you to configure crosshairs to go with the cursor when zoomed in to make the mouse easier to see, Figure 640. You can turn the Crosshairs on and off, allow the mouse to overlap the crosshairs, control the thickness and length of the crosshairs, and select the color.

Figure 6-39. System Settings - Universal Access - Seeing - Zoom Options - Crosshairs

Figure 6-40. System Settings - Universal Access - Seeing - Zoom Options - Crosshairs - Example

6.8.1.4.3 Color Effects The Color Effects tab, Figure 6-41, allows you to control the color, White on black, Brightness, Contrast, and Color.

Figure 6-41. System Settings - Universal Access - Seeing - Zoom Options - Color Effects

Figure 6-42 shows an example of Zoom with White on black enabled.

Figure 6-42. System Settings - Universal Access - Seeing - Zoom Options - Color Effects - White on black

6.8.1.5 Screen Reader The Screen Reader option allows you to turn on a screen reader that will read text from the screen, Figure 6-43.

Figure 6-43. System Settings - Universal Access - Seeing - Screen Reader

6.8.1.6 Sound Keys The Sound Keys option allows you to turn on a beep whenever the Num Lock or Caps Lock is turned on, Figure 6-44.

Figure 6-44. System Settings - Universal Access - Seeing - Sound Keys

6.8.2 Hearing The Hearing section, Figure 6-45, allows you to turn on Visual Alerts for people who have difficulty hearing. You can choose to have the window title or the entire screen flash when there is an alert sound. You can also test the flash alert by clicking the Test Flash button in the upper left hand corner.

Figure 6-45. System Settings - Universal Access - Hearing

6.8.3 Typing The Typing settings, Figure 6-46, contains settings to assist with typing on a keyboard.

Figure 6-46. System Settings - Universal Access - Typing

6.8.3.1 Screen Keyboard 6.8.3.2 Repeat Keys 6.8.3.3 Cursor Blinking 6.8.3.4 Typing Assistant 6.8.3.1 Screen Keyboard Turning on the Screen Keyboard puts a keyboard on the screen that allows keys to be typed by using the mouse, Figure 6-47.

Figure 6-47. System Settings - Universal Access - Typing - On Screen keyboard

6.8.3.2 Repeat Keys

The Repeat Keys option allows you to configure the Delay and Speed that keys will be repeated as they are pressed. You can change the Delay and Speed by moving the sliders, Figure 6-48.

Figure 6-48. System Settings - Universal Access - Typing - Repeat Keys

6.8.3.3 Cursor Blinking The Cursor Blinking option allows you to control the blinking speed of the cursor by moving the slider, Figure 6-49.

Figure 6-49. System Settings - Universal Access - Typing - Cursor Blinking

6.8.3.4 Typing Assistant The Typing Assistant, Figure 6-50, allows you to configure various assistive options.

Figure 6-50. System Settings - Universal Access - Typing - Typing Assist

The Enable by Keyboard option allows you to turn accessibility features on and off using keyboard shortcuts. Sticky Keys allow the use of keys such as Alt, Ctrl, or Shift by pressing the key once and it will remain active without having to hold the key. This helps reduce strain on the hands when typing for a long period of time. Slow Keys creates a delay between when a key is pressed and when the input is accepted. The key must be held for the specified duration before the input is accepted. Bounce Keys allow you to configure the ignoring of repeated rapid pressing of the same key. 6.8.4 Pointing and Clicking Tab The Pointing and Clicking settings, Figure 6-51, allow you to control how the mouse or trackpad on your system works.

Figure 6-51. System Settings - Universal Access - Pointing & Clicking

6.8.4.1 Mouse Keys 6.8.4.2 Click Assist 6.8.4.3 Double-Click Delay 6.8.4.1 Mouse Keys Turning Mouse Keys on will allow you to use the arrow keys on your keyboard to move the pointer vice using the mouse. 6.8.4.2 Click Assist The Click Assist, Figure 6-52, provides assistance with clicking with the mouse.

Figure 6-52. System Settings - Universal Access - Pointing & Clicking - Click Assist

Simulated Secondary Click allows you to configure the mouse to interpret holding a mouse button as doubleclick vice a single click.

Hover Click allows you to configure the mouse to trigger a click when you hover over an area of the screen such as a hyperlink. Turning on Hover Click will bring up a pop up menu that allows you to choose how the hover click will be treated. The options are Single Click, Double Click, Drag, and Secondary Click, Figure 6-53.

Figure 6-53. System Settings - Universal Access - Pointing & Clicking - Hover Click

The Delay option allows you to configure how long a hover has to occur to register as a click. The Motion threshold option allows you to configure how much motion to allow for people who are unable to hold the mouse steady. 6.8.4.3 Double-Click Delay The Double-Click Delay option allows you to configure how close a double click has to be to register as a double click.

6.9 Online Accounts The Online Accounts settings, Figure 6-53, allow you to integrate your online accounts with various Ubuntu programs and websites.

Figure 6-53. System Settings - Online Accounts

Click on any of the listed websites to configure your username and password. Figure 6-54 shows an example of the Google Account configuration.

Figure 6-54. System Settings - Online Accounts - Google

For security reasons I do not recommend using online accounts. I recommend that you provide a username and password each time your applications want to access an online account.

6.10 Privacy The Privacy settings, Figure 6-55, helps keep your data and privacy safe.

Figure 6-55. System Settings - Privacy

6.10.1 Screen Lock 6.10.2 Location Services 6.10.3 Usage & History 6.10.4 Purge Trash & Temporary Files 6.10.5 Problem Reporting 6.10.6 Network Connectivity Checking 6.10.1 Screen Lock The Screen Lock settings, Figure 6-56, allows you to enable and disable the Automatic Screen Lock function.

Figure 6-56. System Settings - Privacy - Screen Lock

You can configure how long to wait before locking the screen, Figure 6-57.

Figure 6-57. System Settings - Privacy - Screen Lock - Time

Enabling Show Notifications allows the showing of notifications on the lock screen. 6.10.2 Location Services

Enabling Location Services allows applications to determine your location, Figure 6-58. Ubuntu use the Mozilla Location Service and there is a link to the Privacy Policy for this service. If you do not want applications tracking your location, disable this option. For security reasons I recommend disabling this option.

Figure 6-58. System Settings - Privacy - Location Services

6.10.3 Usage & History The Usage & History settings, Figure 6-59, allow you to control how long files that you access are remembered and to clear the history.

Figure 6-59. System Settings - Privacy - Usage & History

The Retain History option default is Forever. The other options are 1 day, 7 days, and 30 days.

Figure 6-60 shows the Recent location in Files. The files listed are contained in the retained history.

Figure 6-60. Recent files

After clicking the Clear Recent History button the list of files will be empty, Figure 6-61, but the files still remain on the system. Just the history of file access is deleted.

Figure 6-61. Recent files - Empty

6.10.4 Purge Trash & Temporary Files

The Purge Trash & Temporary Files settings, Figure 6-62, allow you to configure the automatic purging of the Trash and Temporary Files.

Figure 6-63. System Settings - Privacy - Purge Trash & Temporary File

If you enable automatic purging you can aso configure how often to purge the files, Figure 6-64.

Figure 6-64. System Settings - Privacy - Purge Trash & Temporary File - Purge After

From the settings you can also purge the temporary files and trash, Figure 665 and Figure 6-66.

Figure 6-65. System Settings - Privacy - Purge Trash & Temporary File - Purge Temporary File

Figure 6-66. System Settings - Privacy - Purge Trash & Temporary File - Empty Trash

6.10.5 Problem Reporting The Problem Reporting setting allows you to enable and disable the automatic reporting of problems with your system and requiring a dialog box for each error before reporting the error to Canonical, the makers of Ubuntu , Figure 6-67. Clicking on the Privacy Policy link will open a web browser with the Ubuntu Privacy Policy.

Figure 6-67. System Settings - Privacy - Problem Reporting

6.10.6 Network Connectivity Checking The Connectivity Checking setting allows you to enable and disable the ability of your system to verify that it can reach the Internet whenever it is

connected to a network, Figure 6-68.

Figure 6-68. System Settings - Privacy - Connectivity Checking

6.11 Applications The Applications settings, Figure 6-69, allow you to configure sharing some basic options for various applications. The applications will be listed on the left and the options for the selected application will be on the right. Every application has the Notifications option and some applications have additional options such as file associations.

Figure 6-69. System Settings - Applications

6.12 Sharing The Sharing settings, Figure 6-70, allow you to configure sharing of your screen.

Figure 6-70. System Settings - Sharing

Sharing will be covered in more detail in Chapter 23.

6.13 Sound The Sound settings, Figure 6-71, allow you to control the sound on your Ubuntu system. The Sound settings has four sections: 6.13.1 System Volume 6.13.2 Volume Levels 6.13.3 Output 6.13.4 Input 6.13.5 Alert Sound

Figure 6-71. System Settings - Sounds - Output

6.13.1 System Volume The System Volume settings allow you to control the overall system sound. You can raise and lower the sound volume by moving the slider ad enable or disable the sound by clicking the speaker on the right. The OverAmplification option allows you to take the sound over 100%. 6.13.2 Volume Levels The Volume Levels setting allow you to control System Sounds separately from the overall system sound. 6.13.3 Output The Output settings, allow you to choose the Output Device if there are multiple outputs and control the Balance. You can test the sound by clicking the Test Sound button, Figure 6-72.

Figure 6-72. System Settings - Sounds - Output - Speaker Testing

6.13.4 Input The Input settings allow you to control the sound input device and volume and to enable or disable the sound input. 6.13.5 Alert Sound The Alert Sound settings, Figure 6-73, allows you to choose the alert sound. The alert sound is the sound the system makes when there is an error or some other issue.

Figure 6-73. System Settings - Sounds - Alert Sound

6.14 Power The Power settings, Figure 6-74, allow you to control various aspects of power and battery use.

Figure 6-74. System Settings - Power

The Power settings has the following sections: 6.14.1 Battery 6.14.2 Power Saving 6.14.3 Suspend & Power Button 6.14.1 Battery The Battery section shows the current state of the battery if one is present. 6.14.2 Power Saving The Power Saving settings allow you to configure your system to conserve power. The Screen brightness allows you to adjust the screen brightness by moving the slider. The Dim screen when inactive option will automatically dim the screen

when you have not used your system. The Blank screen option allows you to choose how long to wait before turning off the screen, Figure 6-75.

Figure 6-75. System Settings - Power - Blank screen

The Wifi option allows you to enable and disable Wifi to save power when Wifi is not needed. The Bluetooth option allows you to enable and disable Bluetooth to save power when Bluetooth is not needed. 6.14.3 Suspend & Power Button The Suspend & Power Button options allow you to configure the Suspend and Power Button actions. When you click on Automatic suspend the Automatic Suspend window will open, Figure 6-76.

Figure 6-76. System Settings - Power - Automatic Suspend

You have choices for On Battery Power and Plugged In, each with its own switch and drop down menu. Each drop down menu contains the following time options, Figure 6-77:

Figure 6-77. System Settings - Power - Automatic Suspend - Time options

The When the Power Button is pressed option has the following options in the drop down menu, Figure 6-78:

Figure 6-78. System Settings - Power - Automatic Suspend - Power Button

6.15 Network The Network settings, Figure 6-79, allow you to control the network interfaces of your system and will be covered in more detail in Chapter 7.

Figure 6-79. System Settings - Network

6.16 Devices Clicking on Devices will open up the Devices menu, Figure 6-80.

Figure 6-80. System Settings - Devices

The Devices menu has the following settings: 6.16.1 Displays 6.16.2 Keyboard 6.16.3 Mouse & Touchpad 6.16.4 Printers 6.16.5 Removable Media 6.16.6 Thunderbolt 6.16.7 Color 6.16.1 Displays The Displays settings allow you to control your system display, Figure 6-80. The Orientation option, Figure 6-81, allows you to select the orientation of your screen. You can choose Landscape, Portrait Right, Portrait Left, and Landscape (flipped).

Figure 6-81. System Settings - Displays - Orientation

The Resolution option, Figure 6-82, allows you to select the resolution of your screen.

Figure 6-82 System Settings - Displays - Resolution

The Refresh Rate option, Figure 6-83, allows you to select the refresh rate of your screen.

Figure 6-83. System Settings - Displays - Refresh rate

Any time you make a change to the Orientation, Resolution, or Refresh Rate you will have the option to Revert Settings or Keep Changes, Figure 6-84. If you do not make any choice the settings will automatically revert to the previous settings. Even if you cannot see the display due to a change in the settings, the display will revert after 20 seconds as long as you do not make a choice.

Figure 6-84. System Settings - Displays - Keep Changes

The Night Light option, Figure 6-85, allows you to enable and disable the Night Light feature which removes the blue light from the display to make the display warmer. Studies have shown that blue light in computer and device displays can affect your ability to sleep properly. You can Schedule the Night Light functionality to be active from Sunset to Sunrise or use a Manual time configuration.

Figure 6-85. System Settings - Displays - Night Light

6.16.2 Keyboard The Keyboard settings, Figure 6-86, allow you to control keyboard shortcuts. You can reset all of the shortcuts to default by clicking the Reset All button in the top right hand corner.

Figure 6-86. System Settings - Keyboard

To edit a shortcut click on the shortcut and press the new key combination, Figure 6-87.

Figure 6-87 System Settings - Keyboard - Set Shortcut

6.16.3 Mouse & Touchpad

The Mouse & Touchpad settings, Figure 6-88, allow you to configure mouse and touchpad functionality. You can also test your settings by clicking the Test Your Settings button in the upper right hand corner of the window.

Figure 6-88. System Settings - Mouse & Touchpad

6.16.3.1 General 6.16.3.2 Touchpad 6.16.3.1 General The General section allows you to control the Primary Button which is the button used to select items when the mouse is over the item. You can select either Left or Right. 6.16.3.2 Touchpad The Touchpad section allows you to control the Touchpad configuration. The Touchpad option allows you to enable and disable the Touchpad. The Natural Scrolling option allows you to enable and disable the scroll action moving the content. If this is disabled the scrolling action moves the view.

The Touchpad Speed allows you to configure how fast the cursor moves on the screen in relation to the action on the Touchpad. The Tap to Click option allows you to enable and disable the tapping on the Touchpad to simulate a mouse click. The Two-finger Scrolling option allows you to enable and disable the sliding of two fingers across the Touchpad at the same time creating a scroll action on the screen. The Edge Scrolling option allows you to enable and disable the use of the edge of the Touchpad to create a scroll action on the screen. When this option is enabled the Two-finger Scrolling option will automatically be disabled. 6.16.4 Printers The Printer settings, Figure 6-89, allow you add and delete printers from your system. To add a printer click the Add a printer button.

Figure 6-89. System Settings - Printers

Most modern printers will be auto-detected by Ubuntu and will include the correct name. You can also add a network printer. In Figure 6-90, a printer is connected via WiFi. Once your device is selected, press Add.

Figure 6-90. System Settings - Printers - Select Device

6.16.5 Removable Media The Removable Media section, Figure 6-91, allows you control what your system does with different types of removable media. The following types of media can be controlled: CD Audio DVD Video Music player Photos Software

Figure 6-91. System Settings - Removable Media

For each type of media, the drop down menu on the right will allow you to choose what action to take when that particular type of media is detected by the operating system, Figure 6-92. You can choose an application to open the media with, Ask what to do, Do nothing, or Open folder. For security reasons the Software option should be set to Ask what to do or Do Nothing. You should never allow software on removable media to run automatically.

Figure 6-92. System Settings - Removable Media - Options

You can also adjust the settings for other types of media by clicking on the Other Media button. Figure 6-93 shows the Other Media settings.

Figure 6-93. System Settings - Removable Media - Other Media

The Type options, Figure 6-94, allow you to choose the media type.

Figure 6-94. System Settings - Removable Media - Other Media - Type

The Actions options, Figure 6-95, allow you to choose the action type.

Figure 6-95. System Settings - Removable Media - Other Media - Other

Allowing media and software to launch automatically when removable media is connected to a system is not a good security practice. To mitigate the risk you can stop this behavior by checking the Never prompt or start programs on media insertion check box at the bottom of the window. 6.16.6 Thunderbolt The Thunderbolt settings, Figure 6-96, are available is Thunderbolt is installed on your system.

Figure 6-96. System Settings - Thunderbolt

6.16.7 Color The Color settings, Figure 6-97, allow you to view the color profiles for you system.

Figure 6-97. System Settings - Color

6.17 Details The Details menu has the following options. 6.17.1 About 6.17.2 Date & Time 6.17.3 Users 6.17.4 Default Applications 6.17.1 About The About section, Figure 6-98, shows the basic details of your Ubuntu system. The following items can be viewed: Device name Memory Processor Graphics OS Type (32-bit or 64-bit) Disk size

Figure 6-98. System Settings - Details - About

Clicking the Check for updates button will bring up the Ubuntu Software window. Software updates will be covered in Chapter 19. 6.17.2 Date & Time The Date & Time settings, Figure 6-99, allow you to control the date and time settings for you system. The Automatic Date & Time option will use the Network Time Protocol (NTP) to get the time from the Internet. Using NTP is the most accurate way to set the time on your system. The Automatic Time Zone option will use the Internet to get the time zone information.

Figure 6-99. System Settings - Date & Time

If the Automatic Date & Time option is disabled you can set the date and time manually, Figure 6-100.

Figure 6-100. System Settings - Date & Time - Manual time settings

If the Automatic Time Zone option is disabled you can set the timezone, Figure 6-101.

Figure 6-101. System Settings - Date & Time - Timezone

The Time Format option allows you to choose either 24-hour or AM/PM, Figure 6-102.

Figure 6-102. System Settings - Date & Time - Time format

6.17.3 Users The User settings, Figure 6-103, allow you to create new user accounts and administer existing user accounts. In the upper right hand corner of the window there is an Unlock button which you will have to click and provide your password prior to making any changes to a user account.

Figure 6-103. System Settings - Users

The usernames are listed at the top of the window with the information for the highlighted user account below. For each user account the following information is provided: Username Account type Password (hidden) Automatic Login Last Login The following subsections are covered in this section: 6.17.3.1 Change Password 6.17.3.2 Set Account Type 6.17.3.3 Language 6.17.3.4 Automatic Login 6.17.3.5 Last Login 6.17.3.6 Add User Account 6.17.3.7 Setting a User Picture 6.17.3.8 Renaming a User 6.17.3.9 Removing a User

6.17.3.1 Change Password To change a user’s password click on the box with 5 dots next to Password which will bring up the password change dialog box, Figure 6-104. As you enter the new password, the password strength bar will indicate the strength of the password. For security purposes you want to always create a strong password. Once you are done entering the new password and confirming the password by entering it again you must click Change to change the password.

Figure 6-104. System Settings - Users - Changing Password - Random password

If you are changing the password of another user on the system you can allow the user to change their password the next time they login or change the password. 6.17.3.2 Set Account Type To set the account type, make sure to unlock the User settings and click on the Account Type. The options are Standard and Administrator. 6.17.3.3 Language For other system users you can choose the default Language for the user. 6.17.3.4 Automatic Login Enabling Automatic Login will allow a user to access their account without having to provide a password. Automatic Login should not be enabled for security reasons.

6.17.3.5 Last Login For each account there is a history of system access. Highlighting an account and clicking Last Login at the bottom of the window will bring up the Account Activity window, Figure 6-105.

Figure 6-105. System Settings - Users - Account Activity

Using the arrow buttons on the right and left on the top of the window you can page through the history one week at a time. 6.17.3.6 Add User Account To add a user account click the Add User button at the top of the window. The Add User button appears after you Unlock the User window, Figure 6106.

Figure 6-106. System Settings - Users - Add User

The Add Account dialog box allows you to choose what type of user account to add, a standard user or an administrator, fill in the full name, and specify a username, Figure 6-107.

Figure 6-107. System Settings - User Accounts - Add Account

If you click the down arrow next to the Username a list of username suggestions will be displayed, Figure 6-108.

Figure 6-108. System Settings - Users - Add User

You can either allow the user to change their password on next login or you can set the password for the user.

As you enter the new password, the password strength bar will indicate the strength of the password. For security purposes you want to always create a strong password. Once you are done entering the new password and confirming the password by entering it again click the Add button at the top of the window to add the account. 6.17.3.7 Setting a User Picture Once an account is created you can choose a picture to associate with an account. Click on the outline of the head next to the account name to bring up the picture menu, Figure 6-109.

Figure 6-109. System Settings - Users - Choose a Picture

You can select a picture from the default library, select your own picture, or take a picture with the system’s built in camera if it has one. Once a picture has been selected, it will replace the default head outline. 6.17.3.8 Renaming a User

To rename a user account, unlock the User settings and click on the user account name. The username will now be editable. Type the new username and press Enter to complete the change. 6.17.3.9 Removing a User To remove a user account, highlight the account and press the Remove User button of the Users window. The Remove Account dialog box, Figure 6110, will give three options: Delete Files Keep Files Cancel

Figure 6-110-. System Settings - User Accounts - Delete an account

6.17.4 Default Applications The Default Applications settings, Figure 6-111, allow you to control what the default applications are for various functions and media. The following functions and media can be set: Web Mail Calendar Music Video Photos Next to each function or media type is a drop down menu that allows you to specify a default application for that media type.

Figure 6-111. System Settings - Details - Default Applications

7. NETWORK CONFIGURATION

7. Network Configuration The Network Configuration can be accessed via the System Settings or via the drop down menu in the upper right hand corner of the desktop, Figure 71.

Figure 7-1. Network Settings - Wired Settings

The following sections will be covered in this chapter: 7.1 Wired (Ethernet) 7.2 Wireless 7.3 VPN 7.4 Network Proxy

7.1 Wired (Ethernet) The Network settings are shown in Figure 7-2. If you are using a Wired

connection you will be able to enable and disable the connection using the ON/OFF switch on the right. You can setup a VPN connection and a Network Proxy.

Figure 7-2. Network Settings

Next to the ON/OFF switch is a small gear. Clicking on this gear will bring up the Wired configuration settings, Figure 7-3.

Figure 7-3. Network Settings - Wired - Details

The Wired settings window has 5 tabs: 7.1.1 Details 7.1.2 Identity 7.1.3 IPv4 7.1.4 IPv6 7.1.5 Security For the most part there is little to no network configuration required for your Ubuntu system unless you require more advanced configurations such as static IP addresses or VPN connections. Out of the box Ubuntu will autodetect Ethernet and wireless connections and automatically obtain an IP address from a Dynamic Host Control Protocol (DHCP) server, most likely your home router. For a wireless connections a password may be required to access a wireless network. 7.1.1 Details

The Details tab, Figure 7-4, will show the connection Link Speed, IPv4 Address, IPv6 Address, Hardware Address, Default Route, and the DNS server, if your computer is connected to a network. You can also configure the wired connection to connect automatically and to allow other users to use the connection.

Figure 7-4. Network Settings - Wired - Details

To delete the connection profile, click on the Remove Connection Profile button in the bottom right hand corner. 7.1.2 Identity Figure 7-5 shows the Identity tab for the Wired network connection. On this tab you can edit the name of the connection, see the MAC Address for the assigned Network Interface Card (NIC), clone the MAC address, and adjust the MTU. All of the items on this tab are advanced configuration options and will not be covered in this book. I do not recommend changing anything on this tab other than the connection name.

Figure 7-5. Network Settings - Wired - Identity

7.1.3 IPv4 Figure 7-6 shows the IPv4 tab of the Wired settings. On this tab you can configure the connection to use Automatic (DHCP), Link-Local Only, Manual, or Disable the connection. Most users will utilize DHCP to obtain an IPv4 address and will not need to make any changes to this tab.

Figure 7-6. Network Settings - Wired - IPv4

The following subsections are covered in this section: 7.1.3.1 Automatic (DHCP) 7.1.3.2 Manual 7.1.3.3 Link-Local Only 7.1.3.4 Disable 7.1.3.1 Automatic (DHCP) Automatic (DHCP) is the default setting for IPv4 and is the setting used by most Ubuntu Linux users. When utilizing DHCP, all of the necessary network parameters are provided over the network, either wired or wireless, by a DHCP server and no configuration is required by the user. 7.1.3.2 Manual The Manual setting allows for the assignment of a static IP address. A static IP address may be required in certain situations where a DHCP server is not

available or the system needs to always have the same IP address. You will need to obtain the IP address, network mask, gateway IP, and DNS server IP from your network administrator in order to complete the configuration. Figure 7-7 shows the IPv4 tab of the Wired settings with Manual selected. Once Manual is selected the Addresses section will become editable. Enter the IP address, Netmask, and Gateway for this connection. You will also need to add the IP address for your DNS server by turning Automatic Off and then entering the DNS IP address. If you have multiple DNS server addresses, separate the addresses with a comma. Once complete press Apply at the top of the window to save the connection configuration.

Figure 7-7. Network Settings - IPv4 - Manual

You can also manually enter Routes but this is an advanced feature that is not covered in this book. 7.1.3.3 Link-Local Only

Selecting Link-Local Only will cause your system to auto configure an IP address in the 169.254.0.0 Class B network, Figure 7-8.

Figure 7-8. Network Settings - IPv4 - Link-Local Only

Your system will only be able to communicate with other systems on the network also using Link-Local Only. 7.1.3.4 Disable Selecting Disable will disable IPv4 on the interface. 7.1.4 IPv6 Figure 7-9 shows the IPv6 tab of the Wired settings. IPv6 is a replacement for IPv4 but has not taken hold as fast as was originally expected. On this tab you can configure the connection to use Automatic, Automatic DHCP only, Link-Local Only, Manual, or Disable the connection. Most users will utilize IPv4 for their network connections and will not need to make any changes on this tab.

Figure 7-9. Network Settings - Wired - IPv6

The following subsections are covered in this section: 7.1.4.1 Automatic 7.1.4.2 Automatic DHCP Only 7.1.4.3 Link-Local Only 7.1.4.4 Manual 7.1.4.5 Disable 7.1.4.1 Automatic The IPv6 protocol has the ability to auto-detect the network that the system is connected to and automatically configure the IPv6 address accordingly based upon the Network ID, Subnet, and system MAC address. The Automatic setting is the default setting and is the setting used by most Ubuntu Linux users. 7.1.4.2 Automatic DHCP Only

When utilizing Automatic DHCP only, all of the necessary network parameters are provided over the network, either wired or wireless, by a DHCP server and no configuration is required by the user. 7.1.4.3 Link-Local Only Selecting Link-Local Only will cause your system to use the IPv6 Link Local address which is from the fe80:/64 network. All IPv6 capable system auto configure a Link Local address. 7.1.4.4 Manual The Manual setting allows for the assignment of a static IPv6 address. A static IPv6 address may be required in certain situations where a DHCP server is not available or the system needs to always have the same IPv6 address. You will need to obtain the IPv6 address, prefix, gateway, and DNS server IP from your network administrator in order to complete the configuration. Figure 7-10 shows the IPv6 tab of the Wired settings with Manual selected. Once Manual is selected the Addresses section will become editable. Enter the IP address, Prefix, and Gateway for this connection. You will also need to add the IPv6 address for your DNS server by turning Automatic Off and then entering the DNS IP address. If you have multiple DNS server addresses, separate the addresses with a comma.

Figure 7-10. Network Settings - IPv6 - Manual

Once complete press Apply in the top right hand of the window to save the connection configuration. 7.1.4.5 Disable Selecting Disable will disable IPv6 on the interface. 7.1.5 Security The Security tab of the Wired settings, Figure 7-11, allows the configuration of 802.1x protocol. 801.1x is a protocol that allows authentication of devices attempting to connect to a Local Area Network (LAN) and is beyond the scope of this book. Unless you are connecting to a network that requires 802.1x authentication you will normally not change any of the settings on this tab. If you do need to connect to an 802.1x protected network, consult your network administrator for the proper settings.

Figure 7-11. Network Settings - Wired - Security

7.2 Wireless If your system has wireless network functionality, Settings will include WiFi option, Figure 7-12.

Figure 7-12. Settings - WiFi

There will be a list of wireless access points that are in range of your system. Each wireless network will display the wireless access point name, a lock icon if authentication is required, and a signal strength indicator. In the top right hand corner of the window is the button to turn Wireless on and off as well as turn Airplane Mode on and off. The wireless network currently in use will have a check mark next to the wireless access point name. Next to the ON/OFF switch is a drop down menu with additional configuration options, Figure 7-13.

Figure 7-13. Settings - WiFi - Additional Configurations Options

The following subsections are covered in this section:

7.2.1 Details 7.2.2 Identity 7.2.3 Authentication 7.2.4 Hidden Network 7.2.5 Wi-Fi Hotspot 7.2.6 Known Wi-Fi Networks 7.2.1 Details Clicking the gear on the right of the current wireless connection will bring up the connection setting, Figure 7-14. The Details tab for a wireless network contains the following information: Signal strength Link speed Security IPv4 Address IPv6 Address Hardware Address Default route DNS There are check boxes at the bottom of the tab for connecting automatically and make the connection available to other users. You can force your system to purge the wireless network information for network by clicking Forget Connection in the bottom right hand corner.

Figure 7-14. Network Settings - Wireless Settings - Details

7.2.2 Identity The Identity tab for a wireless network, Figure 7-15, contains the following information: SSID BSSID MAC Address Cloned Address

Figure 7-15. Network Settings - Wireless Settings - Identity

7.2.3 Authentication If you try to access a wireless network that requires authentication you will be prompted with an authentication dialog box, Figure 7-16. To authenticate to the wireless network, type the password and click Connect. You can also choose to show the password while you are tying by clicking the Show password checkbox.

Figure 7-16. Network Settings - Wireless Settings - Authentication

7.2.4 Hidden Network Most wireless networks broadcast their Service Set Identifier (SSID) so that users can easily find the network. Some networks, however, do not broadcast their SSID as a security measure. In the case of a network that is hidden and does not broadcast the SSID, you will have to obtain the information from the network administrator. Using the information such as the Network name or SSID and the Wi-Fi security settings, you can connect to hidden wireless network, Figure 7-17.

Figure 7-17. Network Settings - Wireless Settings - Hidden Wi-Fi network

7.2.5 Wi-Fi Hotspot Using your Ubuntu system as a Wi-Fi Hotspot allows you to share a wired connection wirelessly with other systems such as a tablet or other laptop. In order for Wi-Fi Hotspot to work there has to be a wired connection (Ethernet) available. You can not share a wireless connection. Figure 7-18 shows the Wi-Fi Hotspot window. When you turn on Wi-Fi Hotspot you will not be able to use the wireless connection.

Figure 7-18. Network Settings - Wireless Settings - Turn On Wi-Fi Hotspot

Once enabled, your system will automatically assign a Network Name, Security, and Password which you will have to provide to anyone wanting to access your Wi-Fi Hotspot, Figure 7-19.

Figure 7-19. Network Settings - Wireless Settings - Wi-Fi Hotspot

When you turn off the Wi-Fi Hotspot you will be asked to confirm, Figure 720.

Figure 7-20. Network Settings - Wireless Settings - Stop Hotspot

7.2.6 Known Wi-Fi Networks The Known Wi-Fi Networks settings shows all of the Wi-Fi networks that you have connected to and used, Figure 7-21.

Figure 7-21. Network Settings - Wireless Settings - Known Wi-Fi Networks

You can force your system to forget the Wi-Fi network by selecting the checkbox next to the network name and clicking the Forget button in the bottom left hand corner.

Selecting the gear icon to the right of the network name will bring up the details for the wireless network, Figure 7-22. You can see when the network was last used and remove the network by click Forget Connection in the bottom right hand corner.

Figure 7-22. Network Settings - Wireless Settings - Known Wi-Fi Networks - Details

7.3 VPN To configure a VPN connection, you can click the + to the right of the VPN settings on the main Network settings, Figure 7-23.

Figure 7-23. Network Settings - VPN

You can either configure an OpenVPN, Point-to-Point Tunneling Protocol VPN, or input the VPN settings from a file, Figure 7-24. Most VPN

providers will provide a file that contains all of the configurations needed to setup a VPN.

Figure 7-24. Network Settings - Add VPN

7.4 Network Proxy A Network Proxy is a server that sits in between computers on a network and the Internet and acts as an intermediary for the computers when communicating with the Internet. The proxy will hide the internal IP addresses of the computers on the network and can be used to filter web traffic. To access the Network Proxy settings you will need to click the gear to the right of the Network Proxy on the main Network settings, Figure 7-25.

Figure 7-25. Network Settings - Network Proxy

The Network Proxy settings, Figure 7-26, allow you to configure a network proxy. You will have to contact your network administrator to find out if your network uses a Network Proxy. Most home networks do not use a network proxy. You will need to choose between Automatic, Manual, and Disable.

Figure 7-26. Network Settings - Network Proxy

The Automatic configuration method, Figure 7-27, allows for the configuration of a Network Proxy by providing a configuration URL that will tell your system where to pull the configuration information from. You will have to contact your network administrator to find out your configuration URL.

Figure 7-27. Network Settings - Proxy Settings - Automatic

The Manual configuration method, Figure 7-28, allows for the configuration

of HTTP, HTTPS, FTP, and Socks Host. HTTP is for normal web traffic. This is any website that starts with http:\\ in the URL. HTTPS is for encrypted SSL/TLS sessions. This is any website that start with https:\\ in the URL. FTP for is the File Transfer Protocol and is used to transfer files between computers. Socks Host is a SOCKS server that proxies TCP and UDP connections. A SOCKS proxy can handle more than just HTTP, HTTPS, and FTP. The Ignore Hosts tells your system which websites do not need to use the proxy server. Normally you put internal web servers on this list as the server are part of the same network that you system is on.

Figure 7-28. Network Settings - Proxy Settings - Manual

8. INSTALLING SOFTWARE

8. Installing Software One of the things I really like about Linux and especially Ubuntu is the amount of free software that is available. In the past you would have to search the Internet for software to install on your Linux system and go through very difficult installation procedures. Most Linux systems and especially Ubuntu make the installation of software very easy. 8.1 Ubuntu Software 8.2 Installing Software 8.3 Removing Software 8.4 apt-get

8.1 Ubuntu Software Ubuntu Software makes the task of finding and installing software on your system a snap. Ubuntu Software can be reached by clicking on the Ubuntu Software icon on the Launcher, Figure 8-1.

Figure 8-1. Ubuntu Software Icon

The Ubuntu Software main window, Figure 8-2, has tabs on the top for All , Installed, and Updates as well as a search bar. 8.1.1 All Tab 8.1.2 Installed Tab 8.1.3 Updates Tab 8.1.1 All Tab By default the Ubuntu Software window open in the All tab, Figure 8-2. The top section will show a featured software which in this example is Builder which is used by programs to create apps for Ubuntu.

Figure 8-2. Ubuntu Software

In the middle of the Ubuntu Software window there will be a list of software categories. Clicking on any of these categories will show a subset of the available software associated with that category. Figure 8-3 shows the Audio & Video category.

Figure 8-3. Ubuntu Software - All Software - Categories

8.1.2 Installed Tab The Installed tab, Figure 8-4, shows all of the software on your installed via Ubuntu Software. Next to each software package is a Remove button that allows you to uninstall the software.

Figure 8-4. Ubuntu Software - Installed

8.1.3 Updates Tab The Updates tab, Figure 8-6, shows the updates available for your system. The tab will have a number in red that indicates the number of available updates. Clicking on the Install All button next to each update will install the specific update or you can click the Install button in the top right hand corner of the window to install all of the updates.

Figure 8-6. Ubuntu Software - Updates

8.2 Installing Software Once you identify a software package you want to install, click on the software package and then click the Install button. Figure 8-7 shows software information screen about a popular software package named VLC, which is a media player.

Figure 8-7. Ubuntu Software Center - More Info

Before the software can be installed you must authenticate by providing your password, Figure 8-8.

Figure 8-8. Ubuntu Software Center - Authentication

Once you have authenticated, the installation will begin. When the installation is complete, the software will show as installed, Figure 8-9, the Install button will change to a Remove button which can be used to remove the software package. There will also be a Launch button that can be used to start the software.

Figure 8-9. Ubuntu Software Center

8.3 Removing Software To remove an installed software package find the software in the list of installed software and click the Remove button on the right hand side. You will have to authenticate in order to remove the software.

8.4 apt Apt is the Ubuntu command line software management tool. Apt stands for Advanced Packaging Tool. Apt is covered in Chapter 19.

9. E-MAIL

9. E-mail While most people today tend to get their email either on their smartphones or via a webmail service, some people still like to get their email via an email software client on their desktop or laptop. Ubuntu comes with an email software client named Thunderbird. While there are other email client software packages out there I am only going to cover Thunderbird in this book since it is the default. To find Thunderbird, open a search and type thun and the Thunderbird Mail icon will appear, Figure 9-1. Click on the Thunderbird Mail icon to open the email program.

Figure 9-1. Thunderbird - Search

If this is the first time you have run Thunderbird you will have to configure the email program to fetch your email from your ISP or email provider. You will be asked for your name, email address, and password for your email account, Figure 9-2. You will also have the option of allowing the software to remember your password to make accessing your email account easier. For security reasons I do not recommend selecting this option.

Figure 9-2. Thunderbird - Mail Account Setup

When you click Continue, Thunderbird will look in the ISP database for configuration information for your email provider and will present you with an option for IMAP or POP3, Figure 9-3.

Figure 9-3. Thunderbird - IMAP or POP3

IMAP is a protocol that allows access to folders on a remote email server. The email is stored on the server and your email client can access the email

when online and will retain an offline copy when not connected. When connected the email client will synchronize with the remote server so that the server and the email client have the same information. POP3 is a protocol that pulls a copy of the email from the server and stores it on the local desktop or laptop. The email client only connects to the server to retrieve the email. There is also an option for manual configuration of your email accounts. Thunderbird will also give you the option of setting up a new email address with gandi.net if you want to, Figure 9-4. You have the option of skipping this step and using your existing email account or configuring your email client later.

Figure 9-4. Thunderbird - New email address

Once the configuration is done and if the username and password are correct, you will be presented with your email, Figure 9-5.

Figure 9-5. Thunderbird

10. BACKUPS

10. Backups Backing up your Ubuntu system is a good idea to keep from losing important files and being able to restore files that are lost or accidentally deleted. The Backups settings allow you to configure backups for your system. To access Backups settings, you will need to search for the Backups application, Figure 10-1.

Figure 10-1. Search for Backups

The following sections will be covered in this chapter. 10.1 Overview 10.2 Folders to Save 10.3 Folders to Ignore 10.4 Storage Location 10.5 Scheduling

10.1 Overview The Overview settings, Figure 10-2 allows, you Restore from a previous backup and to Back Up Now. You can also turn backups on and off by using the slider in the top right hand side of the window.

Figure 10-2. System Settings - Backups - Overview

If this is the first time using Backups, you will be asked to install some additional software packages, Figure 10-3, when you either before a Backup or Restore for the first time..

Figure 10-3. System Settings - Backups - Install Packages

You will have to authenticate to install the software packages, Figure 10-4.

Figure 10-4. System Settings - Backups - Install Packages - Authentication

Once the software package installation is complete, you will be given the option to set a password for your backups, Figure 10-5. While using a password is not mandatory, it is highly recommended for security purposes.

Figure 10-5. System Settings - Backups - Password

If you choose to use a password you will be prompted to provide a password every time you do a Backup or Restore, Figure 10-6.

Figure 10-6. System Settings - Backups - Password

10.1.1 Restore To restore files, click on the Restore button on the Overview section. The Restore window allows you to choose from where to restore the backup from, Figure 10-7.

Figure 10-7. System Settings - Backups - Restore

The first option, Backup location, allows you to choose from various cloud locations, a network server, or a local folder. Figure 10-7 shows the Backup location as a Local Folder. Figure 10-8 shows the additional options for Backup location.

Figure 10-8. System Settings - Backups - Restore - Location

Depending upon the location you choose you may have to provide additional details to access the service. Once you choose the location and configure the appropriate option click Forward. The next window allows you to choose from when to restore, Figure 10-9. The backup location may have multiple backups taken a different dates and times. Once you choose a backup, click Forward.

Figure 10-9. System Settings - Backups - Restore From Where?

Next you will have to choose to restore the file to the original location or to a new location, Figure 10-10. Once you choose an option, click Forward.

Figure 10-10. System Settings - Backups - Restore to Where?

Next you will be given a Summary of actions to be taken. If everything is correct, click Restore, Figure 10-11.

Figure 10-11. System Settings - Backups - Summary

If the backup is encrypted you will have to provide a password to decrypt the backup.

Once the restore is finished, click Close, Figure 10-12.

Figure 10-12. System Settings - Backups - Restore Finished

10.1.2 Back Up Now To backup files, click on the Back Up Now button on the Overview section. If you configured Backups to use a password, you will have to provide the password before the backup will start, Figure 10-13. You can stop the backup by click either clicking Cancel or Resume Later.

Figure 10-13. System Settings - Backups - Backing Up

When the backup is complete you will get a Backup complete message at the top of the desktop, Figure 10-14.

Figure 10-14. System Settings - Backups - Backup completed

10.2 Folders to Save In the Folders to save settings, Figure 10-15, you can add and remove folders to include in your backup. By default your home folder is added to the backup.

Figure 10-15. System Settings - Backup - Folders to save

10.3 Folders to Ignore The Folders to ignore settings, Figure 10-16, allows you to exclude folders from the backup. By default the Trash and Downloads folders in your Home folder are excluded from backups.

Figure 10-16. System Settings - Backup - Folders to ignore

10.4 Storage Location The Storage Location settings, Figure 10-17, allow you to specify the

location to store the backup.

Figure 10-17. System Settings - Backup - Storage Locations

The Storage location drop down menu, Figure 10-18, allows you to choose from Google, Nextcloud, which is an online backup service, a Network server, or a Local Folder. If you choose Google or Nextcloud you will have to go to their website and create an account and add the account information to your Online Account Settings.

Figure 10-18. System Settings - Backup - Storage Locations - Options

10.5 Scheduling The Scheduling settings, Figure 10-19, allow you to schedule when you want your backup to occur and how long to keep backups.

Figure 10-19. System Settings - Backup - Scheduling

The Every option allows you to choose Day or Week. The Keep option allows you to choose At least six months, At least a year, or Forever.

11. USING THE TERMINAL OR COMMAND LINE INTERFACE (CLI)

11. Using the Terminal or Command Line Interface (CLI) While this book is a beginner book and most Linux beginners do not need to access the terminal or command line interface (CLI), no book on Linux would be complete without some discussion of the terminal. Today we live in a very graphical world as far as our computers and devices are concerned. From our computers to our tablets and smartphones there is not a lot you cannot do with our clicking or tapping on an icon or link. While this may be good for the average user, for the power user and administrator it causes a loss of a skill set that is very necessary, the use of the CLI. Linux is a very powerful operating system with a lot of tools that can be accessed without a graphical user interface (GUI) and in fact there may be times when a GUI is not even an option such as when you make a remote connect via SSH and are only given a CLI. Having the skills to navigate and operate in a CLI is a very important skill for a Linux administrator. The real power of Linux is found in the CLI. The CLI gives you direct access, with the proper permissions, to the configuration files that make Linux run. If you really want to be a Linux guru then you have to become comfortable in the CLI. I like to think of it like driving a car. When I learned how to drive a car my mom taught me on her stick shift car. While it may have been a little more difficult for a new driver to master the art of using a clutch, gas pedal, and stick shift, the lessons stayed with me even today. Now I can drive an automatic or stick shift. Compare this to a driver that learned on an automatic transmission, like my son. He has his license and is a very good driver but if I put him in a stick shift car he would not know what to do. The Linux CLI is like the stick shift and the GUI is like the automatic. The following sections are covered in this chapter: 11.1 Text only please 11.2 Bash

11.3 The Terminal Basics 11.4 Moving around on the CLI 11.5 Tab Autocomplete

11.1 Text only please For the most part, all of your interactions with the CLI will be using text entered via the keyboard. There are some programs that have a pseudographical look but there is no mouse and no pointing and clicking allowed. You will have to use the tab key and arrow keys to move through the options. When I was in highschool I took a business class that included using a typing tutor to learn how to not hunt and peck on the keyboard. The typing skills I learned have served me well and I can now type without looking at the keys. If you are going to spend any length of time on the CLI and plan to be a Linux administrator I would highly suggest investing some time and effort into learning how to type if you do not already know how.

11.2 Bash The Linux CLI is an interactive shell that accepts commands from the user and provides output on the same CLI. In most Linux distributions the default shell is the Bash shell. Bash stands for Bourne Again Shell. The Bourne Shell (sh) was a popular shell of Unix operating system that was released in 1977. The Bash shell takes elements of the Bourne Shell (sh) and combines it with some of the best elements from the Korn Shell (ksh) and the C Shell (csh). It was developed by Brian Fox for the GNU Project to replace the Bourne Shell. All of the commands and examples in this book are from the Bash shell.

11.3 The Terminal Basics Figure 11-1 shows the Terminal window or CLI. When using Linux distributions you can open a Terminal window by pressing Ctrl+Alt+T in the GUI or searching for the terminal application. You can also access the CLI remotely via a Secure Shell (SSH) session. SSH server configuration and connecting to SSH is covered in Chapter 22.

Figure 11-1. The terminal

Any time you open a terminal window you will get a terminal prompt. The terminal prompt includes some basic information about your system. The first part is usually the username of the currently logged on user followed by the @ symbol. Next part is the hostname of the system. What comes next depends on your Linux distribution. For some distributions the : character follows the hostname and for others it is a space. Next is the current location in the filesystem. The default location when first logging on to a Linux system is the current user’s home directory which is indicated by the ~ character. The last character in the terminal prompt is $ which indicates that a user is logged on. If the root user was logged on the last character would be a # character. The example below shows the Ubuntu terminal prompt. matt@localhost:~$ You use the terminal by typing commands in the interactive shell and pressing Enter to execute the command. All of the CLI examples in this book are made using Ubuntu unless otherwise indicated. The text typed by the user is shown in red, the output is shown in blue, and the CLI prompts are shown in black. Some of the

examples are screenshots that are used to preserve the spacing of the output. All CLI commands are case sensitive and all Bash commands are lowercase. The following commands are covered in this chapter: 11.3.1 echo 11.3.2 cat 11.3.3 history 11.3.4 help 11.3.5 date 11.3.6 cal 11.3.1 echo The echo command is a pretty basic Bash command that will help demonstrate how an interactive shell works. The echo command in its basic form takes a line of text and prints it back out to the command line also known as stdout, standard output. There is also stdin, standard in, which is the input you type on the command line and stderr, standard error, which is where errors are displayed which is also the command line. In the example below, the echo command is used to print a line of text back to command line.

There are other things you can do with the echo command such as redirect the output to a file instead of stdout. In the example below, the echo command is used to put the line of text into a file named testfile. There is no output to the command line or an indication that anything took place. This is typical for Linux CLI operations. If the command works there may not be any output.

The > character is what is known as a redirect because it redirects the output to somewhere else besides stdout. You can also use the >> characters to redirect as well. The difference between > and >> is that the > redirect will overwrite the contents of a file and the >> redirect will append or add to the contents of the file. 11.3.2 cat To see the contents of a file you can use the cat command. Just type cat and the name of the file and the contents of the file will be displayed on the CLI as in the example below.

You can display the contents of multiple files at the same time by listing more than one filename in the cat command. You must separate each filename by a space. The output will not indicate which output comes from which file.

11.3.3 history One nice feature of the Bash shell is the bash history file. Every command you type in the CLI is saved to the history file. You can see your history file by typing the history command.

Each command has a line number on the left hand side. You can execute a specific command again by typing the ! character followed by the line number from the history file.

You can also scroll backward and forward through the commands that you have typed using the arrow keys. For example, if you want to repeat a command that you used three commands ago press the up arrow three times and the command will appear on the CLI. You can press enter to execute the command again or edit the command. Using history -c will clear your command history. When using this command, you will enter the command history and -c to perform the operation. The - character indicates that what follows is an option to the command. The c option means to clear the history file. There must be a space in between the history command and the -c. 11.3.4 help The help command can be used to view the command usage and options for a command. In the example below, the help command is used to view the options for the history command.

11.3.5 date The date command displays the current system date and time.

11.3.6 cal The cal command displays the current month in a calendar format. The current day will be highlighted as in the example below.

The cal command with the -d option allows you to specify a specific month and year. The format for the -d option is YYYY-MM.

The cal command with the -y option allows you to specify a specific year and displays a calendar for the entire year as in the example below.

11.4 Moving around on the CLI The Bash shell has a number of shortcuts that you can use to move around on the line that you are currently working on. Inexperienced Linux users have a tendency to automatically go to either the backspace key or the arrow keys to move back and forth on the current line to correct a mistake or make a change. Knowing Bash shortcuts can make you much more efficient in the CLI and save you time. I highly recommend learning these shortcuts if you are going to use the CLI on a frequent basis. Below are the CLI shortcuts and their results.

11.5 Tab Autocomplete The tab key is another powerful tool in the CLI. Pressing the tab key after typing just a few characters will autocomplete a command that starts with the characters typed. If more than one command starts with the same characters all matching commands will be displayed. For example, if you type his and then press the tab key Bash will autocomplete history as this is the only command that starts with his. If you type hi and press the tab key you will get more than one choice as there are multiple commands that start with hi. If you make your first letter or letters too ambiguous such as just typing the letter c and pressing tab you may get more possibilities than you wanted. In the example below, there are 194 commands that start with the letter c so Bash is asking if you really want to display all 194 possibilities. If you want to see all 194 possibilities press y or else press n and trying adding more letters to narrow down the possibilities.

12. WORKING WITH FILES AND DIRECTORIES

12. Working with Files and Directories In a Linux system, everything is a file. Files are files, directories are files, and devices are files. In this chapter we will examine the basics of the Linux file system and how to work with the different types of files and directories. The following sections are covered in this chapter: 12.1 The Linux file system 12.2 Linux File Types 12.3 Moving around the file system 12.4 Listing Files 12.5 Making Files and Directories 12.6 Removing Files and Directories 12.7 File Permissions 12.8 Copying and Moving Files and Directories 12.9 Finding Files and Directories 12.10 Zipping and Unzipping Files 12.11 Links 12.12 File information

12.1 The Linux file system The Linux file system uses a hierarchical tree structure that starts with the root directory which is represented by the / character in Figure 12-1. All other directories are nested under root. Not all directories are shown. In the Linux file structure every directory under the root directory has a parent. For example, the root directory is the parent for all of the directories under root, and the home directory is the parent for all of the home directories.

Figure 12-1. The Linux file system

The example below shows the ls command run in the root directory of an Ubuntu system. The ls command is used to list the contents of the current directory, which in this example is the root directory.

Below is a list of the most common Linux directories and their function. /bin - Holds programs that can be accessed by the system, the root user, and normal system users. /boot - Holds the system startup files and the system kernel, vmlinuz. /cdrom - Holds the disk when a CD or DVD is inserted into the system. /dev - Holds device files which represent all of the hardware on the system. /etc - Holds system configuration files. /home - Holds the home directories for system users. /lib64 - Holds library files for 64-bit programs.

/lost+found - Holds orphaned files. /lib - Holds library files for programs. /media - Holds mount points for removable media. /mnt - Directory for mounting filesystems. /opt - Holds third party software. /root - The home directory for the root user. /run - Holds information about the running system. /proc - A virtual filesystem that provides kernel and process information. /sbin - System files. Can only be used by the system or root. /srv - Holds data on services provided by the system. /sys - A virtual filesystem that holds data about and allows modification of system devices. /tmp - Holds temporary files. /usr - Holds all of the user programs, libraries, and documentation. /var - Holds variable data such as system logs.

12.2 Linux File Types The Linux file system has several different file types. Figure 12-2 lists the file types and their corresponding symbol.

Figure 12-2. File types

Now that you know what the file types and symbols are, let’s look at where you can see the file types and their symbols. When you list files using the ls command with the -l option, long list, you will be able to see the file types. The example below shows the output of the ls -l command. There is one file named myfile, one link named myfile2, and one directory named mydir.

The output includes the following information about the directory mydir. drwxr-xr-x In this output the first d character means that this is a directory. The output of the ls -l command includes the following information about the file myfile on the left hand side.

-rw-r--r-In this output the first - character on the left means that this is a regular text file. The output includes the following information about the link myfile2. lrwxrwxrwx In this output the first l character means that this is a link. More on links later.

12.3 Moving around the file system When using the Linux operating system from the CLI, understanding the filesystem structure and knowing how to move around in the file system is very important. The base of the file system is the root partition which is represented by the / character. All other directories are located under the root directory. Do not get the root directory confused with the root user which is the administrator. There also is a directory named root which is the home directory of the root user which is located off the root of the file system. The following subsections are covered in this section: 12.3.1 Where am I? 12.3.2 pwd 12.3.3 cd 12.3.4 Filesystem shortcuts 12.3.1 Where am I? Every user is given a home directory on a Linux system. When you open the CLI you will be taken to your home directory by default. In the example below, the home directory is represented by the ~ character in the CLI prompt.

12.3.2 pwd The pwd command, which stands for print working directory, is used to print the current working directory to the CLI. This allows you to see exactly where you are in the file system. The example below shows the use of the pwd command from the user’s home directory. In the output, /home/matt, is the absolute path since it starts with the / character which represents the root directory. It is called the absolute path since it indicates the current location absolutely from the root directory.

12.3.3 cd The cd command, which stands for change directory, is used to move between directories in the file system. You can use the absolute path or the relative path to specify a location to change to with the cd command. The relative path does not start with the / character and indicates a location relative to the current location. For example, if you want to change from your home directory to a directory named myfolder in your home directory you would use the cd command with just the directory name myfolder as in the example below.

In the command above myfolder is a relative path as it was relative to the home folder. If the home folder has a directory named myfolder you will be moved into that directory. In most Linux distributions the CLI prompt changes as you move through the file structure. The current location is part of the command line prompt. In

the example below, the ~ character indicates the current location is the current user’s home directory.

The default for most Linux distributions is to start the CLI in the user’s home directory. When the current location is changed with the cd command the prompt will change accordingly. In the example below, the cd command is used to change to the myfolder directory which is located in the user’s home directory. The command prompt changes to ~/myfolder.

You can also use the absolute path to make the same directory change. In the example below, an absolute path starting from / is used to change to the myfolder directory.

As you can see, the result is the same but using the absolute path you can get to myfolder from anywhere in the filesystem. Using the relative path you have to already be in the home directory. Also notice that the command prompt still uses the ~ character to indicate the home directory even though the absolute path was used with the cd command. 12.3.4 Filesystem shortcuts Linux has several file system shortcuts that will help you move around the file system or indicate directories in the file system. The following subsections are covered in this section: 12.3.4.1 Going Home 12.3.4.2 Root

12.3.4.3 Go back from where you came 12.3.4.4 Moving Back 12.3.4.5 Stay right here 12.3.4.1 Going Home The ~ character means the current user’s home directory. When used in conjunction with the cd command it will take you to the current user’s home directory. The example below starts in the root directory, /, and verifies this with the pwd command. Then the cd ~ command is used to move to the home directory and verifies this with the pwd command.

No matter where you are in the file system, cd ~ will always take you to your home directory. Please note that you must put a space between the cd command and the ~ character. 12.3.4.2 Root The / character means the root directory. When used in conjunction with the cd command it will take you to the root directory. The example below starts in the user’s home directory, /home/matt, and verifies this with the pwd command. Then the cd / command is used to move to the root directory and verifies this with the pwd command.

12.3.4.3 Go back from where you came The - character means the last directory and can be used to go back to the directory you just left. In example below starts in the /home/matt/myfolder directory and moves to the root directory using the cd / command and then moves back to the /home/matt/myfolder directory using the cd - command.

12.3.4.4 Moving Back The ../ set of characters is used to move back one directory in the filesystem. If you are in a directory and want to back up one directory in the tree you can use ../ to with the cd command. The example below starts in the /home/matt/myfolder directory. The cd ../ command is used to move back one directory to the /home/matt directory.

You can also combine multiple ../ sets together to move back more than one directory. The example below starts in the /home/matt/myfolder directory. The cd ../../../ command is used to move back three directories to the / or root directory.

12.3.4.5 Stay right here The ./ characters mean the current directory. The ./ shortcut is usually used when executing scripts in the current directory.

12.4 Listing Files Another useful command is the ls command, which stands for list, is used to list the contents of a directory. The following subsections are covered in this section: 12.4.1 Basic list 12.4.2 Long list 12.4.3 List all files 12.4.1 Basic list The ls command used without any options gives a list of the file names only

from left to right.

12.4.2 Long list Using the ls command with the -l option, which stands for long list, provides additional details about files. The long list option provides additional details such as file permissions, file owner, group, file size, and last modified date.

Figure 12-3 shows the columns that are shown using the ls -l command.

Figure 12-3. ls -l columns

Permissions will be covered covered in more detail later in this chapter. Hard links show how many links or shortcuts to the same inode exist. Inodes and Hard links will be covered in more detail later in this chapter. The Owner is normally the user that created the file unless the owner of the file is changed. The Group is normally the main group that the user that created the file

belongs to unless the group is changed. The Size of the file is shown in bytes. The Last modified date and time are the last time the file was modified or edited. Just viewing the file will not change this date and time. The Filename shows the name of the file. 12.4.3 List all files Files in the Linux filesystem can be hidden by starting the filename with a . character. To see hidden files with the ls command you have to add the -a option which stands for all files. In the example below the ls command is used with the -la option added to view hidden files that start with the . character.

12.5 Making Files and Directories There are many ways to create files and directories in Linux. In this section we will go over some of the common ways to use the CLI to create files and directories. The following subsections are covered in this section: 12.5.1 touch

12.5.2 mkdir 12.5.2 Redirection 12.5.1 touch The touch command is a quick and easy way to create a blank file. In the example below, the touch command is used to make three files. The ls -l command is used to list the files. Notice that all of the files have a 0 in the size column as the files are empty.

You can also touch an existing file which will change the last modified date but will not change anything in the file. 12.5.2 mkdir In any filesystem, you will want to be able to make a directory or folder to hold your files. The mkdir command will allow you to make a directory in Linux. In the example below the mkdir command is used to make a new directory named myfolder in the current user’s home directory, the cd command is used to move into the new directory, and the pwd command is used to verify the location.

12.5.2 Redirection Redirection can be used to create files by taking the output of a command and sending it to a file instead of the CLI. If the file does not exist it will be created. In the example below the ls command is used to verify the contents of the directory, the echo command is used with the redirect character > to redirect text to a file, the ls command is used to verify the file was created, and the cat command is used to verify the contents of the file.

12.6 Removing Files and Directories There are many ways to remove or delete files and directories in Linux. In this section we will go over some of the common ways to use the CLI to remove files and directories. The following subsections are covered in this section: 12.6.1 rm 12.6.2 Wildcards 12.6.3 Ranges 12.6.4 rm -r 12.6.5 rmdir 12.6.1 rm The rm command, remove, can be used to remove both files and directories from the filesystem. In the example below, the ls command is used to list the files in myfolder,

the rm command is used to remove a file named myfile1, and the ls command is used to verify that the file has been removed.

Be careful when using the rm command. Most Linux distributions do not ask for confirmation when using the rm command so once the command is executed the file or directory is gone. You can add the -i option to force the rm command to ask first before deleting the file as in the example below. To remove the file answer y or n to not remove the file.

12.6.2 Wildcards The rm command can use the wildcard characters * and ? to delete more than one file at a time. The wildcard character * The example below shows the rm command being used to delete all files that start with myfile and end with any number of characters. Since the * wildcard characters is used, myfile* matches all of the files that start with myfile.

The example below shows the rm command being used to delete all files that start with myfile and end with any one character. Since the ? wildcard characters is used the myfile? does not match all of the files that start with myfile.

12.6.3 Ranges You can use square brackets [ ] to define a range or characters, either letters or numbers. In the example below, the range is [2-5] so myfile2, myfile3, myfile4, and myfile5 will be deleted but myfile1 and myfile6 will not be deleted.

In the example below the range [b-e] is used with a wildcard.

12.6.4 rm -r The rm command can also be used to remove directories. By default a directory has to be empty before it can be deleted using the rm command unless the -r option is used. The -r option stands for recursive which means the rm command will go into the directory specified, delete all of the files in

the directory, then delete the directory. In the example below, the myfolder directory has three files. If the rm command is used without any options you will get an error since myfolder is a directory. You must use the -r option to delete the files and the directory.

If the directory is empty you can use the -d option, which means directory, to delete an empty directory. If the directory is not empty you will get a Directory not empty error. 12.6.5 rmdir The rmdir command is used to remove an empty directory. The rmdir command does not have a -r option like the rm command to remove a directory with files so if you want to remove the directory and the files with one command you will need to use the rm -r command. In the example below, the rmdir command is used to remove the empty myfolder directory.

12.7 File Permissions The following subsections are covered in this section: 12.7.1 Sticky Bit 12.7.2 Changing Permissions 12.7.3 Changing the owner 12.7.4 Changing the group Each file and directory in a Linux file system has three sets of permissions, owner, group, and others. Each set of permissions has three permission settings, r = read, w = write, and x = execute. Figure 12-4 shows the permissions for the Linux file system.

Figure 12-4. Linux file system permissions

The example below shows the output of the ls -l command on a file named myfile1.

The file myfile1 is a regular file with the owner having read and write permissions, rw- , the group having read and write permissions, rw- , and others having read permissions, r--. Any time a permission is not set a character is put in place of the permission. In this case the execute permission is missing from the owner and group and the write and execute permissions are missing from the others. Next to the permissions in the ls -l output is the number of links a file has, the owner of the file, the group owner, the size of the file, last modified date, and the file name. Figure 12-5 is a breakdown of the ls -l output for myfile1.

Figure 12-5. ls -l output

12.7.1 Sticky Bit The Sticky Bit is a special permission that can be assigned to a file or directory that means a file or directory can only be deleted by the owner or root. By default a file or directory can be deleted by any user who has read and write permissions. The Sticky Bit shows up in the file permissions as a T on the right hand side. The following example shows the file permissions with the Sticky Bit set:

12.7.2 Changing Permissions Now that you understand file and directory permissions let’s take a look at how to change file and directory permissions. The following subsections are covered in this section: 12.7.2.1 chmod 12.7.2.2 Setting the Sticky Bit 12.7.2.1 chmod The chmod command is used to change permissions on a file or directory. There are two ways to use the chmod command, with letters or numbers. Using letters has three parts, the target, the operation, and the permission. Figure 12-6 shows the chmod command target designators and their meaning.

Figure 12-6. chmod target designators

Figure 12-7 shows the chmod command operators and their meaning.

Figure 12-7. chmod operators

Figure 12-8 shows the chmod command permissions and their meaning.

Figure 12-8. chmod permissions

To add a permission or remove a permission from a file you use the chmod command with the target, operator, and permission. In the example below, the execute permission is added for the owner of myfile1. The ls -l command is used to examine the permissions of myfile1 which are rw-rw-r--. The chmod command is used with the u+x option to add the execute permission for the owner with the resulting permissions of rwxrw-r--.

The example below shows the execute permission for all, owner, group, and others, being added to myfile1. The ls -l command is used to examine the permissions of myfile1 which are rw-rw-r--. The chmod command is used with the a+x option to add the execute permission for all and the resulting permissions are rwxrwxr-x.

The example below shows the write permission for the group being removed from myfile1. The ls -l command is used to examine the permissions of myfile1 which are rwxrwxr-x. The chmod command is used with the g-w option to remove the write permission for the group and the resulting permissions are rwxr-xr-x.

You can also combine operations together to change more than one permissions at a time on the same file. In the example below, the chmod command is used with the a+x and g-w options separated by a comma. Be

sure not to put any space before or after the comma or the command will fail.

You can also combine targets and permissions. In the example below, the u and g targets are combined and the w and x permission are combined. The chmod ug-wx command below removes the write and execute permissions from the owner and group for myfile1.

The other method for using the chmod command is with numbers. In this method each permission is assigned a numerical value as seen in Figure 129.

Figure 12-9. read, write, execute

You can assign a single permission, such a read, using the number 4 or multiple permissions by adding the numbers together. The read and write permissions together would be 4+2=6. All permissions together would be 4+2+1=7, Figure 12-10. To set no permissions use a 0.

Figure 12-10. read, write, execute combinations

Each file or directory has 3 sets of permissions, owner, group, and others. When using the numerical method all three sets have to be accounted for. In the example below, the chmod command is used with the 746 option to set the permissions on myfile1 to rwxr--rw- using the numerical method. The 7 means read, write, and execute, the 4 means read, and the 6 means read and write.

12.7.2.2 Setting the Sticky Bit There is one other permission that can be set using the chmod command, the Sticky Bit. To set the Sticky Bit using the letter method use the following command: chmod +t To set the Sticky Bit using the number method add a 1 to the front of the permission: chmod 1744 The example below shows the Sticky Bit being set for myfile1. The T at the end of the permissions means the Sticky Bit is set.

12.7.3 Changing the owner

Now that you understand how to change file and directory permissions let’s take a look at how to change the owner of a file. The owner of the file is set when the file is created. The owner is usually the person that created the file. There may be times when you want to change the owner of a file in order to give someone else control of the file. To change the owner of a file you use the chown command. The basic syntax for the chown command is chown newuser filename. The chown command requires root permissions to work so you will have to use the sudo command. In the example below, the ls -l command is used to examine the current owner, the chown command is used to change the owner of myfile1 from matt to jsmith, and the ls -l command is used to verify the change. Even though the owner was changed to jsmith the group owner still remains the same.

12.7.4 Changing the group When a user is created in Linux, a logon group with the user’s name is also created. This group has one member, the user. Any files created by a user get the user’s logon group assigned as the group owner by default. If you want to allow multiple users to have access to a file the best way is by using a group. To change the group owner of a file you use the chgrp command. The basic syntax for the chgrp command is chgrp newgroup filename. The chgrp command requires root permissions to work so you will have to use the sudo command.

In the example below, the ls -l command is used to examine the current group owner, the chgrp command is used to change the group owner of myfile1 from matt to students, and the ls -l command is used to verify the change. Any users that are members of the students group will now will be able to access the file even though jsmith is the owner.

12.8 Copying and Moving Files and Directories It may be necessary to copy or move files and directories from time to time. The Linux command line interface has several commands that can be used to copy or move files and directories. The following commands are covered in this section: 12.8.1 cp 12.8.2 mv 12.8.1 cp The cp command is used to copy files and directories. The basic syntax for the cp command is cp filename newfilename. The cp command may require root permissions to work depending upon the permissions of the file so you may have to use the sudo command. The following subsections are covered in this section: 12.8.1.1 Copy a file to the same directory 12.8.1.2 Copy a file to a different directory 12.8.1.3 Copy a file from one directory to another 12.8.1.4 Copy a directory

12.8.1.1 Copy a file to the same directory In the example below, the ls command is used to list the current files, the cp command is used to copy myfile1 to file2 in the current directory, and the ls command is used to verify the file copy. In this example the cp command is used to make a copy of the file and give it a new name.

12.8.1.2 Copy a file to a different directory The cp command can also be used to copy a file to a different directory. In the example below the cp command is used to copy myfile1 to the /tmp directory. The cd command is used to change to the /tmp directory and the ls command is used to verify the file copy.

When using the cp command to copy a file to a different directory you can omit the filename in the new location and the new file will have the same name as the original. You can also give the new file a new name when copying it to a different directory. 12.8.1.3 Copy a file from one directory to another You can copy a file from one directory to another without being located in either directory by using paths, either relative or absolute. In the example below the cp command is used to copy /tmp/myfile1 to the

myfolder directory in the home folder, ~/ , and name the new file myfile3. The ls command is used to list the contents of myfolder without changing to the myfolder directory. In this example the working directory was neither the copy from nor the copy to location so relative and absolute paths had to be used with the cp command. Absolute paths always start with the / character indicating the root directory and specify the absolute location in the file system. The ~ character in the prompt means the current location is the user’s home directory.

12.8.1.4 Copy a directory Copying a directory requires the cp command with the -r option, which means recursive. When copying a directory, the actual directory, any files in the directory, and any other subdirectories and files in those subdirectories need to be copied. The -r option makes the cp command examine the directory being copied and copy all files and subdirectories. In the example below, the cp command with the -r option is used to copy the myfolder directory directory to the /tmp directory. The cd command is used to change to the /tmp/myfolder directory, and the ls command is used to verify the cope was successful.

12.8.2 mv

The mv command is used to move files and directories. The mv command can also be used to rename a file. The difference between the cp and mv commands is that the mv command creates a copy in the new location and deletes the original file or directory while the cp command retains the original file or directory. The basic syntax for the mv command is mv filename newfilename. The following subsections are covered in this section: 12.8.2.1 Move a file 12.8.2.2 Move a directory 12.8.2.1 Move a file In the example below, the ls command is used to examine the current directory, the mv command is used to move myfile1 to the /tmp directory and retain the original filename, and the ls command is used to verify that the file has been moved to the /tmp directory and that the file myfile1 no longer exists in the current directory.

12.8.2.2 Move a directory The mv command can also be used to move directories. The mv command does not require any options to move the directory and files in the directory. In the example below, the mv command is used to move the myfolder directory from the current directory to the /tmp directory. The ls command is used to verify the files have been moved.

12.9 Finding Files and Directories Finding files and directories in Linux is a fairly easy task. There are a couple of commands that can assist you in finding what you are looking for. The following subsection are covered in this section: 12.9.1 find 12.9.2 locate 12.9.3 locate versus find 12.9.4 which 12.9.1 find The find command is one of the commands used to find files and directories in the Linux filesystem. The basic syntax of the find command is find starting directory -name filename. In the example below, the find command is used to find the file named myfile1 in the home directory, ~/.

The output of the find command shows the absolute path of the files found. In this example the starting directory is set to the home directory, ~/, but entire filesystem can be searched by using the root directory, /, as the starting directory. There are several options to the find command that can be used to narrow the

search for files. The -mmin option, modified minutes, can be used to search for files that have recently been modified in a specified number of minutes. In the example below, there are two files named myfile2. One of the myfile2 files is modified using the echo command to add text to the file thus changing the last modified date of the file. The find command is then used to find the file named myfile2 that has been modified within the last 10 minutes. The -10 after the -mmin option means in the last 10 minutes. The other time options for time would be +10 for greater than 10 minutes and 10 for exactly 10 minutes.

You can also search for files based upon the owner of the file using the -user option. In the example below, there are two files named myfile2. The owner of one of the files is matt and the other file is owned by jsmith. The find command is used with the -user option to search for the myfile2 file that is owned by jsmith.

12.9.2 locate Another way to find files in the Linux file system is using the locate

command. The locate command takes advantage of an index or database of all the files in the Linux filesystem so the locate command can find files much faster than the find command. In the example below the locate command is used to find the file myfile2.

12.9.3 locate versus find There is a major difference between the locate and find commands besides the speed. As mentioned before, locate uses an index of files on the system, while find actually looks at all of the files in the filesystem. The index that locate uses to search for files needs to be updated before locate can find a file. 12.9.4 which The which command can be used to find the location of commands in Linux. In the example below the which command is used to find the location of the echo command.

12.10 Zipping and Unzipping Files In Linux there are several ways to zip or compress files. This section will cover the most common methods which are creating a tarball with the tar command, zipping files with zip, gzip, and bzip commands, and unzipping files with gunzip, unzip, and tar.

The following subsections are covered in this section: 12.10.1 tar 12.10.2 gzip 12.10.3 zip 12.10.4 gunzip 12.10.5 unzip 12.10.6 tar to unzip 12.10.1 tar The tar command creates an archive, also known as a tarball, which is nothing more than taking a group of files and putting them together in one file. You can also compress the archive using the bzip command. The basic syntax or the tar command is tar -options archivename files_to_archive. In the example below the tar command is used to create a tarball name mytarball of all files that start with myfile and zip the archive with the bzip command. The options used with the tar command are -c create an archive, z compress, -v verbose , and -f filename of the archive. The resulting file is named mytarball.tr.bz. The .tr indicates a tarball and the .bz indicates a file zipped by bzip. All of the original files remain in the directory.

12.10.2 gzip When using the gzip command you just tell the command which file to zip. The basic syntax to zip a single file is gzip filename. In the example below, the gzip command is used to zip myfile1. The output file is named myfile1.gz and the original file is no longer in the directory.

The basic syntax to zip multiple files is gzip -c filenames > archivename In the example below, the gzip command is used to zip myfile1 to myfile5. The output file is named myfile.gz and the original files remain in the directory.

12.10.3 zip The zip command can be used to zip files which can be shared with other operating systems. The basic syntax of the zip command is zip archivename filenames. The example below shows the zip command being used to zip myfile1 to myfile5. The output file is myfiles.zip.

12.10.4 gunzip The gunzip command can be used to unzip files that end in .gz. The basic syntax of the gunzip command is gunzip archivename. The example below shows the gunzip command being used to unzip the archive myfile1.gz.

12.10.5 unzip The unzip command can be used to unzip zip files that end in the .zip extension. The basic syntax of the unzip command is unzip archivename. The example below shows the unzip command being used to unzip the archive myfiles.zip. The files myfile1 to myfile5 are unzipped and the zip archive is still in the directory.

12.10.6 tar to unzip The tar command can be used to unzip zip files that end in .tar.bz. The basic syntax of the tar command to unzip a file is tar -xvf archivename.

The example below shows the tar command being used to unzip the archive mytarball.tr.bz.

12.11 Links In Linux links are like shortcuts for the command line but before we can discuss links we have to talk about inodes. The following subsections will be covered in this section: 12.11.1 Inodes 12.11.2 Hard Link 12.11.3 Soft Link 12.11.1 Inodes Each file in the Linux filesystem has an inode. Inodes store the basic information about a file in the Linux filesystem. The following information is found in an inode for a file: Location of the file on the hard drive File type

Permission Owner Group File size File access time File change time File modification time File deletion time Number of links Did you notice something missing from the list? The filename is not part of the inode information. This is because the filename is just a link to an inode. The filename is associated with an inode in the directory. The inode points to the actual file contents. A directory is nothing more than a file that lists the filenames and inodes associated with the directory. You can view the inodes associated with a filename by using the ls command with the -i option. The example below shows a listing of files with the inodes in the left hand column. The -l option was included with the ls command to generate a long list. Each file has a unique inode shown on the left hand side.

12.11.2 Hard Link It is possible to have a link to a file that shares the same inode as the original file. This operates much like a shortcut in other operating systems. The hard link allows you to give the same inode two or more names at the same time.

The basic syntax for creating a hard link is ln target linkname. In the example below, the ln command is used to create a hard link to the myfile1 file named myfile1link. Both myfile1 and myfile1link have the same inode number as seen using the ls -li command.

If the original myfile1 file is deleted the file will still exist under the myfile1link name since both the myfile1 and myfile1link pointed to the same inode. 12.11.3 Soft Link Another type of link is called a soft link. A soft link is truly like a file shortcut. A soft link does not have the same inode as the original file. A soft link just points at the original file. If the original file is deleted the soft link will no longer work. In the example below, the ln command is used with the -s option to create a softlink to myfile1 named myfile1softlink. When viewed with the ls -li command, the inodes are not the same, the file type is listed as l for link, and there is a pointer myfile1softlink -> myfile1, that shows the link’s relation to the original file.

Another difference between hard and soft links is that a soft link can be made to a directory but a hard link cannot. You can delete both hard and soft links using the rm command just like regular files.

12.12 File information Linux has commands that provide information about files and directories. The following subsections are covered in this section: 12.12.1 file 12.12.2 stat 12.12.1 file The file command is used to test a file and find out what type of file it is. In the example below the file command is used to test three different files. The first file, myfile1 is an empty file. The second file, myfile1softlink, is a symbolic link to myfile1. The third file, myfile2, contains ASCII text.

12.12.2 stat The stat command is used display filesystem information about a file or directory such filename, size, number of blocks used, inode, permissions, owner, group owner, last access date and time, last modify date and time, and the last change date and time. The example below shows the stat command used to display the file system information about the file myfile1.

13. WORKING WITH USERS AND GROUPS

13. Working with Users and Groups User and groups are an integral part of the access control system in Linux. A user account is required to be able to login to a Linux system. Groups are used to control access to files for multiple users at the same time. The following sections are covered in this chapter: 13.1 Users 13.2 Root User 13.3 Users 13.4 Groups 13.5 Modifying Users

13.1 Users On a Linux system, a user account is required in order to login to the system. For the most part you will be using a normal user account which is an account without any special privileges. Using a normal user account for everyday system use is a good security practice. Using a root account for everyday system use can lead to a compromise of the system. When logged in as a normal user, your command prompt will end in a $ character by default. In the example below, the command prompt ends in a $ so this is a normal user account. matt@matt-laptop:~$

13.2 Root User The root user is the administrator of a Linux system, also known as the superuser. The root user has full control of the entire system and can make configuration changes. Using the root account for normal everyday system use is dangerous because any program that is launched by the root user will have root level privileges. If you as the root user receive an email with a malicious attachment and open the attachment you will be running malware

with root privileges which will quickly lead to a compromised system. On an Ubuntu Linux system, the root user does not have a password set and cannot be used until the root user password is set. To set the root user password you have to have root level privileges. The following subsections are covered in this section: 13.2.1 sudo 13.2.2 su 13.2.3 Using su 13.2.1 sudo As a normal user on a Linux system you need to have the ability to elevate your privileges to root level to perform certain tasks, such as setting the root user password. The sudo command, which stands for superuser do, will give you the root level permissions you need. Not every user can use the sudo command. When you installed Linux, the installation script may have asked you to create a user which is automatically added to the proper group, sudo, to be able to use the sudo command or you were asked if you want to make the user an administrator. More on groups later. When installing Ubuntu, the account you setup during the installation is automatically made part of the sudo group. If you want to give additional users sudo privileges you can just add them to the sudo group using the usermod command covered later in this chapter. 13.2.2 su There may be times when you want to switch over to the root account for a period of time to perform configurations and there are times when you have to switch to the root account as sudo will not work. The su command allows you to switch to the root account in the CLI. When installing Ubuntu the root account is not configured. If you want to

use the su command to switch to root you will have to set the root account password using the passwd command first. In the example below the passwd command is used to set the root password.

13.2.3 Using su Now that the root user password has been set you can logon as the root user. Instead of logging off and on again you can use the su command which will put you into a root shell. In the example below, the su command is used to access a root shell. You will be asked for the root password. When you use sudo you are using your own password. When you use the su command to become root you have to provide the root user’s password. You can tell that you are in a root shell by the # character at the end of the command prompt and the word root at the front of the command prompt.

To exit the root shell back to your own shell you just use the exit command. In the example below, the exit command is used to revert back to a user shell. Notice the change in the command prompt from # to $ and the username at the beginning of the command prompt.

The su command can also be used to switch to another user's shell. In the example below, the su command is used to switch user shells. The password required is the password of the user you are switching to. Since the new shell is a normal user shell the $ character does not change but the name at the front of the command prompt does.

13.3 Users In this section we will cover the administration of user accounts on a Linux system via the CLI. The following subsections are covered in this section: 13.3.1 useradd 13.3.2 userdel 13.3.3 passwd 13.3.4 passwd file 13.3.5 shadow file 13.3.1 useradd The useradd command is used to add users to a Linux system. The basic syntax of the useradd command is useradd -options username. One of the most common options with the useradd command is -m which tells the useradd command to create the user’s home directory when creating the account. Without a home directory, users will not be able to login to the system via the GUI, however command line access is still permitted. The example below shows the useradd being used to add a user named user1. The useradd command requires root level access so the sudo command is used.

A user created with the useradd command will not have a password until it is set with the passwd command. 13.3.2 userdel The userdel command is used to delete users from a Linux system. The basic syntax of the userdel command is userdel -options username. The most common userdel option is -r which will remove all of the user’s files and home directory. In the example below, the userdel command is used with the -r option to delete user1. There is no mail directory for user1 so the user1 mail spool not found error is displayed. The userdel command requires root level access so the sudo command is used.

13.3.3 passwd To change a user’s password you can use the passwd command. Notice that word is abbreviated so the command is passwd not password. In the example below the passwd command is used to change the password for the user jsmith.

13.3.4 passwd file

The passwd file holds the listing of all users on a Linux system. The passwd file is located in the /etc directory which is where all of the configuration files for a Linux system are located. Any user can look at the contents of the passwd file as there are no actual passwords in the passwd file. In the past the passwords were located in the passwd file but this was deemed a security risk so the passwords have been moved to the shadow file. More on the shadow file later. When viewing the passwd file there is usually more data than can be displayed on a single page in the CLI. To overcome this problem you can pipe the output of the cat command to another command that will allow you to view one page at a time, either the more or less command. The | character is the pipe which means take the output of one command and sends it to the input of another command. In the example below the cat command piped to the more command is used to display the /etc/passwd file.

When the bottom of the page is reached, the end of the page will be marked with --More--. You can move forward one line by pressing Enter, go forward one page by pressing the spacebar, or quit by pressing Q. The passwd file excerpt below for the user jsmith is described in the table, Figure 13-1. In the /etc/passwd file each of the columns are separated by the : character. jsmith:x:1000:1000::/home/jsmith:

Figure 13-1. passwd file description

The first column is the Username. The second column used to be where the password was located but now just contains an X for every users. The third column is the User ID. The root user is always 0. The first created user is always 1000 and each new user increments by 1 so the second user would be 1001. Between User ID 1 and 999 are where the various system accounts are located that are created by the system during the system installation or during the installation of software packages. The fourth column is the Logon Group ID that the user is a member of. Each user is given their own group and added to that group by default. The fifth column is the comments section, is normally blank by default but can be used to hold the user’s full name. The comments section will be covered later in this chapter. The sixth column is the user’s home directory. The seventh column is the user’s shell, /bin/bash by default. You can add users to the system by editing the passwd file directly but this method is not recommended. 13.3.5 shadow file

The shadow file is where the actual user passwords are stored in an encrypted format. The shadow file is located in the /etc directory. The example below shows an excerpt from the shadow file.

jsmith:$6$yW6LViB6$KleEQBExgzRxHwf8RQP/FUL8R23kXwO9A574rphJcg0p2/ The basic components of the shadow file are the username followed by the encrypted password encrypted using a variation of the Data Encryption Standard (DES), followed by account information. The shadow file can only be read by root or the system. Normal users cannot read the shadow file. The other columns in the shadow file will be covered later in this chapter.

13.4 Groups In Linux groups are used to tie users together in order to access shared resources such as files and directories. In this section we will cover the administration of groups on a Linux system. The following subsections are covered in this section: 13.4.1 groupadd 13.4.2 groupdel 13.4.3 group file 13.4.1 groupadd The groupadd command is used to add groups to a Linux system. The basic syntax of the groupadd command is groupadd groupname. In the example below, the groupadd command is used to add the students group. The groupadd command requires root level access so the sudo command is used.

13.4.2 groupdel

The groupdel command is used to delete groups from the system. The basic syntax of the groupdel command is groupdel groupname. In the example below, the groupdel command is used to delete the students group. The groupdel command requires root level access so the sudo command is used.

13.4.3 group file The group file contains all of the groups on the system. Normal users can view the group file. The group file contains 4 columns: group name, group password, group id, group members. If there is more than one group member, the usernames are separated by a comma. In the example below, the less command is used to view the group file.

13.5 Modifying Users In this section we will cover the commands used to modify users on a Linux system. The following commands will be introduced in this section: 13.5.1 usermod 13.5.2 chage 13.5.1 usermod

The usermod command is used to modify the attributes of a user. The basic syntax of the usermod command is usermod -options username. The usermod command requires root level access so the sudo command is used. The following commonly used options are covered in this section. 13.5.1.1 -c Comment 13.5.1.2 -d Modify Home Directory and -m Move home directory 13.5.1.3 -e Expiration date 13.5.1.4 -f Inactivate an account 13.5.1.5 -g Logon Group 13.5.1.6 -G Supplemental groups 13.5.1.7 -l Rename user 13.5.1.8 -L Lock Account 13.5.1.9 -U Unlock Account 13.5.1.1 -c Comment The -c option allows you to add a comment to the user profile. The information will be visible in the /etc/passwd file. The comment section is normally used to hold the user’s full name however anything can be put in this section. In the example below, John Smith is added to the comment section for the user jsmith. Notice that the comments are in quotations.

The example below shows the line that is modified in the passwd file after the execution of the usermod command with the -c option. The line is viewed using the cat command piped to the grep command to isolate the username jsmith.

Comments can also be added to the user’s profile when the account is created with the useradd command using -c option. 13.5.1.2 -d Modify Home Directory and -m Move home directory The -d option is used to modify a user’s home directory and the -m option is used to move the files to the new home directory. The home directory is created during the user creation process if the useradd command is used with the -m option. In the example below, the useradd command is used to create user1. The usermod command is used with the -d and -m options to move the user1 home directory from /home/user1 to /home/newuser. Since the newuser directory did not exist it was created automatically and the old user1 directory is deleted after all of the files are moved. The /etc/passwd file is updated accordingly. The cat and ls commands are used to verify that the changes took place.

13.5.1.3 -e Expiration date By default, accounts are created with no expiration date. You can use the usermod command with the -e option to set an expiration date. The date

format is YYYY-MM-DD. In the example below, the grep command is used to view user1 information in the /etc/shadow file which contains the user’s encrypted password and various account settings.

The line from the shadow file is broken down into 9 columns separated by the : character. The first column is the username. The second column is the encrypted password. The next 7 columns are shown in Figure 13-2. Any column that is blank means that nothing has been defined.

Figure 13-2. shadow file description

The third column is the number of days since January 1, 1970 that the password was last changed. The fourth column is the minimum password age. The default is 0 which means that the user can change their password at anytime. The fifth column is the maximum password age. The default is 99999 which means that password can be really old. The sixth column is the password warning period which is the number of days prior to a password expiring that a user will be warned. The default is 7 days.

The seventh column is the password inactivity period which is the amount of time that an account will remain enabled after the password expires. The default is blank. The eighth column is the account expiration date which is the number of days since January 1, 1970 that the account will expire. The default is blank. The ninth column is reserved for future use and is blank by default. In the example below, the grep command is used to view the contents of the /etc/shadow file for user1. There is nothing in column 8 which is the password expiration date. The usermod command is used with the -e option to set the account expiration date to 2017-10-01. Column 8 in the shadow file for user1 is now 17120 which is the number of days from January 1, 1970 until the expiration date. If you did the math it would turn out that this is 2017-10-01.

13.5.1.4 -f Inactivate an account The -f option defines the number of days after the password has expired until the account is disabled or inactivated. This means that once a password has expired, the user will have the number of days defined with the -f option to change their password. After the date has passed the user will no longer be able to access the account until it is enabled by the root user. In the example below, the grep command is used to view the contents of the /etc/shadow file for user1. There is nothing in column 7 which is the password inactivity column. The usermod command is used with the -f option to set the inactivity period to 7 days for user1. Besides the number of days you can also use 0 to disabled the account as soon as the password

expires and -1 which disables the password inactivity feature. The output of the grep command shows the number 7 in password inactivity column.

13.5.1.5 -g Logon Group The -g option can be used to change the user’s initial Logon Group. By default each user is given their own group named the same as their username and this is set as the user’s initial Logon Group. Any files the user creates will have the initial Logon Group set as the group owner. In the example below, the /etc/group file is viewed with the cat command to find the group numbers. The output is piped to the tail command which shows the last 10 lines of the file. You can see from the output that the user1 group number is 1003 and the students group number is 1004.

In the example below, the grep command is used to view the user1 line in the /etc/passwd file. You can see that the initial logon group, column 4, is set to 1003 which is the user1 group. Using the ls -l command to list the

user1 home directory, which is now named newuser, you can see that the files all have the user1 group set as the group owner.

In the example below, the usermod command is used with the -g option to change the user1 initial Logon Group to students.Using the grep command to view the user1 line in the /etc/passwd file you can see that the initial logon group, column 4, is set to 1002 which is the students group. Using the ls -l command in the user1 home directory you can see that the files all have the students group set as the group owner.

Only files in the user’s home directory will automatically be updated with the new group. All files outside of the user’s home directory will have to be updated manually. 13.5.1.6 -G Supplemental groups Supplemental groups are different than the logon group. A user can have only one logon group but many supplemental groups.

To see a user’s supplemental groups use the groups command. The syntax for the groups command is groups username. In the example below the groups command is used to view the groups for the user matt.

To modify a user’s supplemental groups use the usermod command with the -G option. In the example below, the usermod command is used with the -G option to add matt to the group instructors. Using the groups command shows that matt is now a member of the instructors group. When the usermod command with the -G option is used it will remove the user from all other groups except the user’s own group. In the example the user matt is no longer in the users group.

The usermod command with the -aG option is used to append the group to the user’s profile. In the example below, the usermod command is used with the -aG options to append the users group to the user matt profile.

You can also use the -G option with the groups separated by a comma to add more than one group at a time. There can not be a space before or after the comma. In the example below, the usermod command with the -G option to add multiple groups to the user matt profile.

13.5.1.7 -l Rename user The -l option can be used to rename a user. When the user is renamed the name of the user's home directory does not change. The basic syntax for the usermod command with the -l option is usermod -l new_username old _username. In the example below, the usermod command is used with the -l option to change user1 to jdoe.

13.5.1.8 -L Lock Account The -L option can be used to lock a user account. In the example below, the usermod command is used with the -L option to lock the jdoe account. The /etc/shadow file is modified by putting a ! in front of the user's password to signify that the account is locked.

13.5.1.9 -U Unlock Account The -U option can be used to unlock a user account. In the example below, the usermod command is used with the -U option to unlock the jdoe account. The /etc/shadow file is modified by removing the ! in front of the user's encrypted password.

13.5.2 chage The chage command is used to view and change the expiration settings for a user account. The basic syntax for the chage command is chage options account. The following subsections are covered in this section. 13.5.2.1 -l List 13.5.2.2 -d Last day since password change 13.5.2.3 -E Expiration date 13.5.2.4 -m Minimum number of days between password changes 13.5.2.5 -M Maximum number of days password is valid 13.5.2.6 -I Inactive number of days after password expires account becomes inactive 13.5.2.7 -W Warn days 13.5.2.8 Interactive mode 13.5.2.1 -l List The -l option is used to list the current settings for an account. The items in the list correspond to the information in the /etc/shadow file following the user’s password. When viewed with the chage command the settings are displayed in normal date format. In the example below, the chage command is used with the -l option view the settings for user1.

13.5.2.2 -d Last day since password change The -d option is used to change the last day since the user changed their password. This date will automatically change when a user actually changes their password. If you want to extend or shorten the amount of time a user can use their current password you can use this option. The date format for the -d option is YYYY-MM-DD. In the example below, the chage command is used with the -d option to change the Last password change date for user1 to 2016-11-15 and then the -l option is used to verify the change.

13.5.2.3 -E Expiration date The -E option is used to set the account expiration date for a user. The date format for the -E option is YYYY-MM-DD. In the example below, the chage command is used with the -E option to set the Password expires date for user1 to 2017-01-31 and then the -l option is used to verify the change.

13.5.2.4 -m Minimum number of days between password changes The -m option is used to set the minimum number of days between password changes. This setting will prevent the user from changing their password too frequently. In the example below, the chage command is used with the -m option to set the minimum number of days between password changes for user1 and then the -l option is used to verify the change.

13.5.2.5 -M Maximum number of days password is valid The -M option is used to set the maximum number of days a password is valid. This setting will force the user to change their password when the set number of days has passed. In the example below, the chage command is used with the -M option to set the maximum number of days a password is valid for user1 to 90 and then

the -l option is used to verify the change. When this option is set the Password expires date is automatically calculated based upon the Last password change date.

13.5.2.6 -I Inactive number of days after password expires account becomes inactive The -I option is used to set the number of days following a password expiration date that an account becomes inactive or disabled. The Password expiration date must be set with the -M option first for this option to take effect. In the example below, the chage command is used with the -I option to set the number of days following a password expiration date that an account becomes inactive or disabled to 7 for user1 and then the -l option is used to verify the change. The Password inactive date is now 7 days after the Password expires date.

13.5.2.7 -W Warn days The -W option is used to set the number of days prior to the password expiring to warn the user. The Password expiration date must be set with the -M option first for this option to take effect. In the example below, the chage command is used with the -W option to set the number of days prior to the password expiring to warn the user to 14 for user1 and then the -l option is used to verify the change.

13.5.2.8 Interactive mode Running the chage command with no options, just a username, runs the command in interactive mode. In interactive mode, each setting is provided one at a time with the current or default settings in square brackets, [ ]. Pressing enter without entering any values will keep the default value in the brackets. Entering a value will change the settings to the entered value. Once you have gone through all of the settings the account is updated. In the example below, the chage command is used without any options to enter interactive mode for user1 update the settings. The chage command with the -l option is used to verify the change.

14. WORKING WITH COMMANDS

14. Working with commands In Linux there are several types of commands that can be accessed from the CLI. Built in commands are commands that come as part of the Bash shell. The cd command which is used to change directories is an example of the built in command. Executable programs are programs that are added to the Linux system by installing various software packages or are scripts that are written for Linux. The vi program which is a popular text editor for the CLI is an example of an executable program. Functions are keywords that are part of the Bash shell used for scripting. Aliases commands that use other commands and certain options to generate a certain outcome. The following sections are covered in this chapter: 14.1 Identifying commands 14.2 Getting help 14.3 Aliases 14.4 Redirection 14.5 Quotes 14.6 Expansion 14.7 Escaping 14.8 Controlling commands

14.1 Identifying commands Linux has several commands that can be used to identify commands. The following commands are covered in this section: 14.1.1 type

14.1.2 which 14.1.1 type The type command is used to determine the type of command. In the examples below, the type command is used to examine cd, ls, and if. The output options are aliased, shell keyword, function, shell builtin, file or not found.

14.1.2 which The which command is used to show the absolute path of a shell command. Most of the shell commands are located /bin directory on Debian based systems such a Debian, Ubuntu, and Mint Linux, and located in the /usr/bin directory on Fedora based systems. In the example below, the which command is used to locate the ls command.

14.2 Getting help There are lots of ways to get help learning how to use Linux. Reading this book is a good first start. There are lots of sites on the Internet that provide advice and guidance. Then there are the built in Linux help systems. The following commands are covered in this section: 14.2.1 man

14.2.2 apropos 14.2.3 help 14.2.4 info 14.2.1 man The manual pages for a Linux command, which are online references built into Linux, can be accessed with the man command. The syntax for the man command is man command. The man pages can be a little daunting at first as there is a lot of information, some of which does not pertain to the beginning user. The man page for a command will normally contain the following information: Name Synopsis Configuration Description Options Exit status Return value Errors Environment Files Versions Conforming to Notes Bugs Examples Authors See also Of the sections listed above, the sections most useful to a new users are the Name, Synopsis, Description, Options, and Examples. In the example below, the man command is used to view the man page for the ls command.

The man command will only show one page at a time. To go to the next page you can press the Spacebar. To go forward 1 line press the Enter key. You can also use the up and down arrow and the PgUp and PgDn keys. To exit the man page press Q. The man pages also include a search function that will allow you to quickly find a specific section. To enter the search function press the / character. The bottom of the screen will display the / character. Enter the term that you are searching for and press enter. Searches are case sensitive. 14.2.2 apropos The apropos command is used to search the man pages for references to whatever string you specify. In the example below, the apropos command is used to search the man pages for any references to “add a user”. The apropos command finds two commands that contain the string.

14.2.3 help

The help command can be used to find information about Bash builtin commands. The information is normally much more concise than the man pages and displays all of the content to the CLI. Not all commands will have help pages.

14.2.4 info Info pages are the new documentation method used by the GNU Project which makes the most of the tools used in the Bash shell in most Linux distributions also known as the GNU Coreutils. The syntax for the Info pages is info command. The example below shows

the Info page for coreutils.

Info pages are hyperlinked meaning any word that is underlined will lead to another page. To use the hyperlink move the cursor over the underlined word and press enter. You will be taken to the page that the hyperlink references. There are several commands that can be used to navigate the Info pages. Each page is known as a node. Figure 14-1 shows the navigation commands.

Figure 14-1. Info page navigation commands

14.3 Aliases An Alias allows you to create a custom command and option and give it an easy to use name. The following commands are covered in this section: 14.3.1 alias 14.3.2 unalias 14.3.1 alias The alias command is used to create a new command using existing commands and options. The alias command syntax is alias=’command and options’. In the example below, the alias command is used to create a new command that uses the ls command with the -la options. The new command is named

mycom. Now mycom will perform an ls -la anytime the alias is typed.

The example below combines several commands together. The ifconfig command is used to view the network configuration information on a Linux system such as the IP address. Depending upon how many interfaces there are on a system you have to scroll through several pages to find each IP address. Using the alias command you can make one command to do the work of several commands. The example uses several commands that have not been introduced yet but shows you that you can combine several commands together.

An alias only lasts as long as the current CLI is open. When you close a terminal any aliases created will be lost. 14.3.2 unalias To remove an alias use the unalias command. The unalias command syntax

is unalias alias_name.

14.4 Redirection Redirection allows to change where the output of a command is sent or where the input for a command comes from. The following subsections are covered in this section: 14.4.1 Standard Out 14.4.2 Standard In 14.4.3 Standard Error 14.4.4 Pipes 14.4.1 Standard Out The default Standard Out (stdout) is the CLI. When you run a command that generates output, the output is sent to stdout and the output is displayed on the CLI. You can redirect the output to a file using the > or >> characters. The > character will send the output to a file and overwrite any text already in the file. The >> character will append the output to any text already in the file. In the examples below, the output of the ls -l command is sent to the file file_list. Then a second ls -l command is executed on a different directory and the output is appended to the file file_list. The cat command is used to examine the contents of the file file_list.

14.4.2 Standard In The default Standard In (stdin) is the user input from the CLI. When you run a command that needs input, the user must provide the input via stdin. You can redirect input to a command from a file using the < character. In the example below, the sort command is used to sort a list of names from the file name_list. The < character after the sort command redirects the contents of the file to the input of the command.

You can also use a redirection for both the input and output in the same command. In the example below the file is used as the input to the sort command and the output is redirected to another file.

14.4.3 Standard Error When a command has an error, the error message is sent to Standard Error (stderr) which is the CLI. Since stdin and stderr both go to the CLI by default, the CLI can get a little busy so be able to redirect the error messages to a file can be useful. The stderr redirect is 2>. In the example below the stderr redirector, 2>, is used to redirect the error from the ls command to a file named error.txt and the cat command is used to view the contents of the file.

If you do not care about the error message at all you can redirect the error messages to /dev/null which is basically a black hole where things you do not care about can be sent and they basically disappear.

In the example below the stderr redirector, 2>, is used to redirect the error from the ls command to /dev/null.

14.4.4 Pipes The pipe character | allows you to take the output of one command and make it the input of another command. One of the most common uses of the pipe is to send output to the grep command. The grep command is used to search text and find lines matching a search string. In the example below, the cat command is used to view the sorted_name_list file which is a list of first and last names. Piping the output of the cat command to the grep command and using the search string Smith generates the output of only lines with the word Smith in the line.

14.5 Quotes There are two types of quotes used in Linux, double quotes and single quotes. How each type of quotes are used with a command depends upon the desired outcome.

In the example below a variable named fullname is created with the string Fred Smith. In this case the variable declaration can be done with either single or double quotes and the results will be the same. The echo command is used to print the contents of the variable to the CLI. When referencing a variable name you have to use the $ character. Also since the echo command is just using the variable name quotes are not required. The echo command is used again but this time with double quotes in order to add additional text. The variable is converted to the text and added to the additional text. The same command is used with single quotes and the variable is not converted to text but rather is displayed as is.

In the example below both single and double quotes are used together to get the desired output.

14.6 Expansion When commands are executed on the CLI, there may be certain types of commands that require expansion before the command can be executed. The command may contain variables or wildcard characters that need to be expanded. In the example below, the echo command with the wildcard * is used to show a simple example. The * character is expanded to all of the files and directories in the current location and printed to the CLI.

The following expansions are covered in this section: 14.6.1 Arithmetic Expansion 14.6.2 Brace Expansion 14.6.3 Variable Expansion 14.6.4 Command Expansion 14.6.1 Arithmetic Expansion Arithmetic Expansion allows you to use arithmetic operations on the CLI. The syntax for an Arithmetic Expansion is $((arithmetic expression)). In the examples below, various arithmetic expressions are used on the CLI with the echo command.

Figure 14-2 shows the arithmetic operators which can be used:

Figure 14-2. Arithmetic operators

Without using the proper Arithmetic Expansion syntax the arithmetic function will not be executed but rather displayed as is as in the following example.

14.6.2 Brace Expansion Brace Expansion allows you to specify a range of alphanumeric characters and each of the characters is acted upon. The Brace Expansion syntax is {first character..last character}. In the example below the touch command is used with the pattern {1..5} to create 5 files named myfile1 to myfile5 and then uses the pattern {A..E} to create 5 more files named myfile_A.txt to myfile_E.txt.

You can also use commas to define specific characters to use vice a range.

14.6.3 Variable Expansion Variable Expansion allows you to use environmental and user defined variables. In the example below the $USER and $HOME environmental variables are used with the echo command. Both of these variables are tied to the current user and change with each user.

In the example below the variable MYVAR is defined with the text Something. The export command is used to make the $MYVAR variable available to all CLI then the echo command uses the variable.

14.6.4 Command Expansion Command Expansion allows you to use the output of one command in another command. The syntax for Command Expansion is $(command) or “$(command)” or `command`. In the examples below the echo command is used with the pwd command. The first two examples the pwd command is not expanded. In the second two examples the command is expanded.

Using Command Expansion on commands with options and arguments can

cause some interesting results. When using commands with options and arguments you have to enclose the Command Expansion in quotes. In the examples below the ls -l command is used in Command Expansion and the output is not what is normally expected. With the quotes the output is correct.

14.7 Escaping There are times when you need for special characters not to be special characters. The $ character is a good example. It normally is used to denote a variable, however, when you need it to be the $ character you have to escape the character first using the \ character. In the examples below, the $USER environment variable is used to display the current user. The variable is used again in a sentence with quotes. In both cases the variable is converted into the current username and displayed on the CLI. In the last example the variable is used again to display the current user and the $ special character is escaped using the \ character to stop $USER from being seen as a variable.

14.8 Controlling commands

When running commands on the CLI there are certain key combinations that you can use to control how commands execute. The following commands are covered in this section: 14.8.1 Ctrl+C 14.8.2 Ctrl+Z 14.8.3 jobs 14.8.4 fg 14.8.5 bg 14.8.1 Ctrl+C When you are running a command on the CLI and want to stop the command execution you can use Ctrl+C. In the example below the cat command is used without a filename which causes cat to keep running awaiting input. If you type in quit or exit, cat just prints the word you typed out to the CLI. In order to stop the cat program from running type Ctrl+C which is indicated by the ^C.

14.8.2 Ctrl+Z When you are running a command on the CLI and want to pause the command execution you can use Ctrl+Z. In the example below the cat command is used without a filename which causes cat to keep running awaiting input. In order to pause the cat program

type Ctrl+Z which is indicated by the ^Z. Following the ^Z, the information about the paused command is output to the CLI. The first item is the [1] which means it is the first paused command. The next paused command would be listed as [2]. Next is says Stopped which actually means paused. The last part is the name of the command.

14.8.3 jobs To see a list of paused commands you can use the jobs command. In the example below, the jobs command shows three stopped commands. Each command has a number and the last one has a + sign which means that is was the last command to be paused. The - next to the second one means that it is the second to last command to be paused.

14.8.4 fg To return a paused process to running you use the fg command which stands for foreground. Typing fg will bring back the last paused command. You can also use the fg command with the number from the list from the jobs command to bring a specific command or job back to the foreground. In the example below the cat command is paused and the fg command is used to bring the command back and Ctrl+C is used to stop the command.

In the example below the jobs command is used to list the current paused jobs and the fg command is used to bring back paused job #1,

14.8.5 bg By using the bg command you can send a stopped job to the background to run and give you back control of the CLI. In the example below the find command is used to find a file named test. The output is being sent to /tmp/output.txt and any errors are being sent to /dell/null. The 2> means redirect any errors and /dev/null is a location that is sort of like a black hole where you can send stuff that you do not need. A find command may take some time to run and you will not have access to the CLI while the command it running. Pressing Ctrl+Z pauses the command. The jobs command is used to list the current jobs. The find command is listed as #5 and is shown as Stopped. The bg command is used to send the find job to the background to run. The jobs command is used to verify that the find job is running in the background.

You can run commands from the start as a background process by placing a & character at the end of the command. In the example below, the same find command is run as a background process by adding the & character to the end of the command. When a command is run as a background process job number as well as the Process ID (PID) is displayed. PIDs will be covered in Chapter 15. The jobs command is used to view the status of the background job. Running means the command is executing in the background. Exit 1 means that the command is complete and errors were detected. In this case the find command gives an error when it detects a directory that the user does not have permission to view. Since this known behavior of the find command, the errors are sent to /dev/null to avoid getting error messages on the CLI.

15. WORKING WITH PROCESSES AND SERVICES

15. Working with Processes and Services Processes and services are the programs that make the Linux operating system work. The following sections will be covered in this chapter: 15.1 Processes 15.2 Services

15.1 Processes A process is an individual program that runs in the background to perform some task for the Linux operating system. The most important process in a Linux system is systemd which is the first process started when Linux boots and starts all other processes. Most current versions of Linux use systemd, however, older versions of Linux used a program called init. This book will not be covering init as most linux systems have stopped using it in favor of systemd. Processes that end with the letter d are known as daemons which are process which run in the background and carry out certain functions. Systemd is a daemon. When one process starts another process, the first process becomes the parent process and the second process is the child process. A process can be both a child of one process and the parent of another process. Each process is assigned a Process ID (PID). The following commands will be covered in this section: 15.1.1 ps 15.1.2 top 15.1.3 kill 15.1.4 killall 15.1.1 ps

The ps command can be used to print a list of currently running processes. The list can be rather long so piping the output of the ps command to less allows you to view the list 1 page at a time. In the example below the ps command is used to view the processes on a Linux system. The ps command without any options will only display process in the current terminal session. The output lists the PID, TTY, TIME, and CMD. The PID is the Process ID. The TTY is the terminal type. In the example below the TTY is pts/2, which stands for pseudo terminal number 2. Any time you open a terminal window you are opening a pseudo terminal. TIME is the CPU time that a process has been running. CMD is the command that started the process.

In order to see all of the processes running on a Linux system you have to use the -e option, which means every process. In the example below the ps command with the -e option is used to list all processes. Notice that the first process is systemd with a PID of 1 which means that systemd is the first process. The list is rather long so the output has been cut off.

You can see many more categories by using the ps command with the -aux options. The -a option shows all users processes, the -u option provides additional information, and the -x option shows process without a controlling terminal, such as daemons.

If you are looking for a specific process you can pipe the ps command to the grep command and provide the name of process. In the example below from

an Ubuntu system, the ps and grep commands are used to find the systemd process. As can be seen below there are other processes besides systemd that start with systemd.

The systemd-journal process is a daemon that is used to collect and store log data. The systemd-udevd process is a daemon that is a device manager. The systemd-timesyn process is a daemon that synchronizes time across a network. The systemd-logind process is a daemon that handles the login process. The systemd-resolve process is a daemon that handle name resolution. 15.1.2 top The top command provides a real time list of system statistics and running process. The display is divided into two parts. The top section contains system information and the bottom contains information about running processes.

The top section contains the following information starting from the top left and moving to the right. 1. 2. 3. 4.

System time Up time Number of users on the system Load average for the CPU for one-minute, five-minute, and 15minute intervals 5. Number of total running tasks or processes, running, sleeping, stopped, and zombie a. Running means the process is currently active b. Sleeping means the process is waiting for something c. Stopped means the process is paused d. Zombie means the process is done but is still listed in the process table 6. Percentage of CPU utilization a. us - percentage of CPU time in user mode b. sy - percentage of CPU time in kernel mode c. ni - percentage of CPU time spent on low priority processes d. id - percentage of CPU time spent idle e. wa - percentage of CPU time spent in wait

f. hi - percentage of CPU time servicing hard interrupts g. si - percentage of CPU time servicing soft interrupts h. st - percentage of CPU time spent in involuntary wait by the virtual CPU 7. System Memory a. total b. free c. used d. buff/cache 8. Virtual Memory a. total b. free c. used d. avail Mem The bottom section contains the following information starting from left and moving to the right. 1. 2. 3. 4. 5. 6. 7. 8.

9. 10. 11. 12.

PID - process ID USER - user who owns the process PR - priority (default is 20) NI - nice value VIRT - virtual memory area allocated to the process RES - resident memory area allocated to the process SHR - shareable memory S - process status a. R- Running b. D - Sleeping but may not be interrupted c. S - Sleeping and may be interrupted d. T - Stopped or paused e. Z - Zombie %CPU - percentage of CPU used %MEM - percentage of memory used TIME+ - CPU time used by the process COMMAND - The command name

The top command is an interactive command. While the command is running you can use certain keys to control the display.

If you have multiple CPU on your system, pressing 1 will show the CPU statistics for each CPU in the top section. In the example below, the system has four CPUs labeled Cpu0 through Cpu3.

The following keys can be used to change the sorting order in the bottom section: 1. 2. 3. 4.

T - Sort by TIME+ column M - Sort by %MEM column P - Sort by %CPU column (default) N - Sort by PID column

To exit top press the q key. 15.1.3 kill Occasionally a program or process will get hung up and will need to be terminated. The kill command can be used to terminate a process. The basic syntax for the kill command is kill pid. Since the kill command uses the PID to identify the process to terminate, you must already know the PID by using ps or top. Many times, however, the basic kill command will not terminate a process. In order to terminate a process you may have to use the kill command with a signal, -9, which means “kill this process now.” In the example below, the ps and grep commands are used to find the PID for the nano program. The basic kill command is used to attempt to terminate the program but it fails. The kill command is used with the signal -9 which terminates the process.

Be careful to only use the kill command to terminate process when absolutely necessary as any unsaved work will be lost. 15.1.4 killall The killall command can be used to terminate multiple instances of a program running at the same time. Unlike the kill command, the killall command can use the name of a program. Like the kill command, the killall command uses signals like -9. In the example below the killall command is used to terminate all instances of the nano program.

15.2 Services A service in Linux is a process or a group of processes that run in the background and carry out certain tasks. Many times services are configured to start when the system boots. One of the most popular services is the Apache web server, httpd, Figure 15-1. Other services include things like an

SSH server, DNS server, email server, and DHCP server.

Figure 15-1. Apache web server

15.2.1 systemctl Services are not started and stopped the same way as regular commands. The systemctl command is used to control services. The systemctl command has its own commands. The following systemctl commands will be covered in this section: 15.2.1.1 status 15.2.1.2 start 15.2.1.3 stop 15.2.1.4 restart 15.2.1.5 enable 15.2.1.6 is-enable 15.2.1.7 disable 15.2.1.1 status The systemctl command with the status command will show the current status of an installed service. In the example below, the systemctl command

is used to check the status of apache2 which is a web server for Linux.

15.2.1.2 start The systemctl command with the start command will start an installed service. In the example below, the systemctl command is used to start apache2.

15.2.1.3 stop The systemctl command with the stop command will stop a running service. In the example below, the systemctl command is used to stop apache2.

15.2.1.4 restart The systemctl command with the restart command will restart a running service. In the example below, the systemctl command is used to restart apache2.

15.2.1.5 enable The systemctl command with the enable command will start an installed service during boot. Some Linux distributions do not enable certain services during the installation of the service. If you want the service to start during the system boot you have to enable the service. In the example below, the systemctl command is used to enable apache2.

15.2.1.6 is-enable The systemctl command with the is-enable command will show the enabled status of an installed service. In the example below, the systemctl command is used to verify the enabled status of apache2.

15.2.1.7 disable The systemctl command with the disable command will stop the starting of an installed service during boot. In the example below, the systemctl command is used to disable apache2 and verify the status.

16. EDITING FILES

16. Editing files Editing files from the CLI is an important skill to master. You will not always have a GUI available for editing files. There are numerous command line editing tools out there but I am going to focus on two of the most popular in this book, nano and vi. The reason is that most Linux distributions come with both or at least of of these programs already installed. This chapter will be a basic overview of the editors to get you started editing files, not an extensive tutorial. 16.1 nano 16.2 vi

16.1 nano Nano is basic text editor that comes installed on most Linux distributions. The example below shows the nano program running. When nano is running, the program takes over the CLI and you will only be able to type in the nano program until you exit the program. At the bottom of the nano screen is a menu of the most common shortcuts used which will be covered in the following sections.

The following subsections are covered in this section: 16.1.1 Starting nano 16.1.2 Editing a file 16.1.3 Getting Help 16.1.4 Reading Files 16.1.5 Write Out 16.1.6 Where Is 16.1.7 Replace 16.1.8 Cut Text 16.1.9 Uncut Text 16.1.10 Justify 16.1.11 To Spell 16.1.12 Cur Pos 16.1.13 Go To Line 16.1.1 Starting nano The easiest way to start nano is just by typing nano on the CLI and pressing enter. If nano is installed it will start with a blank file. You can also start nano and open a file at the same time by using the following syntax:

nano filename If no file with that name exists, a new file will be created. If you are using nano to edit a configuration file you will need to have root privileges by using the sudo command: sudo nano filename When using a text editor on the CLI to open a file in another area of the file system you will have to use the path along with the filename. The following example is used to open the file test.txt in the /tmp directory. nano /tmp/test.txt If you do not include the path, nano will create a file named test.txt in the current directory. This is a common mistake that new Linux users make. They are trying to edit a configuration file in another part of the file system and forget to use the path. Nano creates a blank file with the same name in the current directory. The user puts their configuration in the file, saves the file, and restarts the service only to find that their changes have not taken place. The user has placed the configuration in the wrong file. Be careful when editing configuration files. You can also enable mouse support when starting nano by including the -m option. The mouse support will allow you to place your cursor by using the mouse. nano -m or nano -m filename 16.1.2 Editing a file Once you have a file open in nano you can edit the file by just typing text. You cannot use a mouse to move the cursor in nano unless you enable mouse support, but you can use the arrow keys and the PgUp and PgDn keys to move throughout the document. Once you start editing a file the word Modified will appear in the top right hand corner as in the example below. When you open an existing file, the path and filename will appear in the

middle of the window at the top. A file in nano is also known as a file buffer.

16.1.3 Getting Help To access the nano help file, press Ctrl+G. The example below shows the nano help file. You can use the arrow keys and the PgUp and PgDn keys to move throughout the document.

To exit the help file press Ctrl+X. 16.1.4 Reading Files To open a file from nano press Ctrl+R which stands for Read File. At the bottom of the screen you will be asked for the name of the File to insert as in the example below. You can either enter a filename or the path and filename. When you are using the Read File function you are not opening the file you are reading but rather copying the text of the file into a new file. If you want to open a file with nano to edit you have to provide the filename on the CLI when running the nano command. Files are read into the current file buffer. You can have more than one file buffer at a time which means you can edit more than one file at a time and switch between files. Buffers will be covered later in this chapter.

If the file is not found you will get a File not found error like the example below.

If the file is found and opened the text will appear and the number of lines read from the file will be displayed at the bottom of the screen above the shortcut as in the example below.

The Read File screen has a shortcut menu that is different than the main shortcut menu.

The following shortcuts will be covered in this section: 16.1.4.1 Get Help 16.1.4.2 Cancel 16.1.4.3 Execute Command 16.1.4.4 New Buffer 16.1.4.5 To Files 16.1.4.1 Get Help When in the Read File screen you can access help for inserting a file by press Ctrl+G which will take you to the help file for inserting a file as seen in the example below. To exit back to the Read File screen press Ctrl+X.

16.1.4.2 Cancel To cancel the Read File and return to the main screen press Ctrl +C. 16.1.4.3 Execute Command From the Read File screen you can also execute a command from the current directory by pressing Ctrl+X and the results will be inserted into the current buffer.

In the example below the ls command was run from the Read File screen and the results are now in the current buffer.

16.1.4.4 New Buffer Pressing ESC+F will change the location from the current buffer to a new buffer. Pressing ESC+F again will return to the current buffer.

In the example below the file will be inserted into a new buffer.

16.1.4.5 To Files From the Read File screen you can access a list of files in the current directory by pressing Ctrl+T. You can use the arrow keys to select a file and then press enter to insert the text from the file into the current buffer. You can also navigate the file structure by using .. (parent dir) to access the parent directory of the current directory.

16.1.5 Write Out To save the current buffer out to a file use Ctrl+O for Write Out. After pressing Ctrl+O you will be asked for the File Name to Write Out as in the example below.

After the Write Out is complete, nano will tell you how many lines were written out as in the example below.

The Write Out screen has a shortcut menu that is different than the main shortcut menu.

The following shortcuts will be covered in this section: 16.1.5.1 Get Help 16.1.5.2 Cancel 16.1.5.3 DOS Format 16.1.5.4 Mac Format 16.1.5.5 Append 16.1.5.6 Prepend 16.1.5.7 Backup File 16.1.5.8 To Files 16.1.5.1 Get Help

To Get Help in the Write Out screen press Ctrl+G. The example below shows the Write File Help Text.

To exit the Help screen press Ctrl+X. 16.1.5.2 Cancel To cancel the Write Out screen press Ctrl+C. 16.1.5.3 DOS Format To Write Out a file in DOS Format press Esc+D from the Write Out screen. You can turn off DOS Format by pressing Esc+D again. In the example below file1.txt is being saved in DOS Format.

Text files contain an end of line character that tells the program presenting the text file to display a new line. Linux and Windows systems and do not use the same end of line character. In a Linux system the end of line is signified by \n which is a line feed and in Windows it is \r\n which is a carriage return and line feed combined. These end of line characters are special ASCII control characters that do not appear in the text file when viewed with a text editor. To see the special characters to need to use a program like hexdump. In the example below, the hexdump command is used to view the hex characters that make up two text files file1.txt and file2.txt. All files are made of binary numbers 1 and 0. Hexadecimal is used to display binary files in a more readable format. Four binary numbers make up a single hexadecimal character. In a text file, ASCII characters are used to display the text you type on the screen. Each ASCII character is made up of 2 hexadecimal characters or 8 binary bits. If you look at the hexdump of the two files below, file1.txt and file2.txt, you will see that the hex dumps are different. The text is each file is the same but the format of the files is different. The file1.txt file is a Linux format and file2.txt is n DOS format. The line feed character in hexadecimal is 0a and the carriage return character is 0d. Looking at the output from file1.txt you

can see the 0a character at the end of the first line and then at different areas in the rest of the output. Looking at the output from file2.txt you can see the 0a0d characters at the end of each line.

You can also use the hexdump command with the -c option to see the actual characters including the \n and \r.

When you view both of these files on a Windows system with a basic text editor the following are the outputs you will see. file1.txt (Linux format)

file2.txt (DOS format)

16.1.5.4 Mac Format To Write Out a file in Mac Format press Esc+M from the Write Out screen. You can turn off Mac Format by pressing Esc+M again. In the example below file1.txt is being saved in Mac Format.

Linux and Mac systems and do not use the same end of line character. In a Linux system the end of line is signified by \n which is a line feed and on a Mac it is \r which is a carriage return.

You can use the hexdump command with the -c option to see the actual characters. The example below is from a file encoded for Mac which shows the \r.

16.1.5.5 Append From the Write Out screen you can choose to Append the current buffer to a file by pressing Esc+A. You can toggle Append off by pressing Esc+A again. In the example below the current buffer is being appended to file1.txt. Appending the current buffer to a file will place the text from the buffer after the text already in the file.

16.1.5.6 Prepend From the Write Out screen you can choose to Prepend the current buffer to a file by pressing Esc+P. You can toggle Prepend off by pressing Esc+P again. In the example below the current buffer is being prepended to

file1.txt. Prepending the current buffer to a file will place the text currently in the buffer before the text already in the file.

16.1.5.7 Backup File From the Write Out screen you can choose to create a Backup file before writing out the current buffer to a file by pressing Esc+B. You can toggle Backup off by pressing Esc+B again. In the example below the current buffer is written out to file1.txt and a backup file will be created of the existing file1.txt.

To mark the file as a backup file, nano puts a ~ character at the end of the file name. In the example below, file1.txt and file2.txt have backup files but file3.txt does not.

16.1.5.8 To Files From the Write Out screen you can access a list of files in the current directory by pressing Ctrl+T. You can use the arrow keys to select a file and then press enter to Write Out the text in the current buffer into the file you select. You can also navigate the file structure by using .. (parent dir) to

access the parent directory of the current directory.

16.1.6 Where Is To search the current buffer for a specific word or text you can use the Where Is function from the main screen by pressing Ctrl+W. The Search dialog will appear at the bottom of the screen as in the example below. Type in your search term and press enter. If a match is found, nano will place the cursor on the first occurrence from the original cursor location. If there is more than one instance of the search string, you will have to search again to find the next one. To cancel a search press Ctrl+C.

If the search string is not found you will get a not found error as in the example below.

16.1.7 Replace To search the current buffer for a specific word or text and replace it with other text you can use the Replace function from the main screen by pressing Ctrl+\. The Search (to replace) dialog will appear at the bottom of the screen as in the example below. Type in your search term and press enter.

Next you have to provide replacement text in the Replace with dialog box as in the example below.

If a match is found, nano will place the cursor on the first occurrence from the original cursor location and you will be asked if you want to replace the instance found. To replace the instance press Y. To not replace the instance

press N. To replace all instances in the buffer press A. To cancel the replace press Ctrl+C.

When the replacement is done you will get a message that tells you how many replacements were made.

16.1.8 Cut Text To cut a line of text from the current buffer you can use the Cut Text function from the main screen by placing the cursor on the line you want to cut and pressing Ctrl+K. The line will disappear and the line below it will be moved up. You can cut multiple lines of text by pressing Ctrl+K multiple time. 16.1.9 Uncut Text To uncut a cut line of text in the current buffer you can use the Uncut Text function from the main screen by placing the cursor on the line you want to uncut line to be placed on and pressing Ctrl+U. The line will be placed at the location of the cursor and the current line will be moved down. If cut

multiple lines of text by pressing Ctrl+K multiple times, all of the lines will be uncut at the same time. 16.1.10 Justify You can combine all of the lines in a file together by using the Justify function by pressing Ctrl+J. In the example below, the current buffer has two lines.

After pressing Ctrl+J, all of the lines are combined into one line. It does not matter how many lines there are in the file, all lines will be combined. Immediately after pressing Ctrl+J you can press Ctrl+U to Unjustify but as soon as you do anything else you will no longer be able to undo the justify anymore .

16.1.11 To Spell Nano includes a spell checker function which you can use by selecting the To Spell shortcut from the main screen by pressing Ctrl+T. In the example below the word buffer is misspelled. In the example below the spell checker is activated by pressing Ctrl+T and the misspelled word is highlighted and a list of options is presented. Choose the option you want and the word will be replaced with the correct spelling.

In Ubuntu and Debian the spell checker does not work by default. If you try and use the spell checker you will get the following error.

To fix this problem use nano to open the /etc/nanocr file which is a configuration file for nano. Since the nanorc file is a configuration file, you will have to use sudo to be able to edit the file. sudo nano /etc/nanorc Once the file is open in nano press Ctrl+W to start the search function and search for the words set speller. Uncomment the line #set speller “aspell -x -c” by deleting the # character at the beginning of the line.

Press Ctrl+O to write out the file. Exit and start nano again. The spell checker should now work. 16.1.12 Cur Pos To find the current position of the cursor in the buffer, use the Cur Pos function by pressing Ctrl+C from the main screen. The current position will be displayed at the bottom of the screen as in the example below.

16.1.13 Go To Line To move the cursor to a specific position in the buffer, use the Go To Line function by pressing Ctrl+Shift+_ from the main screen. Nano will ask for the line number and column number to move to at the bottom of the screen as in the example below. If you just enter a line number without a column number then nano will the cursor to the specified line.

16.2 vi While there are many very good text editors out there, the vi editor is the one that I always recommend my students obtain a good working knowledge of all versions of Unix and Linux today come preloaded with a version of vi. If you find yourself working on a Unix or Linux command line without your favorite graphical editor or other text editor you can always fall back to good old vi. While learning vi can be a daunting task at first, with practice anyone can become a vi expert. 16.2.1 What is vi 16.2.2 Starting vi 16.2.3 Vi Modes 16.2.4 Opening a file 16.2.5 Saving a file 16.2.6 Quitting vi 16.2.7 Vi compatible mode 16.2.8 Autosave (sort of)

16.2.9 Moving Around Vi 16.2.10 Editing Files 16.2.11 Searching in a file 16.2.12 Search and replace 16.2.13 Marking Text 16.2.14 Merging files 16.2.15 Split screen 16.2.16 Named buffers 16.2.17 Markers 16.2.18 Vimtutor 16.2.19 Help 16.2.1 What is vi The vi editor was originally created for the Unix operating system by Bill Joy in 1976 so it has been around for quite a while. The name vi is a shorthand for visual mode because the vi editor was originally created as a visual mode to another text editor named ex. There are still a lot of ex commands in vi today. 16.2.2 Starting vi To start vi type vi in the CLI. Most Linux distributions have upgraded vi to vim which stands for vi improved so you can also type vim.

When you start vi without providing a filename you will get the VIM start screen, as in the example below, that includes various information about vim.

16.2.3 Vi Modes Vi has five modes, vi mode, insert mode, replace mode, ex command mode, and search mode. 16.2.3.1 Vi Mode 16.2.3.2 Insert Mode 16.2.3.3 Replace Mode 16.2.3.4 Ex Command Mode 16.2.3.5 Search Mode 16.2.3.1 Vi Mode Vi starts in vi mode by default. This is also called command mode but there is another command mode that you will learn about shortly. In vi mode, vi will respond to commands that are typed vice placing characters in the file. You can return to vi mode any time by pressing the Esc key. You have to be in vi mode before you can enter any other mode. 16.2.3.2 Insert Mode Insert mode allows you to enter characters into the file. You enter insert

mode by entering vi editing commands in vi mode such as i for insert. If you press i in vi mode, -- INSERT -- will appear in the bottom left hand corner which means vi is in insert mode and ready for you to insert text as in the example below.

To exit insert mode and go back to vi mode press the Esc key. You should always press the Esc key before entering any vi command to make sure you are not in insert mode. 16.2.3.3 Replace Mode Replace mode allows you to replace characters in the file. You enter replace mode by pressing R in vi mode and -- REPLACE -- will appear in the bottom left hand corner which means vi is in replace mode and ready for you to replace text as in the example below.

To exit replace mode and go back to vi mode press the Esc key. You should always press the Esc key before entering any vi command. 16.2.3.4 Ex Command Mode Ex command mode is reached by pressing the : character in vi mode which will place a : character in the bottom left hand corner of the screen as in the example below. You can now enter ex commands that are separate from the commands you use in vi mode. The use of the ex mode for search and replace will be covered later in this chapter.

To exit ex command mode and go back to vi mode press the Esc key. You should always press the Esc key before entering any vi command. 16.2.3.5 Search Mode Search mode, which is reached by pressing the / character in vi mode, will place a / character in the left hand bottom of the screen as in the example below. You can now enter search strings for vi to search for in the file. The use of the search mode will be covered later in this chapter.

16.2.4 Opening a file When using vi, you can open a file via the command line or via ex commands in vi once the program has been started. The following subsections are covered in this section: 16.2.4.1 Opening a file from the command line 16.2.4.2 Opening a file from inside vi 16.2.4.3 Problems with opening an existing file 16.2.4.1 Opening a file from the command line To open a file from the command line with vi just put the name of the file behind the vi command.

If the filename already exists the file will be opened by vi. If the file does not exist a new file will be created with the filename specified. When a new file is created, vi will start with a blank screen with each empty line starting with the ~ character and the cursor at the top of the screen. The

lines with the ~ character are not actually lines in the file but rather a filler for the screen. The bottom right hand corner of the screen will have the filename and the word New File as in the example below.

If you open a file that already exists, the bottom left hand corner of the screen will contain the filename followed by the number of lines and the number of characters in the file. In the example below the bottom of the screen on the left hand side shows the filename followed by 1L, 24C. The 1L means the file contains 1 line and 24C means the file contains 24 characters. Spaces count as characters.

16.2.4.2 Opening a file from inside vi You can also open a file from inside vi using the ex commands :o filename or :e filename. If a file with the filename specified does not already exist, a new file will be created. In the example below :o is used to open a file named myfile.

If you already have a file open and all changes have been written to the file, vi will close the current file and open the new file. If you already have a file open and all changes have not been written to the file, vi will give you a No write since last change error, as in the example below. You can either write the changes to the file or you can override the error with the ! character. Be careful when using the override as all changes will be lost.

16.2.4.3 Problems with opening an existing file Be sure when opening existing files that you are in the correct location in the file system. A common mistake that new Linux users make is to try an open an existing file such as a configuration file while they are in the wrong directory. Vi will just create a new file with the same name in the current location without complaining. The user then gets confused because they are looking at a blank file when they expected something to already be there. Another common mistake that new Linux users make is opening a file in vi that they do not have write permissions to and attempting to edit the file. The example below shows an attempt to open a file to which the user has no permissions. At the bottom of the screen vi displays a Permission Denied error. The user attempted to open the /etc/shadow file which contains the hashed passwords for the user accounts on the Linux system. Only the root user can access the shadow file.

The example below shows the user opening a file to which they only have read permissions. The readonly warning is displayed at the bottom of the screen. The user can see the contents but cannot edit the file.

If the user attempts to edit a readonly file they will get an additional warning as seen in the example below.

If you really want to edit a readonly file you have two options. Option one is to close the file and use the sudo command to open the file thus giving you administrative or root privileges to the file. You may not be able to use the sudo command depending upon your permission on your system. Option two is to save the file under another name using the :w filename command. Once the new file is created you have to close vi and open the new file to have full control. This only works for files that you have read permission to and you have to save the file in a directory for which you have write permissions. For example if you are in the /etc directory and want to open and save a file under another name without using root permissions you will get a Can’t open file for writing error like the one in the example below. This is because normal users do not have write permissions to the /etc directory.

To overcome this limitation you can save the file to your home directory by putting ~/ in front of the filename. Each user has a home directory with full permissions to the files and directories in the home directory. In Linux ~/ means the home directory of the current user. :w ~/filename 16.2.5 Saving a file There are several ways to save a file in vi. 16.2.5.1 :w filename 16.2.5.2 Saving lines to a new file 16.2.5.1 :w filename The ex command :w filename can be used to write the changes to a file. Pressing : in vi mode will put vi into ex command mode and place a : in the bottom left hand corner of the screen. Commands entered in ex command mode will appear at the bottom of the screen next to the : character. In the example below, the ex command used is the w or write command.

In the example below the :w myfile command was used to save the file and vi shows that the changes have been written to the file.

If you are writing the changes to an existing file that is already open in vi you do not need to specify the filename with the :w command. You can just type :w and vi will save the file to the currently open file. You only have to

specify a filename if you are writing to the file for the first time or you want to save the current file under a new filename. 16.2.5.2 Saving lines to a new file You can save specific lines to a new file by adding line numbers to the front of the write command. For example :1,10w filename will write lines 1 to 10 into the filename specified. Normally the filename is a file other than the current file as it would make no sense to write specific lines of the current file back into the same file. In the example below lines 1 to 10 are saved to a new file named tophalf.

16.2.6 Quitting vi There are multiple ways to quit vi. 16.2.6.1 :q 16.2.6.2 :wq 16.2.6.3 Shift ZZ

16.2.6.1 :q To quit vi you can use the :q ex command. As long as there are no unsaved changes vi will exit without any errors. :q If there are unsaved changes vi will give a No write since last change error as in the example below.

To override this error you use the ! character after :q. Be careful when using the override as all changes will be lost. :q! 16.2.6.2 :wq If you want to save your changes and quit at the same time you can use the :wq ex command which saves the file and then quits vi. You can also use the :x ex command which does the same thing but with one letter. 16.2.6.3 Shift ZZ Holding Shift and pressing ZZ will also save and quit Vi.

My preference is Shift+ZZ but be careful with Shift+ZZ. When pressing Shift+ZZ to save and close you may mistakenly press Ctrl+Z which will suspend but not close vi. Vi will now be a background process and you will be returned to the CLI. The number in the square brackets [ 1 ]+ is the background process number for vi. Normally this will be 1 but if there are other suspended processes on your system it may be a higher number. Type fg 1 at the command line to bring vi back to the foreground. If the background process number for vi is something other than 1 be sure to use that number.

16.2.7 Vi compatible mode In some Linux distributions vim starts in vi compatible mode which means it acts like an older version of vi and not like vim. To stop this you can use the :set nocp however this only works for the current session. When vi is restarted the setting will be forgotten. 16.2.7.1 Creating a .vimrc file To make the set nocp permanent you will need to create a .vimrc file in your home directory. Rc files are runtime command files which means that when vim or vi starts it reads the .vimrc file for runtime settings. Make sure you are in your home directory and start vi with the filename .vimrc. cd ~/ vi .vimrc Press i to enter vi insert mode. Type set nocp without the : character as in the example below.

Press Esc to exit input mode. Type :wq to save and quit vi or press Shift+ZZ. Now every time vi starts the .vimrc file will be read and vi will function correctly. 16.2.8 Autosave (sort of) There is no autosave function in vi without using a script so use the :w command often to avoid losing your work. This will save you a lot of headaches, trust me. If vi should crash or shutdown unexpectedly there is a chance you can recover your file. When you are working on a file, vi creates a swap file in the current folder. A swap file is basically a temporary buffer used to hold the file until the changes are written to the disk. The swap file is a hidden file which starts with the . character and ends with a .swp file extension You can see hidden files by using the ls -la command from the command line. If vi should crash or you press Ctrl+C while you are in the middle of the

document, the swap file will contain the most recent copy of the file. When you try and open the document, vi will check for the existence of a swap file and give you the error seen in the example below if a swap file is found.

If you should get this error, close the file without making any changes and open the file again with the -r option for recovery. vi -r myfile If the recovery was successful be sure to go back and delete the .swp file to avoid getting the error again. rm .myfile.swp 16.2.9 Moving Around Vi Since vi is a text based editor, you can not use the mouse as you would normally use when editing a document in the GUI world. You have to rely on the keyboard to move around. In the following sections there will be very few examples as showing cursor movement in pictures is not very educational. My recommendation is that you practice the commands in vi to get a better appreciation of how the commands actual work.

16.2.9.1 Moving around with the arrow keys 16.2.9.2 Moving around with h j k l 16.2.9.3 w - Beginning of the next word or punctuation mark 16.2.9.4 W - Beginning of the next word ignoring punctuation mark 16.2.9.5 b - Beginning of the previous word or punctuation 16.2.9.6 B - Beginning of the previous word ignoring punctuation marks 16.2.9.7 e - End of the next word or punctuation mark 16.2.9.8 E - End of the next word ignoring punctuation marks 16.2.9.9 $ - End of the current line 16.2.9.10 0 - Start of the current line 16.2.9.11 :set nu 16.2.9.12 G - Last line in the file 16.2.9.13 [line number x]G - Move to line number x 16.2.9.15 H - Move the cursor to the top of the screen 16.2.9.17 L - Move the cursor to the bottom of the screen 16.2.9.18 Ctrl+f - Move forward one screen 16.2.9.19 Ctrl+b - Move backward one screen 16.2.9.21 Ctrl+u -Move backward one half screen 16.2.9.22 Ctrl+g - Show the current cursor position 16.2.9.1 Moving around with the arrow keys The most basic way to move around vi is with the arrow keys on the keyboard. You can use the arrow keys in vi mode and insert mode. Pressing the right arrow key moves the cursor to the right. Pressing the down arrow key moves the cursor down. Pressing the left arrow key moves the cursor left. Pressing the up arrow key moves the cursor up. You can also add a number to your arrow movement. For example pressing a 5 and the right arrow in vi mode will move the cursor 5 spaces to the right. You must be in vi mode, not input mode, for this to work. If you press 5 in input mode you will type a 5 in the document. You can always get to vi mode by pressing the Esc key.

The number + command combination is something that you will often see in vi. Using a number x causes your command or command combination to be repeated x number of times. 16.2.9.2 Moving around with h j k l In vi mode you can also move around with the h j k l keys. Thi is part of vi because keyboards did not always have arrow keys. h - move left j - move down k - move up l - move right 16.2.9.3 w - Beginning of the next word or punctuation mark Pressing w in vi mode will move the cursor to the beginning of the next word or punctuation mark from the current cursor location. The w command, like most movement commands, can be used with a number. Adding a number in front of the w command will move the cursor forward that number of words. For example 3w will move forward 3 words. Do not get the w movement command confused with the :w write command. The movement command is used in vi mode while the write command is used in ex command mode. 16.2.9.4 W - Beginning of the next word ignoring punctuation mark To move to the beginning of the next word ignoring punctuation marks use a capital W command. Adding a number in front of the W command will move forward that number of words. For example 3W will move forward 3 words. 16.2.9.5 b - Beginning of the previous word or punctuation The opposite of the w command is the b command. Pressing b will move the cursor to the beginning of the previous word or punctuation mark.

Adding a number in front of the b command will move backward that number of words. For example 3b will move backward 3 words or punctuation marks. 16.2.9.6 B - Beginning of the previous word ignoring punctuation marks The capital B command will move to the beginning of the previous word ignoring punctuation marks. Adding a number in front of the B command will move backward that number of words. For example 3B will move backward 3 words. 16.2.9.7 e - End of the next word or punctuation mark The e command will move the cursor to the end of the next word or punctuation mark. When moving to the end of a word, the cursor will be placed on the last letter of the word. Adding a number in front of the e command will move forward that number of words. For example 3e will move forward 3 words and place the cursor on the last letter of the 3rd word. 16.2.9.8 E - End of the next word ignoring punctuation marks The capital E command will move to the end of the next word ignoring punctuation marks. Adding a number in front of the E command will move forward that number of words. For example 3E will move forward 3 words place the cursor on the last letter of the 3rd word. 16.2.9.9 $ - End of the current line The $ command will move the cursor to the end of the current line. Adding a number in front of the $ command will move forward that number of lines and place the cursor at the end of the line. For example 3$ will move forward 3 lines and place the cursor at the end of the 3rd line from the current cursor position.

16.2.9.10 0 - Start of the current line The 0 (the number zero) command will move the cursor to the start of the current line. Adding a number in front of the 0 command will not move backward that number of lines. For example since 0 is a number placing a 3 in front of 0 forms the number 30. Vi sees this as the number 30 and the next command will execute 30 times. 16.2.9.11 :set nu The :set nu ex command can be used to turn on line numbers to help when moving around in a large document. To use the set nu command you have to type : first. If you want the numbers to be permanently turned on you can add the set nu command to the .vimrc file. When line numbers are turned on the lines numbers will appear to the left of each line as in the example below.

16.2.9.12 G - Last line in the file The G command will move the cursor to the last line of the file. 16.2.9.13 [line number x]G - Move to line number x Adding a number before the G command will move to that line number. It does not matter if you are above or below the target line number. 16.2.9.14 gg - Top of the file The gg command will move the cursor to the top of the file. 16.2.9.15 H - Move the cursor to the top of the screen The H command will move the cursor to the top of the current screen. In the examples below the starting position is line 21 which is in the middle of the screen. The top line on the screen is line 10. After pressing H the cursor moves to the top of the screen to line 10. This is different than the gg command which will move you to the top of the file i.e. line 1.

s

16.2.9.16 M - Move the cursor to the middle of the screen The M command will move the cursor to the middle of the current screen. If there are not enough lines to fill the screen then the cursor will move to the middle of the lines on the screen. 16.2.9.17 L - Move the cursor to the bottom of the screen The L command will move the cursor to the bottom of the current screen. 16.2.9.18 Ctrl+f - Move forward one screen The Ctrl+f command will move forward one screen and place the cursor at the top of the current screen. The last two lines on the screen will become the first two lines after pressing Ctrl+f which will create some overlap between screens. The number of lines on a screen is a function of how large the screen is and how many lines of text the screen can accommodate. Ctrl+f can be combined with a number to move forward that number of screens, for example 2 Ctrl+f to move forward 2 screens. 16.2.9.19 Ctrl+b - Move backward one screen

The Ctrl+b command will move backward one screen and place the cursor at the bottom of the current screen. The first two lines on the screen will become the last two lines after pressing Ctrl+b which will create some overlap between screens. Ctrl+b can be combined with a number to move backward that number of screens, for example 2 Ctrl+b to move backward 2 screens. 16.2.9.20 Ctrl+d - Move forward one half screen The Ctrl+d command will move forward one half screen and place the cursor at the top of the current screen. The last line on the screen will become the middle line after pressing Ctrl+d. 16.2.9.21 Ctrl+u -Move backward one half screen The Ctrl+u command will move backward one half screen and place the cursor at the bottom of the current screen. 16.2.9.22 Ctrl+g - Show the current cursor position If you do not have line numbers turned on and you want to know what your current cursor position in the file is you can use the Ctrl+g command. In the example below the position is displayed at the bottom of the screen. The position information includes the following. Filename Modification status Line number and number of total lines Percentage of the file where the current location is Current column number The percentage is the location of the cursor with 0% being the top of the file and 100% being the bottom of the file. So if the cursor was located in the middle of the file then the percentage would be 50%. The current column number starts at the far left as column 1 and increments as you move the cursor right.

16.2.10 Editing Files The purpose of using any text editor is to edit files. This section will cover the various editing commands in vi. 16.2.10.1 i - Insert text at current location 16.2.10.2 I - Insert text at the beginning of the line 16.2.10.3 a - Insert after current location 16.2.10.4 A - Insert after end of the current line 16.2.10.5 x - Delete text at the cursor 16.2.10.6 u - Undo the last change 16.2.10.7 Ctrl+r - Redo 16.2.10.8 dd - Delete the current line 16.2.10.9 D - Delete the to the end of the current line 16.2.10.10 Delete Command Combinations 16.2.10.11 p - Put text from the buffer after the current line 16.2.10.12 P - Put text from the buffer before the current line 16.2.10.13 yy - Copy current line (also known as yank) 16.2.10.14 Yank Command Combinations

16.2.10.15 r - Replace a single character 16.2.10.16 R - Replace text until Esc 16.2.10.17 o - Open a line below and enter insert mode 16.2.10.18 O - Open a line above and enter insert mode 16.2.10.19 cc - Change the current line 16.2.10.20 ~ to change the case 16.2.10.21 J - Join lines 16.2.10.1 i - Insert text at current location The basic insert command is the i command. Pressing i will put vi in insert mode and the word -- INSERT -- will appear at the bottom of the screen. The insert will occur wherever the cursor is located. 16.2.10.2 I - Insert text at the beginning of the line The I command will put vi in insert mode, the word -- INSERT -- will appear at the bottom of the screen, and the cursor will move to the beginning of the line. 16.2.10.3 a - Insert after current location The a command will put vi in insert mode, the word -- INSERT -- will appear at the bottom of the screen, and the cursor will move to the next character. The a command is used to insert text after the current cursor position. 16.2.10.4 A - Insert after end of the current line The A command will put vi in insert mode, the word -- INSERT -- will appear at the bottom of the screen, and the cursor will move to the end of the current line. 16.2.10.5 x - Delete text at the cursor You will not only be inserting text when editing a file but also deleting text. If you want to delete a character in vi you can use the x command. The x command will delete the character where the cursor is located.

The x command can be used with a number to delete more than one character at a time. For example 3x would delete 3 characters starting at the location of the cursor and going toward the end of the line. You can also delete multiple characters by pressing and holding the x key. As long as you hold the x key vi will delete characters. Be careful, however, as depending upon your system and how you are connected to the system, there may be a delay between the pressing of the x key and the actual deletion of the character on the screen. If there is a delay and you hold the x key too long you may end up deleting more characters that you intended. Another function of the x command is that the deleted characters are placed into a general buffer which can be used later to place the deleted characters back into the file. Placing characters in the buffer back into the file will be covered later with the p and P commands. 16.2.10.6 u - Undo the last change If you make a mistake in either insertion or deletion of text you can undo your changes by using the u command. Changes are kept in a buffer so you can go back multiple changes. When the u command is used, it provides information about what was undone at the bottom of the screen. The u command can be used with a number to undo more than one change at a time. For example 3u would undo the last 3 changes. 16.2.10.7 Ctrl+r - Redo If you want to undo an undo, also known as a redo, your can use the Ctrl+r command. As with the undo command the redo information comes from the buffer so using the u and Ctrl+r commands you can step through changes made to a file. The Ctrl+r command can be used with a number to redo more than one change at a time. For example 3 Ctrl+r would redo the last 3 undos. 16.2.10.8 dd - Delete the current line

You learned previously that you can use the x command to delete a single character or add a number in front of the x command to delete multiple characters at the same time. If you want to delete an entire line at one time you can use the x command to delete each character in the line or you can use the dd command to delete the line. The deleted lines will be removed and the text will be moved up to fill the now empty space. The dd command can be used with a number to delete more than one line at a time. For example 3dd would delete 3 lines starting at the location of the cursor and going toward the end of the file. Another function of the dd command is that the deleted lines are placed into a general buffer just like the x command which can be used later to place the deleted lines back into the file. 16.2.10.9 D - Delete the to the end of the current line The D command will delete a line like the dd command with one exception. The D command will leave a blank line where the line was and the dd command will remove the line and fill in the text by moving the lines below up. The D command can be used with a number to delete more than one line at a time. For example 3D would delete 3 lines starting at the location of the cursor and going toward the end of the file. When used with a number, however, the D command acts just like the dd command and will not leave blank spaces. Text deleted with the D command is placed into a general buffer which can be used later to place the deleted lines back into the file. 16.2.10.10 Delete Command Combinations In vi commands can be used in combination with movement commands to do some very specific things. The d command is one of these commands. You have already seen that the dd command is used to delete a line. Since the dd command is a combination of two d’s once the first d is pressed Vi waits for a second command before performing any action. Not all

commands are like this. For example the i command will put vi into insert mode as soon as the i is pressed so this is not a command that can be used in a combination command. Combination commands usually take the following form: action command + movement command For example the w command is a movement command that is used to move the cursor to the beginning of the next word. Combine the d action command with the w movement command and you get a combination command, dw, that will delete from the current cursor position to the beginning of the next word. Most combination commands can also take a number at the beginning to perform the action a certain number of time. For example 3dw will delete from the cursor to the beginning of the 3rd word from the cursor. Figure 16-1 shows examples of combination command using the d command. This is not a complete list just an example of some common combinations.

Figure 16-1. Combination command using the d command

16.2.10.11 p - Put text from the buffer after the current line Following the placing of text into the buffer using a delete or copy command, you can place the text from the buffer back into the file by using the p command. The p command will place the text from the buffer after the

current line where the cursor is located. Using a number with the p command with a number will cause the text in the buffer to be placed that number of times into the file. 16.2.10.12 P - Put text from the buffer before the current line The P command will place the text from the buffer before the current line. 16.2.10.13 yy - Copy current line (also known as yank) If you want to copy an entire line you can use the yy command. Text that is copied with the yy command will be placed in the general buffer and can be placed back into the document using the p or P commands. The yy command can be used with a number to copy more than one line at a time. For example 3yy would copy 3 lines starting at the current location of the cursor and going toward the end of the file. When pasting the lines back into the document with the p or P command it is not necessary to use a number as all lines are copied at the same time and stored in the general buffer together. You can also obtain the same results of the yy command with the Y command but you can not use the Y command in combination commands. You can use the Y command with a number just like the yy command. 16.2.10.14 Yank Command Combinations The y command, like the d command, can be used in combination with movement commands. The y command operates much like the d command except it does not delete the text. The y command only places copied text in the general buffer for later use. Figure 16-2 shows examples of combination command using the y command. This is not a complete list just an example of some of the most common combination.

Figure 16-2. Combination command using the y command

16.2.10.15 r - Replace a single character If you want to replace a single character in a file you could use the x command to delete the character and then the i command to insert a character or you could use the r command to allow the replacement of the single character. To use the r command you place the cursor on the character that needs to be replaced and press r. The next character you type will replace the character that the cursor is on. Once the character is replaced vi goes back into vi mode. The r command can be used with a number to replace more than one character at a time but not with the result you may expect. For example 2r followed by the character a will replace the character the cursor is on and the next character with the character a. 16.2.10.16 R - Replace text until Esc If you want to replace more than one character without deleting and inserting then you can use the R command. The R command will put vi into replace mode. The word -- REPLACE -- will appear at the bottom of the screen. Replace mode is different than insert mode in that characters typed in

replace mode will overwrite the characters on the screen while insert mode will place the new character in front of the characters on the screen. Vi will stay in replace mode until you press Esc to return to command mode. While in replace mode you can use the arrow keys to move around the file and replace characters in multiple places. You cannot use letter movement commands in replace mode as vi will just replace the current cursor location with the letter you typed. The R command does not work with numbers or any other command. 16.2.10.17 o - Open a line below and enter insert mode If you want to open up a blank line to enter text use the o command. The o command will open a blank line below the current line and put vi into insert mode. The o command can be used with a number to open up more than one blank line but the command does not operate as you would expect in fact it acts kind of weird. If you type 3o vi will open up one blank line and enter insert mode. Vi will not give you 3 blank lines unless you press Esc without typing any text. Once back in vi mode the other 2 blank lines will appear. If you type any text before pressing escape you will get 2 more copies of whatever you typed once you do press Esc. 16.2.10.18 O - Open a line above and enter insert mode The O command will open a line above the current line and put vi into insert mode. If you type 3O vi will open up one blank line and enter insert mode. Vi will not give you 3 blank lines unless you press Esc without typing any text. Once back in vi mode the other 2 blank lines will appear. If you type any text before pressing escape you will get 2 more copies of whatever you typed once you do press Esc. 16.2.10.19 cc - Change the current line The cc command is used to delete the current line and enter insert mode on

the blank line that is created. The cc command can be used with a number to delete more than one line at a time. For example 3cc would delete 3 lines starting at the location of the cursor and going toward the end of the file, however, you will be left with only one blank line. The cc command like the dd and yy commands is made up of two of the same letter and can be combined with movement commands to make combination commands. You can also obtain the same results of the cc command with the C command but you can not use the C command in combination commands. You can use the C command with a number. Figure 16-3 shows examples of combination commands with the c command.

Figure 16-3. Combination command using the c command

16.2.10.20 ~ to change the case Vi lets you change the case, upper to lower or lower to upper, of letters using the ~ command. The ~ command will toggle the case of the letter under the cursor. If the current case of a letter is lowercase then the ~ command will

change the letter to uppercase. If the current case of a letter is uppercase then the ~ command will change the letter to lowercase. The ~ command can be used with a number to change the case of multiple letters at the same time. For example 3~ will change the letter under the cursor and the next two letters for a total of 3. The ~ command cannot be used with movement commands like the d, c, and y commands can but you can mark text and change a group of text all at one time. Marking text will be covered later in this chapter. 16.2.10.21 J - Join lines Vi allows you to join two or more lines together using the J command. To use the J command, place the cursor on the line that you want to be the front of the new line and then press the J command. The location of the cursor on the line does not matter. The line directly below the current line will be added to the current line with 2 spaces in between the lines. The J command can be used with a number to join more than 2 lines together. For example 3J will join the current line and the next two lines together, for a total of 3 lines. 16.2.11 Searching in a file Vi has the capability to search a file for a specific piece of text. When searching for text you will be using the vi search mode. The following subsections will be covered in this section: 16.2.11.1 Search forward 16.2.11.2 n - Go to the next instance 16.2.11.3 N - Go to the previous instance 16.2.11.4 Search backward in a file 16.2.11.5 Ctrl o - Return to previous position 16.2.11.6 Ctrl i - Go back forward again 16.2.11.7 Up and down arrows to search again 16.2.11.8 % to find matching brackets

16.2.11.1 Search forward The / character is used for searching forward in vi. You have to be in vi command mode and not insert mode to conduct a search. When you press the / character, a / will appear in the bottom left hand corner of the screen. Type the text you want to search for and press enter. Vi will find the first instance of the search text working from the current cursor position down toward the bottom of the file. Vi will place the cursor on the first match if a match exists. In the example below the forward search function is used to search for the word yet.

If Vi can not find the text in the file you will get a Pattern not found error as in the example below.

16.2.11.2 n - Go to the next instance To continue the search for the next instance you can just press n. Using the n command to search for the next instance will work until the next search term is used even if you leave search mode and enter insert mode. You will have to be in vi command mode to use the n command after insert mode. 16.2.11.3 N - Go to the previous instance If you want to search in the opposite direction you can use the N command to go back to the previous instance. When you use the N command after performing a forward search, the search character at the bottom of the screen will switch from / to ?. The ? character is for searching backwards, as in the example below.

One important distinction needs to be made here. The n and N commands may go toward the bottom or top of the file depending upon which direction you start the search. If you start your search in the forward direction then the n command will take you forward, toward the bottom of the file, and the N command will take you backward, toward the top of the file. If you start your search in the backward direction then the n command will take you backward, toward the top of the file and the N command will take you forward, toward the bottom of the file. The n command keeps searching in the same direction and the N command reverses the search direction. I know this may be a little confusing but with a little bit of practice you should get the hang of it. 16.2.11.4 Search backward in a file The ? character is used for searching backward. When you press the ? character a ? will appear at the bottom of the screen. Type the text you want

to search for and press enter. Vi will find the next instance of the text working from the current cursor position up to the top of the file. In the example below the backward search function is used to search for the word this.

As with the forward search function the n and N commands can be used to search for the next instance either forward or backward in the file. 16.2.11.5 Ctrl o - Return to previous position When searching you may want to return to the position where you started the search. Ctrl+o will let you step back through your search to the original starting location. Ctrl+o works with either / or ?. 16.2.11.6 Ctrl i - Go back forward again Ctrl+i is the opposite of Ctrl+o. Ctrl+o returns you back in the direction the search came while Ctrl+i will take you in the direction of the original search. For example if you search through a document for a word and get to the end of the file you can use Ctrl+o to step back all the way to the original cursor position.

At any time you can use Ctrl+i to step back through the searches again up to the last found instance. If there are more instances past the last found instance Ctrl+i will not take you there. You will have to use the n command to continue the search. Ctrl+o and Ctrl+i are not just for searches. They just take you where you have already been and can be used with other commands such as movement commands to return you to your previous location. 16.2.11.7 Up and down arrows to search again If you want to execute a search again based upon a previous search term you can use the up and down arrows after pressing / or ? to scroll back through your past searches. Once you find the search you were looking for just press enter to execute the search. 16.2.11.8 % to find matching brackets If you are a programmer then the % character will be very useful to you. The % character will allow you to put the cursor on a bracket ( ), [ ] , { } and find the corresponding bracket anywhere in the file. Again if you are a programmer you know how valuable this is. In the examples below the cursor is on the bracket at the end of line 1. Pressing the % character takes the cursor to the corresponding bracket on line 11. The brackets on line 5 and line 9 belong together as nested code so they are ignored by the % search. This search will work in either direction. If the cursor is on the bracket on line 11 and the % character is pressed the cursor would move to the bracket on line 1.

16.2.12 Search and replace The search and replace function of vi is a great way to replace a single word or section of text on a line or every instance of the word or section of text in a file. To perform a search and replace you first have to start with :s ex command followed by the old and new word or text separated by the / forward slash. :s/old word/new word

To replace all instances in a line add a /g to the end of the search. :s/old word/new word/g You can replace the text in more than one line at a time by specifying the line numbers to apply the search and replace. :1,3s/new word/old word In the examples below the search and replace function replaces the first word text in lines 1 to 3.

At the bottom of the screen vi will tell you how many substitutions were made and the number of lines that were affected.

In the examples below the /g is added to the search string to replace all instances of the word text in lines 1 to 3.

To replace all instances of text in a file without using line numbers start the search command with :% and end it with /g. :%s/old word/new word/g Adding a c to the end of the search command will cause vi to ask before making any replacements. :%s/new/old/gc Figure 16-4 shows the possible answers y/n/a/q/l/^E/^Y.

Figure 16-4. Search and replace answers

In the example below vi asks before replacing text.

16.2.13 Marking Text Vi stands for Visual Editor and while most of the work in vi is command line work there are some visual functions that you can use. 16.2.13.1 v - Mark visually with arrow keys

16.2.13.2 Saving marked text 16.2.13.1 v - Mark visually with arrow keys To mark text visually put the cursor on the first character that you want to mark and press v in vi command mode. You can then use the arrow keys or the h, j, k, and l keys to move the visual marking to the end of the area you want to mark. In the bottom left hand corner you will see the word -VISUAL -- to indicate that you are marking text visually as in the example below.

Once text has been marked visually a command can be used to modify the text. For example, you can use the d to delete, y to yank, c to change, or ~ to change case commands to modify the marked text. 16.2.13.2 Saving marked text Marked text can also be saved to a different file. Once the text is marked visually press the : command and ‘ automatically appears at the bottom of the screen as in the example below. The ‘ characters stand for the start and end of the visual marking.

To save the text add w and filename as in the example below.

After the lines are saved, vi will display the filename, the number of lines, and the number of characters saved at the bottom of the screen as in the example below.

16.2.14 Merging files Vi allows you to merge the contents of two files together using the :r filename command. The imported text will be placed in the file under the current line where the cursor is located. 16.2.15 Split screen Vi allows you to open more than 1 file at a time in a split screen format using the :split filename or :new filename commands. The :split command without a filename will open the current file in the new window which will result in the same file being open in 2 windows. The :new filename command is a little misleading in that a new file will only be created if the filename does not exist. If the file already exists the contents of the file will be displayed. In the example below the new file is displayed in the top pane of the split screen.

The following subsections will be covered in this section: 16.2.15.1 Switching between windows 16.2.15.2 Resizing the window 16.2.15.3 Copy and paste between windows 16.2.15.4 Closing split windows 16.2.15.1 Switching between windows To switch between the split screen windows you can use the Ctrl+ww which switches to the next screen from top to bottom. If you have more than 2 windows and are in the last window Ctrl+ww will take you back to the top window. Ctrl+wj will move you down to the next window until you get to

the bottom. Ctrl+wk will move you up to the next window until you get to the top. 16.2.15.2 Resizing the window When vi splits the screen the windows are sized proportionally giving each window an equal part of the screen. If you want to adjust the window sizes you can use Ctrl+w - to decrease the window size and Ctrl+w + to increase the window size of the current window. You can also add a number to increase or decrease the window size more than one line at a time. For example, Ctrl+w 3+ will increase the window size by 3 lines. 16.2.15.3 Copy and paste between windows Once the window is split you can cut and paste text between the windows. Any buffers will also be available for pasting text between windows. 16.2.15.4 Closing split windows When you want to close a split window you can use the :close, :q, :wq, and Shift+zz commands in the window that you want to close. 16.2.16 Named buffers Whenever a c, d, or y command is used, the text being deleted, yanked, or changed is placed into a general buffer. The general buffer retains its contents until the next c, d, or y command. If you want to retain the text for a longer period of time or place more than one section of text into multiple buffers then you can use named buffers. Vi has 26 named buffers, a-z, that can be used to store text. To use named buffers, you start with the “ command which tells vi that you are using a named buffer. Following the “ command you add the letter for named buffer a-z. Following the named buffer you add the c, d, or y command. For example to delete 3 lines to a named buffer use the following command.

“a3d To paste the a named buffer into a file place the cursor in the proper location and use the following command. “ap Even though the a named buffer was used, the text in the buffer will remain in the buffer until the buffer is overwritten or vi is restarted. If you use a number to place more than 1 line into a named buffer it is not necessary to use the same number to get the lines out of the buffer. A paste command using a named buffer puts all of the contents of the buffer into the file. 16.2.17 Markers Vi allows you to place markers in a file that can be used to move or perform editing functions against. If you have a large file that you are working on and want to mark a location in the file in order to be able to return to the same location for editing in the future, you can place a marker at the location using the m command with any lowercase letter a-z. The marker will not be visible and will become part of the file so even when vi is restarted the marker will remain. To return to the marker use the ` command, the key under the Esc key on most keyboards, with the letter a-z that represents the marker. You can place multiple markers in a file. 16.2.18 Vimtutor On most Linux system Vim comes with a tutor called vimtutor. You can start vimtutor by typing vimtutor on the CLI. The example below shows the vimtutor start screen.

As you work through the vimtutor it will guide you through the commands and provide practice text to work with. When I was learning to use vi the vimtutor was a great help and I recommend that everyone goes through it at least once. 16.2.19 Help Vi has a great help function that allows you can search through the help documents for answers or get help for a specific command. Typing :help in vi will open a split window with the help window on the top and the file that was open at the bottom as in the example below. The file at the bottom is at the minimum window size. You can resize the bottom window by using Ctrl+ww to switch to the window followed by Ctrl+w+ to increase the window size.

You can go directly to a specific command in the help screen by type :help command. In the example below typing :help d shows the help file for the d command.

In the help files you will see tags between bars that are links to other files. To navigate to one of files place the cursor in between the bars and press

Ctrl+]. Help will take you to the file for the topic in the tag. To return to the previous screen press Ctrl+o.

Help files are read only so when you want to close a help window you can only use the :close, :q and Shift+zz commands.

17. PROCESSING TEXT FILES

17. Processing text files Linux is very good at handling and processing text files. This chapter will look at some of the most popular commands for processing text files. The following sections are covered in this chapter: 17.1 Viewing text files 17.2 wc - Word Count 17.3 diff - Compare files 17.4 grep 17.5 sort 17.6 paste 17.7 nl 17.8 uniq

17.1 Viewing text files Linux has several commands for viewing text files from the CLI. 17.1.1 cat 17.1.2 head 17.1.3 tail 17.1.4 more 17.1.5 less 17.1.1 cat The cat command will print the contents of a file to the CLI.

If you want to see line numbers use the cat command with the -n option.

17.1.2 head The head command can be used to see the top of a file. By default the head command will show the first 10 lines of a file as in the example below.

To see a specific number of lines use the head command with the -n option followed followed by the number of lines to display as in the example below.

17.1.3 tail The tail command can be used to see the bottom of a file. By default the tail command will show the last 10 lines of a file as in the example below.

To see a specific number of lines use the tail command with the -n option followed followed by the number of lines to display as in the example below.

17.1.4 more When viewing large files from the CLI with the cat command not all of the file contents can be viewed in one screen. Using the more command will show a file one screen at a time as in the example below. You can move forward one screen by pressing the spacebar or one line by pressing the enter key. You can exit more by pressing Q for quit. The more command will exit automatically when the end of the file is reached.

17.1.5 less Using the less command will show a file one screen at a time just like the more command with a couple of exceptions. You can move forward and backward with the less command. You can move forward one screen by pressing the spacebar or one line by pressing the enter key. When using the less command can also use the PgUp, PgDn, and arrow keys to move through the file. You can exit less by pressing Q for quit. When the end of the file is reached the word (END) will appear in the bottom left hand corner of the screen but less will not exit unless you press the Q key.

17.2 wc - Word Count The wc command can be used to count the words, lines, and bytes in a file. In the example below the wc command is used to examine the file file1.txt. The output shows the number of lines, the number of words, bytes, and the filename.

If you only want to see the number of words in the file you can use the -w option as in the example below.

If you only want to see the number of lines in the file you can use the -l option as in the example below.

17.3 diff - Compare files If you want to compare two files to find the differences between the files, you can use the diff command. This can come in handy especially when working with configuration files. In the example below the diff command is used to examine the differences between file2.txt and file3.txt. The output shows the lines from both files where differences are found.

17.4 grep The grep command can be used to search a file for a specific string. The following is the syntax for the grep command: grep -options string filename In the example below the grep command is used to search file2.txt for the word file.

You can use the grep command with the -n option to see the line numbers for the matching lines as in the example below.

17.5 sort The sort command can be used to sort the contents of a file. In the example below, the cat command is used to view the contents of the file file1.txt. The file contains an unsorted list of first names.

The sort command is used to sort the file and output the results to the CLI. The default sort is alphabetical in ascending order.

To reverse the sorting order use the -r option.

To output the sorted list to a file use the -o option followed by the filename to output the sorted list into. In the example below the file file1.txt is sorted and output to the file sorted.file1.txt. The cat command is used to view the contents of the new file.

The sort command can also be used to sort numbers. In the example below the cat command is used to view the file file1.txt which contains a list of numbers.

When the sort command is used to sort numbers it will sort them alphabetically by default not by numerical order as can be seen in the example below.

To sort the numbers numerically use the -n option.

The sort command can be used to sort months using the -M option.

17.6 paste The paste command can be used to combine two files together in columns.

In the example below the file first.names is a list of first names and the file last.names is a list of last names. The paste command puts the two files together.

You can redirect the output the paste command to another file by using the > redirector.

17.7 nl The nl command can be used to add number lines to a file. In the example below the cat command is used to view the file file1.txt.

The nl command is used to add numbers to the file file1.txt and print the output to the CLI.

You can send the output to a new file by using the > redirector.

17.8 uniq The uniq command can be used to remove duplicate lines from a file. In the example below the cat command is used to view the file file1.txt which has duplicate lines.

The uniq command is used to remove the duplicates and print the remaining lines to the CLI.

You can send the output to a new file by using the > redirector.

18. NETWORKING

18. Networking It is very likely that you will be using your Linux system on a network or some sort. There are several utilities that can be used to configure and control networking in Linux. The following sections will be covered in this chapter: 18.1 Network manager 18.2 Configure Networking 18.3 Testing Network Connectivity 18.4 Name Resolution 18.5 route

18.1 Network manager Most modern Linux desktop systems use a Network Manager to control the configuration of networking. While this simplifies the configuration of networking it also means that control from the CLI is minimal. The following subsections will be covered in this section: 18.1.1 Disabling the Network Manager 18.1.2 Enabling the Network Manager 18.1.1 Disabling the Network Manager If you want to be able to configure Linux networking from the CLI you will need to disable the Network Manager and configure networking the good old fashioned way. I recommend this approach for new Linux users who really want to learn how to use Linux from the CLI. The Network Manager makes configuring networking so easy that vital CLI skills can easily be lost. To disable the Network Manager use the systemctl command with the disable option followed by network-manager.service as in the example below. Disabling a service means that the service will not start on the next boot.

Even though you disabled the service it will still be running so you can also use the systemctl command to stop the network-manager service.

Even after disabling and stopping the Network Manager, the system interfaces may still have IP address assigned by the Network Manager. To clear the interfaces you can either reboot the system or flush the interfaces. To reboot use the following command: sudo reboot To flush the interfaces use the following command: sudo ip address flush dev interface_name In the example below the ip command is used to flush the enp0s3 interface.

18.1.2 Enabling the Network Manager If you want to use the Network Manager again you will have to enable and start the Network Manager. To enable the Network Manager use the systemctl command with the enable option followed by network-manager.service as in the example below. Enabling a service means that the service will start on the next boot. Even though you enabled the service it will still be not running until you use

the systemctl command to start the network-manager service.

18.2 Configure Networking After disabling the Network Manager and rebooting you will not have any configured interfaces so you will have to configure networking manually from the CLI. 18.2.1 ifconfig 18.2.2 List all interfaces 18.2.3 Configure a static IPv4 address 18.2.4 Configure a static IPv6 address 18.2.5 dhclient 18.2.6 Wireless Networks 18.2.7 Configuring Interfaces on Boot 18.2.8 ifup 18.2.9 ifdown 18.2.1 ifconfig The ifconfig command is the swiss army knife of Linux networking. You can use this one command to configure all of the necessary network parameters to get your system on the network. Your Ubuntu system may not have ifconfig installed by default. If so you will need to install net-tools via apt-get. sudo apt-get install net-tools

The ifconfig command without any options will show a list of all active interfaces on your system. The example below shows the output of the ifconfig command from an Ubuntu system. The enp0s8 interface is an ethernet interface and the lo interface is a loopback interface.

You can use ifconfig with the interface name to show information about a single interface.

The first part of the ifconfig command output is the name of the network interface. Older versions of Ubuntu named the ethernet interfaces starting with eth and ending with the number of the interface starting at 0. The first ethernet interface was named eth0, the second eth1, the third eth2 and so on. Wireless interfaces were names wlan ending with the number of the interface starting a 0. The problem with this naming convention is that there was no control over which interface got which name. During the boot process the interfaces would get named by which interface was enabled first. This method was unpredictable and caused issues with interface names changing when additional interfaces were added to a system. Newer versions of Ubuntu name the interfaces based on hardware information. All ethernet interfaces start with en for ethernet or wl for wireless. Next there will be either an o for onboard devices, i for PCI Express hot plug devices, and p for PCI devices. Following the o or i will be a number that represents the slot number. Following the p will be the PCI bus number followed by an s followed by the slot number. Since these names are based on the hardware information of the interface the names do not change. The following are some examples of interface names. eno1 eni2 enp0s3 wlp3s0 There is also an interface known as a loopback interface and is named lo.

The loopback interface always gets the IP address 127.0.0.1. The following is the first line of the ifconfig output. enp0s8: flags=4163 mtu 1500 Following the interface name are the interface flags which show the status of the interface. UP means that the kernel modules for the interface have been loaded. BROADCAST means that the interface supports broadcasting. RUNNING means that the interface is ready to accept data. MULTICAST means that interface supports multicasting. The mtu 1500 means that the Maximum Transmission Unit is set to 1500 bytes which is the default for ethernet interfaces. The following is the second line of the ifconfig output. inet 192.168.56.101 netmask 255.255.255.0 broadcast 192.168.56.255 The inet label is the IPv4 address for the interface, the netmask label is the network mask for the interface, and the broadcast label is the broadcast address for the interface. The following is the third line of the ifconfig output. inet6 fe80::a00:27ff:fe83:6540 prefixlen 64 scopeid 0x20 The inet6 label is the IPv6 address for the interface, the prefixlen label is the IPv6 network mask for the interface, and the scopeid label is the scope for the interface. The following is the fourth line of the ifconfig output. ether 08:00:27:83:65:40 txqueuelen 1000 (Ethernet) The ether label is the Media Access Control (MAC) address for the interface. The MAC is a 48 bit hexadecimal address that is unique to each device. The txqueuelen label is the size of the transmit queue in number of frames. The (Ethernet) label means that this is an ethernet interface. The following is the fifth through eighth lines of the ifconfig output. RX packets 0 bytes 0 (0.0 B)

RX errors 0 dropped 0 overruns 0 frame 0 TX packets 38 bytes 4842 (4.8 KB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 The RX stands for receive and the TX stands for transmit. The fifth line shows the number of packets and bytes received. The sixth line shows the number of receive errors, dropped packets, overruns, and frame errors. The seventh line shows the number of packets and bytes transmitted. The eighth line shows the number of transmit errors, dropped packets, overruns, carrier errors, and frame collisions. 18.2.2 List all interfaces The ifconfig command without any options will only show active interfaces. In order to see a list of all interfaces on your system use ifconfig -a. 18.2.3 Configure a static IPv4 address You can use the ifconfig command to configure a static IPv4 address on an interface. The syntax is as follows: sudo ifconfig interface_name ipv4_address netmask subnet_mask In the example below the ifconfig command is used to configure the enp0s8 interface with the IPv4 address 192.168.56.101 and a subnet mask of 255.255.255.0.

This IPv4 address, however, will not be permanent. If the interface is restarted, networking is restarted, or the system is rebooted, the IP address will be lost. 18.2.4 Configure a static IPv6 address You can use the ifconfig command to configure a static IPv6 address on an interface. The syntax is as follows: sudo ifconfig interface_name add ipv6_address/prefix In the example below the ifconfig command is used to configure the enp0s8

interface with the IPv6 address fe80::2 and a prefix length of 64.

18.2.5 dhclient If you want to use the Dynamic Host Control Protocol (DHCP) to get an IP address from a DHCP server, you can use the dhclient command. The syntax is as follows: sudo dhclient interface_name In the example below, the dhclient command is used to get an ip address for the enp0s3 interface.

18.2.6 Wireless Networks If you have a wireless card on your Linux system and are not using the Network Manager you can configure the wireless connection from the CLI. The following subsections are covered in this section: 18.2.6.1 Finding Wireless Interface 18.2.6.2 ip link 18.2.6.3 Locating a Wireless Network 18.2.6.4 Connecting to a Wireless Network with WPA 18.2.6.5 Connecting to a Wireless Network with WEP 18.2.6.6 Connecting to a Wireless Network without security 18.2.6.1 Finding Wireless Interface Before you can configure a wireless interface you have to know the name of the interface. For wireless interfaces the iw command with the dev option can be used. The most important piece of information is the Interface name which in the

example below is wlp3s0.

18.2.6.2 ip link The ip link command can be used to find additional information about the wireless interface.

The ip link command can also be used to enable the wireless interface. Enabling the wireless interface does not connect it to an access point as seen in the example below. The iw command can be used to show the status of the link.

The ip link command can also be used to show the status of the wireless interface as seen in the example below. The current state of the interface is DOWN.

18.2.6.3 Locating a Wireless Network In order to connect to a wireless network you have to know what the Service Set Identifier (SSID) is. When using Network Manager it is very easy to see what networks are available. To see a list of available wireless networks from the CLI you can use the iwlist command with the scan option as in the example below. The iwlist command will produce a lot of output so you can pipe the output to the grep command to isolate the SSID. In the example below there are 3 wireless networks.

To find out which wireless networks are using Wi-Fi Protected Access (WPA) add WPA to the grep command as in the example below. You will need to enclose the search terms in single quote and place the \| characters in between the terms. In the example below Network1 and Network2 are using WPA and Network3 is not.

18.2.6.4 Connecting to a Wireless Network with WPA In order to connect to a wireless network using WPA for security you will

have to use the wpa_passphrase and wpa_supplicant commands to configure a WPA passphrase. The first step is using the wpa_passphrase command to set the WPA passphrase for the network you want to connect to. You will have to enter the phase phrase and then press enter. One quirk about the wpa_passphrase command is that you cannot use the sudo command with the command. In the example below the wpa_passphrase command is used with the sudo command and generates a Permission denied error.

You can use the sudo command with the -s option to access the root prompt. You will then be able to run the wpa_passphrase command. After you enter the command and press enter you will be given a blank line without any prompt. Just type in the passphrase and press enter. The output of the command will be redirected to the /etc/wpa_supplicant/wpa_supplicant.conf file. Be sure to remember to exit the root prompt when you are done.

You can use the cat command to verify the contents of the /etc/wpa_supplicant/wpa_supplicant.conf file. The file contains the SSID, cleartext passphrase, and the encrypted passphrase.

Next you will use the wpa_supplicant command to establish a wireless connection. The -B option runs the command as a background process. The -D option tell the command which wireless drive to use. In the example below the wext generic driver is used. The -i option defines the wireless interface, which is wlp3s0 in the example below. The -c option specifies the configuration file /etc/wpa_supplicant/wpa_supplicant.conf. When the command runs you may get 2 Invalid argument errors but do not worry as this is normal.

You can use the iw command to verify that the connection is complete.

If the connection was successful, you can use the dhclient command to get

an IP address from the DHCP server or set a static IP address.

When you test your configuration with ping you may find that you can ping IP addresses but not domain names as in the example below. This most likely is a problem with the /etc/resolv.conf file.

Take a look at the /etc/resolv.conf file and you may see the line below which tells the Linux system which nameserver to use for DNS resolution. The IP address 127.0.0.1 is the loopback interface which means that the system is asking itself for DNS queries. nameserver 127.0.0.1 Change the nameserver to 8.8.8.8 and you should be able to ping domain names.

nameserver 8.8.8.8

18.2.6.5 Connecting to a Wireless Network with WEP When connecting to a wireless network with WEP security the iw command with the connect and key options as in the example below.

18.2.6.6 Connecting to a Wireless Network without security When connecting to a wireless network without any security such as an Internet cafe you can use the iw command with the connect option as in the example below.

18.2.7 Configuring Interfaces on Boot When not using Network Manager you can use the /etc/network/interfaces file to configure the interfaces to start automatically on boot. Since the /etc/network/interfaces file is a configuration file so you will need to use the sudo command to edit the file. sudo vi /etc/network/interfaces The example below shows an example of a default interfaces file. Only the loopback interface lo is defined. Any line that starts with the # character is seen as a comment and has no effect on the parsing of the file.

To add additional interfaces to the file place the new configurations below the loopback interface. The following lines add the enp0s3 interface.

In the first line the auto enp0s3 line tells Linux to start the enp0s3 interface automatically during boot. In the second line the iface stands for interface followed by the interface name enp0s3. The inet stands for the internet options, in this case dhcp, which will cause the interface to get an IP address from a DHCP server. The following lines add the enp0s8 interface.

In the first line the auto enp0s8 line tells Linux to start the enp0s8 interface automatically during boot. In the second line the inet option is static. The third line uses the address keyword to define the static IPv4 address 192.168.56.150. The fourth line uses the netmask keyword to define the subnet mask 255.255.255.0. The last line uses the gateway keyword to define the default gateway 192.168.56.1. 18.2.8 ifup Once you save the file you can use the ifup command to enable the interfaces as in the example below.

You can verify the interfaces have IP addresses with the ifconfig command. 18.2.9 ifdown If you want to take an interface down you can use the ifdown command.

18.3 Testing Network Connectivity Sometimes your networking may not work as expected and you will need to troubleshoot the problem by testing the network connectivity. The following commands will be covered in this section: 18.3.1 ping 18.3.2 traceroute 18.3.1 ping The ping command is a basic troubleshooting command that can be used to verify network connectivity. The following subsections will be covered in this section: 18.3.1.1 Loopback 18.3.1.2 Default Gateway 18.3.1.3 IP 18.3.1.4 Hostname 18.3.1.1 Loopback If you ping the loopback address 127.0.0.1 it verifies that the networking service is working. In the example below the ping command is successful. Each line 64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.073 ms indicates a successful ping. The ping command will continue until you press Ctrl+C.

In the example below the ping to the loopback address is unsuccessful as the network service is not running.

18.3.1.2 Default Gateway On a network the default gateway is the router or device that leads out of the network usually eventually to the Internet. If your system cannot communicate with the default gateway then it cannot access the Internet. The default gateway is normally the first usable IP address in a network but that is not a requirement. For example, if the network is 10.0.2.0/24 then the default gateway would be 10.0.2.1. In the example below the ping to 10.0.2.1 was successful meaning the system can communicate with the default gateway.

If you are unable to ping the default gateway it does not mean that there is anything wrong with your system as it could be a problem with the network. 18.3.1.3 IP If you can ping the default gateway the next step is to ping something past the default gateway, preferably something on the Internet. In the example below, a ping to 8.8.8.8 is successful which means that everything is working and the system is able to reach the Internet. The ping command used the -c 3 option which cause the ping command to only do three pings and then stop vice running until pressing Ctrl+C.

18.3.1.4 Hostname While pinging an IP address on the Internet will show you if your network connectivity is working it does not give you the entire picture. In order to be

able to access web pages and other services by using a hostname requires DNS to be configured and working correctly.

18.3.2 traceroute The traceroute command is used to trace the path of the IP packets from your system to another system. In the example below the traceroute command is used to trace packets to www.somewebsite.com.

18.4 Name Resolution Name Resolution is the process of converting hostnames to IP addresses. The way the Internet works today we mostly use hostnames and domains to connect to websites and other resources. Your system, however, needs to know the IP address of where you want to go in order to get there. 18.4.1 /etc/hosts 18.4.2 DNS 18.4.1 /etc/hosts

When the Internet was very young, you had to know the IP address of any site that you wanted to access. Then the hosts file was created and shared among the users of the Internet which worked because there were not many people on the Internet. The hosts file holds the manual mapping of hostnames to IP address. With the advent of DNS the hosts file was no longer necessary but it still remains in Linux as a fallback Name Resolution method. The example below shows the default Ubuntu hosts file.

If you want to add a custom IP to hostname mapping you must edit the /etc/hosts file. The following is the syntax for entries: ip_address

hostname

18.4.2 DNS The Domain Name System (DNS) is a system for naming systems on the Internet based on resource locators, hostnames, and domains and providing a mechanism to rapidly distribute updates when things change. When you use a web browser to connect to a website you type if something like www.somewebsite.com which is known as a Universal Resource Locator (URL). Starting from the right and moving left the URL starts with .com which is a Top Level Domain (TDL). There are lots of TDLs, .com, .net, .org, .mil, and each TDL has an organization that controls the TDL. The next part of the URL is the domain name, somewebsite. When someone registers a domain name, the domain name is registered with the appropriate TDL controlling authority which which will in turn advertise DNS information about the domain. The last part of the URL is the resource

locator www which is the resource locator for a web page. The following commands will be covered in this section: 18.4.2.1 nslookup 18.4.2.2 dig 18.4.2.1 nslookup The nslookup command can be used to query the DNS server for information about domains. The basic use of the nslookup command from the command line as in the example below.

The output lists the IP address of the DNS server. The line Nonauthoritative answer: means that the answer is not from the main DNS server responsible for the domain but rather another DNS server that knows the answer. The last part of the output is the name you were looking for and the IP address. If you type the command nslookup without putting in a domain name you will enter interactive mode. In interactive mode you will have a > character that means nslookup is awaiting your input.

The server option in interactive mode will show you which DNS server you are getting name resolution from. You can also use the server option to

change the DNS server to query. This will not change the server which is used for normal name resolution. In the example below the DNS server is changed to 10.8.4.3.

The set type option allows you to change the type of DNS record to look for. By default nslookup shows a records which are resource records. In the example below, the type is set to ns which is for nameservers or DNS servers. The example below shows four name servers for the domain somewebsite.com.

In the example below, the type is set to mx which is for mail exchangers or email servers. The example below shows five email servers for the domain somewebsite.com.

In the example below, the type is set to a which is for resource records. The example below shows the a record for www.somewebsite.com.

In the example below, the type is set to aaaa which is for IPv6 resource records. The example below shows the aaaa record for www.somewebsite.com.

To exit nslookup interactive mode, type exit. 18.4.2.2 dig The dig is another command that can be used to query the DNS for information about domains. The basic use of the dig command is from the command line as in the example below. The output lists the IP address of www.somewebsite.com. The flag line AUTHORITY: 0 means that the answer is non-authoritative.

The dig command by default looks for a records. The dig command can also be used to lookup other types of records by using the -t option followed by the type of record, ns, mx, a, or aaaa.

18.5 route The route command is used to view the network routes that your system knows about. On most systems with only one NIC there is not much to do with routes. The most important route that your system has is a route to the default gateway which is the route to to Internet.

If your system has multiple NICs then will be multiple routes. It is important to make sure that default gateway is pointed in the right direction. The syntax to add a default gate is as follows: route add default gw ip_address dev interface_name In the example below the route command is used to add 192.168.56.1 as the default gateway which can be reached via the enp2s0 interface.

19. INSTALLING SOFTWARE

19. Installing software One of my favorite things about Linux is being able to install free software to do just about anything you want. While there are many ways to install software, most modern Linux systems have a package management system. Ubuntu use .deb packages and apt-get.

19.1 apt-get Ubuntu can install software from the command line using the apt-get command which is used to update and install software. The following apt-get commands will be covered in this section: 19.1.1 apt-get update 19.1.2 apt-get upgrade 19.1.3 apt-get dist-upgrade 19.1.4 apt-get install 19.1.5 apt-get cache 19.1.6 apt-get remove 19.1.1 apt-get update Before installing any software you should always update your system. The apt-get command with the update option will refresh all of the software sources and look for any new software for your system. The example below shows the use of the apt-get update command. Notice that the sudo command is used and a password is required.

19.1.2 apt-get upgrade Once the software sources have been updated, you can use the apt-get command with the upgrade option to install any updates. The apt-get upgrade command will only update software installed via the package management system, either the GUI version or apt-get from the command line. The example below shows the use of the apt-get command with the upgrade option. Before software is updated you may have to press y to agree to continue.

19.1.3 apt-get dist-upgrade The apt-get command with the dist-upgrade option will update software dependencies along with new versions of packages. Sometimes the apt-get upgrade command will not be able to update all software, however the dist-

upgrade option can. The example below shows the use of the apt-get command with the distupgrade option. Before software is updated you may have to press y to agree to continue.

19.1.4 apt-get install To install an actual software package you can use the apt-get command with the install option. In the example below, apt-get is used to install mplayer a popular Linux media player.

You can also install multiple packages at the same time by separating each package name with a space. 19.1.5 apt-get cache The apt-cache command with the search option allows you to search for information on a software packages. In the example below the apt-cache command is used to search for the vsftp package. The output shows several packages associated with vsftp.

The apt-cache command with the show option allows you to display information on a particular software package. In the example below the aptcache command is used to display information on the vsftpd package.

19.1.6 apt-get remove To uninstall an actual software package you can use the apt-get command with the remove option. In the example below, apt-get is used to uninstall mplayer.

20. WORKING WITH DISKS

20. Working with disks When Linux boots, the Linux Kernel recognizes disks connected to your system, assigns names to the disks, and adds the disks to the /dev directory. When you add a new disk to a Linux system you have to create a partition or multiple partitions before the disk can be used by the system. Before you can partition the disk, however, you have to be able to locate the disks and know what label Linux have given the disk. The following sections are covered in this chapter. 20.1 df 20.2 lshw 20.3 fdisk 20.4 Create the filesystem 20.5 Mounting a disk 20.6 Unmounting a disk 20.7 /etc/fstab

20.1 df The df command can be used to view the current system disks that are partitioned and the space utilization of each disk. The example below shows the output of the df command without any options.

The first column on the right side is the Filesystem. The first Filesystem is udev which is a temporary file system for managing removable devices.

The second Filesystem is tmpfs which is a temporary file system resident in memory. As you can see in the example above there are several tmpfs entries which are used for various system processes. You can tell what the tmpfs if used for by looking at the last column, Mounted on. /run - Used to hold runtime files for various system daemons. /dev/shm - Used for shared memory between processes. /run/lock/ - Contains lock files that control access to devices being used by a process. /sys/fs/cgroup - Tracks and controls resource usage by processes. /run/user/1000 - Used to hold files for use processes The third Filesystem is /dev/sda1 which is an actual file system. The first part of file system indicates that the device is located in the /dev directory. The second part indicates the type of device, the number of the device, and the partition on the device. hd - IDE hard drives. sd - Serial and SATA drives. Following the hd and sd designation is a letter that indicates the number of the device. The letter a indicates the first device. The letter b would indicate the second device. The letter c would indicate the third device and so on. After the letter will be a number which indicates the partition number. For example the device hda1 would be the first partition on the first IDE hard drive. The device sdc3 would be the third partition on the third SCSI or SATA hard drive. The other columns in the df output are: 1K-blocks - Size of the partition in 1 Kilobyte blocks. Used - Number of 1 Kilobyte blocks used. Available - Number of 1 Kilobyte blocks available. Use% - Percentage of space used.

If you want to see the information in a more user friendly format you can use the df command with the -h option which means human readable, as in the example below.

20.2 lshw The lshw command, which stands for list hardware, can be used to locate any disk on a Linux system, even if it is not partitioned. Fedora does not come with the lshw installed by default. The lshw command without any options will list all of the hardware recognized by the Linux system which can be a long list. To isolate the disks you can use the -C option with the disk keyword as in the example below.

20.3 fdisk Before a new disk can be used on a Linux system it must be partitioned first. The fdisk command is used to partition disks on a Linux system. The following subsections will be covered in this section: 20.3.1 Listing partitions 20.3.2 fdisk menu 20.3.3 Create a new partition 20.3.4 Set partition type 20.3.1 Listing partitions The fdisk command with the -l option can be used to look at the active disks and current partitions and to verify that new disks added to the system were recognized by the system on boot. In the example below the fdisk command

shows several ram disks.

In the example below the fdisk command shows the /dev/sda and /dev/sdb disks. The /dev/sda has three partitions, /dev/sda1, /dev/sda2, and /dev/sda5. The /dev/sdb has no partitions because it is a new disk.

The /dev/sda1 partition is a Linux partition that is also the Boot partition which means that this is where the Linux system is located.

The /dev/sda2 partition is an Extended partition. The /dev/sda5 partition is a Linux Swap partition which is used for system virtual memory. 20.3.2 fdisk menu Since /dev/sdb is recognized by the system and does not have any partitions you can use the fdisk command to list and modify partitions on the disk. The syntax is as follows: fdisk device_name The example below shows the fdisk command being used to view /dev/sdb.

The fdisk command is an interactive command that requires user input. At the bottom is each screen will be a prompt Command (m for help): which is where you type your command. To get a list of all fdisk interactive commands, type m. In the example below the Help menu is broken down into six sections. Each section lists the single letter commands that you can use to perform various fdisk functions.

20.3.3 Create a new partition Type p to list the partition table and verify that /dev/sdb is present. In the example below you can see that /dev/sdb is available and is 8GB in size.

Type n to create new partition as in the example below.

You will be asked for the Partition Type which will be a primary partition as this will be the first partition on this disk. The default is primary so you can just press enter or you can type p. You will be asked for the Partition number. The default is 1 since this is the first partition on the disk so you can just press enter or you can type 1. You will be asked for the First sector. The default is 2048 since this is the first partition on the disk so you can just press enter or you can type 2048. You will be asked for the Last sector. The default is 16777215 which is the end of the disk so you can just press enter or you can type 16777215. Once complete the new partition will be created as type Linux by default. Instead of selecting the last sector you can also specify a disk size. In the example below the size of 4G is specified. You have to type +4G.

20.3.4 Set partition type Type l to see the list of partition types. Each type has a number code. The default is 83 which is Linux. As you can see from the example below, there are a lot of options to choose from. The most commonly used types are 7 for NTFS, b for FAT32, 82 for Linux swap, 83 for Linux, and 8e for Linux LVM.

Type t to set the partition type. Select partition 1 and set it to NTFS by using code 7 as in the example below.

Once you have finished making all of your partition changes type w to write the changes and exit fdisk.

Use fdisk with the -l option again to verify that the partition changes are correct. sudo fdisk -l /dev/sdb

20.4 Create the filesystem Before you can use a new partition you have to create a file system by using the mkfs command which stands for make filesystem. The mkfs command has several versions for different file systems as seen in the example below.

The following subsections will be covered in this section: 20.4.1 Create a Linux filesystem 20.4.2 Create an NTFS filesystem 20.4.3 Create a FAT32 filesystem 20.4.1 Create a Linux filesystem Linux partitions can either be ext2, ext3, or ext4. Most Linux systems today use ext4. You can use the mkfs.ext4 command to make an ext4 Linux file system as in the example below. Make sure the partition is set to type Linux

(83) in fdisk before making a Linux filesystem. When using the mkfs.ext4 command make sure that you designate the partition not the disk. In the example below the disk is /dev/sdb the partition is /dev/sdb1.

20.4.2 Create an NTFS filesystem You can use the mkfs.ntfs command to make an ntfs file system as in the example below. Make sure the partition is set to type 7 in fdisk before making a NTFS filesystem. When using the mkfs.ntfs command make sure that you designate the partition not the disk. In the example below the disk is /dev/sdb the partition is /dev/sdb1.

20.4.3 Create a FAT32 filesystem You can use the mkfs.vfat command to make a FAT32 file system as in the example below. Make sure the partition is set to type b in fdisk before making a FAT32 filesystem. When using the mkfs.vfat command make sure that you designate the partition not the disk. In the example below the disk is

/dev/sdb the partition is /dev/sdb1.

20.5 Mounting a disk Once a disk partition has been created and the file system made you have to mount the partition to the file system before it can be used. Create a mount point Mount the partition Test the new mounted partition 20.5.1 Create a mount point A mount point is an empty directory in a Linux file system used to mount a disk partition. In the Linux file system structure there is a directory /mnt which is for mounting file systems however a disk can be mounted anywhere. If you create a mount point in the /mnt you will need root permission so you will need to use the sudo command. To make a mount point use the mkdir command. You can name the mount point whatever you want. sudo mkdir /mnt/newdisk 20.5.2 Mount the partition The mount command is used to mount the partition to the mount point that you created. You need root permission to mount a disk so you will need to use the sudo command. sudo mount /dev/sdb1 /mnt/newdisk 20.5.3 Test the new mounted partition If you use the cd command to navigate to the new mounted partitions and

attempt to create a test directory you will get an error as in the example below. This is because only the root user can mount disks and the permissions assigned to the disk during the mounting process prevent users from writing to the disk.

There are several ways to fix this issue. 1. Use the sudo command.

2. Use the chown command to change the owner of the partition. In the example below root is the owner of newdisk and the chown command is used to change the owner to matt. The user matt will now be able to write to the disk.

3. Use the chgrp command to change the group owner of the partition and add your user account to the group by using the usermod command. In the example below the root group is the group owner of newdisk and the chgrp command is used to change the group owner to users, however, the group does not have the write permissions to the partition.

You can use the chmod command to add the necessary permissions to the

users group as in the example below.

20.6 Unmounting a disk Before a disk can be removed to a Linux system the drive needs to unmounted. You can use the umount command to unmount partitions. Only a root user can unmount a disk so you will need to use the sudo command. sudo umount /dev/sdb1

20.7 /etc/fstab When you manually mount partitions in Linux, the partitions are only temporarily mounted using the mount command. To mount the partitions on boot you have to edit the /etc/fstab file and add your new partitions. Only a root user can edit the fstab file so you will need to use the sudo command. sudo vi /etc/fstab The following line adds the partition /dev/sdb1 to the mount point /mnt/newdisk as type ext4. The defaults option means use default options which will give you read and write permissions. The 0 means do not dump the file system. The 2 means check the file system after the root file system. Add the line to the bottom of the file and save the file. Be sure to use the tab key between each section not the spacebar.

The following line adds the partition /dev/sdb2 to the mount point /mnt/newdisk as type vfat.

Reboot the system and check that you new partitions are mounting properly.

21. WORKING WITH REMOVABLE MEDIA

21. Working with removable media Modern Linux systems make working with removable media such as CDs, DVDs, and USB drives very easy. Most Linux system will auto mount removable media. In a GUI system finding and accessing the removable media is simple as the removable media will be present in the file manager application. When using the CLI, however, you have to know where to look to find the mount point for the removable media. Different versions of Linux mount removable media in different locations. The following sections will be covered in this chapter: 21.1 CD/DVD 21.2 USB Disk

21.1 CD/DVD Most modern Linux systems will auto mount CDs and DVDs when the disks are inserted into the system. When a CD or DVD is inserted into an Ubuntu Linux system, the disk is mounted in the following location: /media/current_user/DVD_NAME The current_user will be the name of the user that is logged on to the system. The DVD_NAME depends upon the name assigned to the disk when it was created and will vary from disk to disk. To unmount a CD or DVD you can use the umount command with the location of the mount point. If you are in the CD or DVD in the CLI then you will get a target is busy error as in the example below.

To overcome this error you will need to move from the CD or DVD using the cd command and then unmount the disk with the umount command as in the example below.

21.2 USB Disk Most modern Linux systems will auto mount USB disks when the disks are inserted into the system. When a USB disk is inserted into an Ubuntu Linux system, the disk is mounted in the following locations: /media/current_user/USB_NAME /media/current_user/UUID The current_user will be the name of the user that is logged on to the system. The USB_NAME depends upon the name assigned to the disk when it was created and will vary from disk to disk. If the disk does not have a name then the Universal Unique Identifier (UUID) will be used. The UUID is a 128 bit 32 hexadecimal character number used to identify block devices in Linux systems. Since disks are block devices they are assigned a UUID when the partitions are created. In the example below a USB disk with the UUID 92fc30ee-f2e8-47d8-9bd05aefead150b0 is connected to the system. Looking in the /media/matt directory where removable media is mounted you can see a directory named 92fc30ee-f2e8-47d8-9bd0-5aefead150b0 which is where the USB disk is

mounted.

To unmount a USB disk you can use the umount command with the location of the mount point. If you are in the USB disk in the CLI then you will get a target is busy error as in the example below.

To overcome this error you will need to move from the CD or DVD using the cd command and then unmount the disk with the umount command as in the example below.

22. SSH

22. SSH When remotely connecting to a Linux system you want to make sure that a secure method is used. In the past telnet was a popular way to connect remotely however telnet is not secure and usernames and passwords are sent in clear text. A more secure method of connecting remotely to a Linux system is via the Secure Shell (SSH) protocol which uses TCP port 22. 22.1 SSH Server 22.2 SSH Client 22.3 Connecting to SSH Server

22.1 SSH Server The SSH server is the key to being able to remotely connect to a Linux system. The SSH server is configured to accept incoming connections and authenticate users. The SSH server also provides a secure key that allows the connection from the client to the server to be encrypted. 22.1.1 Installing SSH Server In order to be able to remotely access a Linux system with SSH you have to install the SSH server, openssh-server on the server that you want to connect to. All modern versions of Linux have packages for openssh-server. To install openssh-server on Debian and Ubuntu use the apt-get command. sudo apt-get install openssh-server

22.2 SSH Client On most modern Linux, Unix, and Mac systems it is not necessary to install an SSH client as the SSH client comes already installed on the system. If you are using a Windows system you will have to download an SSH client such a Putty to be able to access an SSH Server.

22.3 Connecting to SSH Server

When connection to an SSH server you will need to know either the IP address or the hostname of the SSH server and have a username and password for the system. The following subsections are covered in this section: 22.3.1 Linux, Unix, and Mac 22.3.2 Windows 22.3.3 Firewalls 22.3.1 Linux, Unix, and Mac On most modern Linux, Unix, and Mac systems you can connect to a remote Linux system by opening the CLI and using the following syntax: ssh ip_address ssh domain_name The example below shows a connection from one Linux system to another:

The first time you connect to a system remotely you will be asked if you want to connect. If you type yes the system IP address or hostname will added to a list of known hosts and you will not be asked if you want to connect the next time. You will have to provide a username and password to access a remote system via SSH. By default the SSH Client uses the username of the user making the connection. If there is a username with the same name on the remote system then all you will have to provide is the password for the username on the remote system. In the example below the first line starts with matt@ which indicates that the username being used is matt.

If you want to use a different username to login to the remote system you can use the ssh command with the -l option followed by the username you want to use. In the example below the user jsmith is used to logon to the remote system.

To exit an SSH session just type exit and press enter and you will be returned to the local CLI. 22.3.2 Windows When using a Windows system to connect remotely to a Linux system via SSH you will have to use an SSH client such as Putty. You can download Putty from www.putty.org. The example below shows the Putty client.

To connect to an SSH server you must enter the IP address or hostname and make sure SSH is selected as in the example below. Click the Open button to connect to the server.

If this is the first time that you are connecting to the SSH server you will get the PuTTY Security Alert as in the example below. Click the Yes button to add the host key to the registry and complete the connection.

Once the SSH connection is made you will be asked to provide a username and password for the remote system as in the example below.

When you are finished with your SSH session just type exit on the CLI and press enter to close the session. 22.3.3 Firewalls

If your Ubuntu system has a host based firewall installed and running then you will have to open up the port for SSH, TCP port 22, inbound in order to allow incoming connections. There are security risks with running protocol such as SSH on a Linux system so make sure that you have the system properly configured and placed in the network before opening up a port on the firewall allowing connections from the Internet. Ubuntu uses the Uncomplicated Firewall (UFW) to control basic firewall configurations, however the firewall is not configured by default. To open TCP port 22 using the following command: sudo ufw allow in ssh

23. SHARING FILES

23. Sharing files When working in a network environment it is important to be able to share files between users and systems. Ubuntu has multiple ways to share files between Linux, Windows, and Mac systems. 23.1 FTP 23.2 SFTP 23.3 HTTP/HTTPS 23.4 NFS 23.5 Samba

23.1 FTP The FTP protocol is a quick and easy way to share files on the Internet or a network but is also very insecure. The FTP protocol passes the username and password in clear text which can be captured by anyone able to capture traffic between the client and the FTP server. Due to security concerns, you should only use FTP to share files that do not need to be secured. On most Linux system you will need to install an FTP server if you want to make files available via FTP. If you have to use FTP make sure that the server you install the FTP server software on does not perform any critical function on the network. You should also not put an FTP server on your internal network that allows connections from outside the network or the Internet. If you need to share files with the Internet your FTP server should be in the Demilitarized Zone (DMZ) on the firewall. The following subsections will be covered in this section: 23.1.1 FTP Server Install 23.1.2 Firewalls 23.1.4 FTP Client 23.1.1 FTP Server Install To install an FTP server on Ubuntu you can use the apt-get install

command. sudo apt-get install vsftpd Ubuntu configures and enables the vsftpd service and start the service automatically during the install process. 23.1.2 Firewalls If your Ubuntu system has a host based firewall installed and running then you will have to open up the port for FTP, TCP port 21, inbound in order to allow incoming connections. There are security risks with running an insecure protocol such as FTP on a Linux system so make sure that you have the system properly configured and placed in the network before opening up a port on the firewall. Ubuntu uses the Uncomplicated Firewall (UFW) to control basic firewall configurations, however the firewall is not configured by default. To open TCP port 21 using the following command: sudo ufw allow in ftp 23.1.4 FTP Client In order to connect to an FTP server you need to use an FTP client. Ubuntu comes with ftp already installed. The following subsections will be covered in this section: 23.1.4.1 Connecting to a server 23.1.4.2 Passive Mode 23.1.4.3 Help 23.1.4.4 List Remote Files 23.1.4.5 List Local Files 23.1.4.6 Current Remote Directory 23.1.4.6 Current Local Directory 23.1.4.7 Change Remote Directory 23.1.4.8 Change Local Directory 23.1.4.9 Get Files

23.1.4.10 Put Files 23.1.4.11 Exit FTP 23.1.4.1 Connecting to a server To connect to an FTP server from the CLI use the ftp command followed by either the IP address or hostname of the server. In the example below ftp command is used to connect to the IP Address 192.168.10.10.

You will be asked for the username and password to access the server as in the example below. By default ftp will use the username of the current user unless you specify a specific user.

You can also open a connection to a server from inside the ftp program by using the open command with the IP address or hostname as in the example

below. If you leave an ftp connection open for too long you will get disconnected from the server and may need to reconnect.

23.1.4.2 Passive Mode The FTP protocol can run in two modes, active or passive. Active mode uses two TCP ports 20 and 21, and passive mode uses just TCP port 21. Most servers today run in passive mode but most FTP clients assume active mode by default. To make sure you are using the proper mode you must set the FTP client to passive mode using the passive command as in the example below:

23.1.4.3 Help The FTP client comes with a help menu that can be accessed by typing either ? or help to access the help menu.

You can get help on a specific command by using the help command followed by the name of the command as in the example below.

23.1.4.4 List Remote Files You can get a list of files and directories on the remote system by using either the dir or ls commands as in the example below.

23.1.4.5 List Local Files You can get a list of files and directories on the local system by putting the ! character in front of the dir or ls commands as in the example below.

23.1.4.6 Current Remote Directory You can find out what the current remote directory is by using the pwd command as in the example below.

23.1.4.6 Current Local Directory

You can find out what the current local directory is by using the !pwd command as in the example below.

23.1.4.7 Change Remote Directory You can change the remote directory by using the cd command. In the example below, the pwd command is used to check the remote directory, the ls command is used to view the remote director, and the cd command is used to change to the Documents directory.

23.1.4.8 Change Local Directory You can change the local directory by using the lcd command. In the example below, the !pwd command is used to check the remote directory and the lcd command is used to change to the Documents directory.

23.1.4.9 Get Files To get or download a file from an FTP server you can use the get command followed by the filename. In the example below, the !ls command is used to view the local directory, the ls command is used to view the remote directory, the mget command is used to get the myfile4 file, and the !ls command is used to view the local directory and verify that the file download occured.

To get or download multiple files from an FTP server you can use the mget command followed by the filename as in the example below.

23.1.4.10 Put Files To put or upload a file to an FTP server you can use the put command followed the filename. By default vsftpd is configured not to allow writing to the FTP server as in the example below.

To enable writing to the FTP server you must edit the vsftpd.conf file and remove the # character in front of the write_enable=YES line and save the file. Ubuntu and Debian put the vsftpd.conf file in the /etc/ directory and Fedora puts the file in the /etc/vsftpd directory.

You will need to restart the vsftpd server. sudo systemctl restart vsftpd Once the server has restarted you will be able to use the put command to upload the file as in the example below.

To upload multiple files to an FTP server you can use the mput command followed by the filename and a wildcard as in the example below.

23.1.4.11 Exit FTP To exit the ftp program just use the exit command.

23.2 SFTP Since FTP is an insecure it is not recommended for secure file transfers. To securely transfer files you can use the SFTP protocol which uses the SSH protocol on TCP port 22 to transfer files. You can use the sftp command just like you would use the ftp command as in the example below.

23.3 HTTP/HTTPS You can share files using the HTTP and HTTPS protocols. Files placed on a web server for download can be downloaded from the CLI using the wget command followed by the URL as in the example below.

The wget command will append a . and a number to the end of the filename if a file with the same name already exists in the directory the file is being downloaded into.

23.4 NFS The Network File System (NFS) allows files and directories to be shared across the network between Linux systems. The NFS server hosts directories that can be mounted by the NFS client on a remote system. 23.4.1 Installing NFS 23.4.2 Firewalls 23.4.3 /etc/exports 23.4.4 NFS Client 23.4.1 Installing NFS To install the NFS server use the apt-get install command. sudo apt-get install nfs-kernel-server 23.4.2 Firewalls If your Ubuntu system has a host based firewall installed and running then you will have to open up the port for NFS, TCP and UDP port 2049, inbound in order to allow incoming connections. There are security risks with running

any protocol such as NFS on a Linux system so make sure that you have the system properly configured and placed in the network before opening up a port on the firewall. Ubuntu uses the Uncomplicated Firewall (UFW) to control basic firewall configurations, however the firewall is not configured by default. To open TCP and UDP port 2049 using the following command: sudo ufw allow in nfs 23.4.3 /etc/exports Following the installation of the server the /etc/exports file needs to be edited to add directories that you want to make available via NFS. sudo vi /etc/exports The syntax for entries in the exports file are as follows: directory

hosts(options)

The directory is the local directory that you want to share. The hosts are hosts that should be allowed to access the share. You can use an IP address, network ID, hostname, or * which means all hosts. The options control the permissions for the share. The following are the common options: ro - Read only access rw - Read and write access no_root_squash - Allows the root user from the client to have root permission on the server. no_subtree_check - disables the verifications of directory subtrees if an entire volume is shared to speed up access time. sync - Prevents data corruption The following are examples of shares in the /etc/exports file: Share the /home directory with any IP address and provide Read and Write permissions: /home *(rw)

Share the /home directory with IP address 192.168.1.3 and provide Read only permissions: /home 192.168.1.3(ro) Share the /home directory with IP address 19.168.1.3 (Read and Write) and 192.168.1.4 (Read Only) and allows root to have permissions: /home 192.168.1.3(rw,no_root_squash) 192.168.1.4(ro,no_root_squash) Once you edit the /etc/exports file you must restart the nfs service: sudo systemctl restart nfs-kernel-server.service 23.4.4 NFS Client In order to connect from a Linux system to an NFS server the system must have an NFS client and the user using the client must have a matching username and password on the server. To install the NFS client on Ubuntu use the apt-get install command. sudo apt-get install nfs-common 23.4.4.1 mount In order to access NFS shares on an NFS server you must mount the share to a local directory that is empty. To make an empty directory use the mkdir command: mkdir ~/mydir To mount the share in the empty directory use the mount command . The syntax is as follows: sudo mount ip_address:share_name local_directory In the example below the mount command is used to mount the /home folder on the NFS server with the IP address 192.168.56.163 and mount it in the local folder myfolder.

To mount the share automatically during boot add the share information to the /etc/fstab file: 192.168.56.163:/home

~/myfolder

nfs

rw

0

0

23.5 Samba The Samba service allows files and directories to be shared across the network between Linux, Unix, Mac, and Windows systems. The Samba server hosts directories that can be accessed and mounted by a Samba client on a remote system. Samba uses the Server Message Block (SMB) Protocol. 23.5.1 Installing Samba 23.5.3 Firewalls 23.5.4 Configure a Samba Password 23.5.5 Edit /etc/samba/smb.conf 23.5.6 Connecting to a Samba Server 23.5.1 Installing Samba To install the Samba server on Ubuntu use the apt-get install command. sudo apt-get install samba 23.5.3 Firewalls If your Ubuntu system has a host based firewall installed and running then you will have to open up the port for SMB, TCP port 445, inbound in order to allow incoming connections. There are security risks with running any protocol such as SMB on a Linux system so make sure that you have the system properly configured and placed in the network before opening up a

port on the firewall. Ubuntu uses the Uncomplicated Firewall (UFW) to control basic firewall configurations, however the firewall is not configured by default. To open TCP port 445 using the following command: sudo ufw allow in samba

23.5.4 Configure a Samba Password Samba uses a separate password than the Ubuntu login password for a user, however, you can make the passwords the same. Before a user can access a Samba share a password must be set using the smbpasswd command with the -a option as in the example below.

23.5.5 Edit /etc/samba/smb.conf Samba shares are defined in the /etc/samba/smb.conf file. sudo vi /etc/samba/smb.conf Go to the end of the file and add the following: [share_name] comment = share_comment

path = share_path valid users = samba_user read only = yes or no guest ok = yes or no browseable = yes or no The example below shows the configuration for a share name myshare.

You will need to restart the smb service for the changes to take effect. sudo systemctl restart smbd 23.5.6 Connecting to a Samba Server In order to connect from a Linux system or Windows system to a Samba server the system must have an SMB client and the user using the client must have a username and password on the server. 23.5.6.1 Linux 23.5.6.2 Fstab 23.5.6.3 Windows 23.5.6.1 Linux On Linux systems you have to install a Samba client is one is not already installed. Ubuntu and Debian

sudo apt-get install smbclient Fedora sudo apt-get install samba --best Once the Samba client is installed you can use the smbclient command with the -L option to query the Samba server for sharing information as in the examples below. You will have to provide the Samba password that was created previously.

You can also use the smbclient command to connect to the share. In the example below there are four \ before the IP address and two after. This is because when using the smbclient command you must escape the \ character to give it meaning so if you need two \ characters you have to escape each one which gives you four. You will have to provide the Samba password that was created previously. Once connected you will get the smb: \> prompt which means you are connected to the server. In the example below the ? command is used to access the help menu.

When connected to the Samba server you can use commands to get and put files on the server just like you can with FTP and SFTP. The example below shows what happens when not enough \ characters are used.

You can also mount Samba shares using the Common Internet File System (CIFS). Most Linux systems do not have CIFS installed by default so you will have to install the software. Ubuntu and Debian sudo apt-get install cifs-utils Fedora sudo dnf install cifs-utils --best Once CIFS is installed you can use the mount command to mount the Samba share as in the example below.

You can also use the mount command to view information about the mounted share as in the example below. You will want to use the grep command to isolate the specific share as there may be many shares on the server.

To unmount a Samba share use the umount command. sudo umount ~/myfolder 23.5.6.2 Fstab Using the /etc/fstab file you can configure Samba shares to be mounted to the filesystem during the boot process. There are some security concerns with this configurations, however, as the Samba username and password are placed into a configuration file. 23.5.6.2.1 User File

Since the Samba share controls access to the share based on a username and Samba password you have to make the username and password available to the boot process by storing them in a file. Create /etc/samba/user file. Add the following lines replacing sabmba_username with the actual username and the samba_password with the actual password. username=sabmba_username password=samba_password Edit /etc/fstab and add the following line. //ip_address/sharename /local_mount_point cifs credentials=/etc/samba/user,noexec 0 0 The example below mount the myshare share from 192.168.56.1 to /home/matt/myfolder and users the username and password from the /etc/samba/user file. //192.168.56.1/myshare /home/matt/myfolder cifs credentials=/etc/samba/user,noexec 0 0 Reboot the system to mount the Samba share. 23.5.6.3 Windows To access a Samba share from a Windows system, open a File Explorer window and type \\ followed by the IP address of the Linux server running Samba in the address bar. \\IP_address\ You can also connect directly to the share by including the share name. \\IP_address\share_name You will be required to provide the Samba username and password.

24. INSTALLING ALTERNATE DESKTOPS

24. Installing Alternate Desktops One of the great things about Linux is your ability to completely customize your desktop environment and Linux has some great options for customization. Ubuntu comes installed with the Unity Desktop by default but you are not stuck with one desktop environment. You can install multiple desktop environments and switch back and forth between the different environments as you desire. While there are too many desktop environments to cover them all, I will introduce two of the most popular options. 24.1 GNOME Flashback 24.2 KDE

24.1 GNOME Flashback GNOME Flashback is a mode of GNOME provided by the GNOME Project which allows users who prefer the way GNOME used to look to still have the ability to use GNOME. Of all the alternate desktops this is my favorite and the one I use on my personal laptop. Figure 24-5 shows Ubuntu with the GNOME Flashback Desktop installed.

Figure 24-5. GNOME Session Flashback Desktop

The GNOME Session Flashback can be installed by opening a terminal and typing the following command: sudo apt-get install gnome-session-flashback Once installed you can select the desktop during the logon process. Figure 24-6 shows the Ubuntu Login screen with the additional GNOME Flashback option.

Figure 24-6. Select desktop environment

24.2 KDE KDE is a desktop environment maintained by the KDE Community, www.kde.org. Canonical maintains a separate version of Ubuntu built on the KDE Desktop named Kubuntu. You can either download and install Kubuntu or you can add all of the KDE Desktop packages to your existing Ubuntu system using the following command: sudo apt-get install kubuntu-desktop

Figure 24-7 shows the Plasma option on the Ubuntu Login Screen.

Figure 24-7. Plasma

Figure 24-8 shows the Kubuntu Desktop.

Figure 24-8. Kubuntu Desktop

Figure 24-9. Kubuntu Desktop

25. UBUNTU RECOVERY MODE

25. Ubuntu Recovery Mode Linux is a very stable operating system but every once in awhile something will go wrong and you will need to fix it. Since Ubuntu is mainly a graphical environment, if the graphical user interfaces fails to start then you may not be able to fix any problems. To aid in the recovery of a broken Ubuntu system, Ubuntu has a recovery mode. To enter recovery mode you have to press the right shift key while booting your system. Figure 25-1 shows the GRUB bootloader menu that will appear. GRUB is the default bootloader for Ubuntu. There are several options but it is the first two that are the most important. The first option, Ubuntu, will proceed with a normal boot into the GUI. The second option, Advanced option for Ubuntu, is for system recovery.

Figure 25-1. GRUB Menu

Figure 25-2 shows the Advanced options menu. Looking at the menu we

can see that there are several menu options. Depending upon how many times the kernel on your system has been updated, you may have many different kernel versions with the most recent kernel version at the top. The first option is a regular boot, the second option is upstart which is a service manager, and the third option is recovery mode.

Figure 25-2. Advanced options menu

Choosing recovery mode will lead you to the Recovery Menu, Figure 25-3. There are several options in the Recovery Menu but the one we are most interested in is root which will give you a terminal with root privileges.

Figure 25-3. Recovery menu

Figure 25-4 shows the recovery terminal with root privileges.

Figure 25-4. Recovery terminal

Having root privileges at a terminal can be a very dangerous thing so by default the recovery mode boots into a read only mode meaning that changes can not be made to the operating system. To make any changes you will need to mount the filesystem in read/write mode using the following command: mount -o remount,rw /

Once the command above has been run you will have full control of the operating system.

26. MANUAL DISK PROVISIONING

26. Manual Disk Provisioning During the installation process you will be given the option to manually partition the disk yourself, Figure 26-1. While this is an advanced topic I wanted to show you some of the basics of manual disk partitioning. The following sections are covered in this chapter: 26.1 Installation Types 26.2 Create a New Partition 26.3 Free Space 26.4 Swap Area 26.5 Root Partition 26.6 Other Partition Types

26.1 Installation Types To manually partition the disk select Something else and click Continue, Figure 26-1.

Figure 26-1. Something else

26.2 Create a New Partition Figure 26-2 shows the disk partitioning window. If this is a fresh install on a new disk there will be no partitions present. The only thing that will be present is the disk device /dev/sda. The disk device is located in the /dev or device directory. The sd in sda stands for SCSI device which is a disk type which also covers USB and SATA devices. If the drive was an IDE drive it would be hda instead of sda. The a in sda signifies the first device. The second device would be sdb and the third device would be sbc. To create a new partition, select the /dev/sda device and click New Partition Table in the lower right hand corner.

Figure 26-2. New Partition Table

You will have to confirm your choice to create a new partition by clicking Continue, Figure 26-3.

Figure 26-3. Confirm New Partition Table

26.3 Free Space Once the partition table is created, you will see the new partition table with the label free space, Figure 26-4. The size of the free space will depend upon the size of the disk. You can now create the partitions by clicking the + in the lower left hand corner.

Figure 26-3. Free Space

26.4 Swap Area The swap area on a Linux system is part of the virtual memory system that is is made up of the physical memory and the swap space. The swap area requires its own partition on a Linux system. The size of the swap area is determined by the amount of RAM on your system. At a minimum you should have as much swap area as you do physical memory if you are not using hibernation and double the amount of RAM if you are using hibernation. This only works up to a point, however, as once you get over 1 or 2 GB of RAM, adding too much swap area does not increase performance. For example, my laptop has 16GB of RAM and only 3 GB of swap area which almost never gets used. To configure your swap area you will need to set the size, type of partition, in this case Primary, the location of the partition, in this case at the Beginning of the free space, and then select Use as: swap area, Figure 26-4. Once all of the parameters are set click OK.

Figure 26-4. Configure Swap area

On the partition window you will now see the swap area and the free space, Figure 26-5. In Figure 26-5, the swap area location is listed as /dev/sda1, with the 1 standing for the 1st partition of sda.

Figure 26-5. Swap Area /dev/sda1

26.5 Root Partition The next partition that should be installed is the root partition. The root partition is the root of the Linux file system. An explanation of the Linux file system can be found in Chapter 12. To install the root partition, select the free space and click the + in the bottom left hand corner, Figure 26-6.

Figure 26-6. Add root partition

The root partition needs to be large as this is where most of the operating system is located. In Figure 26-7, the root partition is assigned 15GB. Since the swap partition was the Primary partition, the root partition will be a Logical partition. You should set the partition to be located at the Beginning of this space and select Use as: Ext4 journaling file system. Finally you need to select a mount point. For the root partition the mount point is / which is the root of the file system.

Figure 26-7. root partition parameters

Once all of the parameters are set click OK.

26.6 Other Partition Types When manually partitioning your disk, you can define many other partitions other than swap and root, Figure 26-8.

Figure 26-8. other partition mount points

The following are a list of the other mount points and their uses. If you do not define a mount point, the directory will automatically be created under the root partition. /boot - Holds the system startup files and the system kernel, vmlinuz. /home - Holds the home directories for system users. /tmp - Holds temporary files. /usr - Holds all of the user programs, libraries, and documentation. /var - Holds variable data such as system logs. /srv - Holds data on services provided by the system. /opt - Holds third party software. /usr/local - Holds locally installed programs. In Figure 26-9, the swap, root, and home partitions have been configured. Once you have configured the partitions you want to define, click Install Now.

Figure 26-9. swap, root, and home partitions configured

Before the install begins you will have to confirm that you want to write the changes to the disk by clicking Continue Figure 26-10.

Figure 26-10. Continue

27. WINDOWS AND UBUNTU DUAL BOOT

27. Windows and Ubuntu Dual Boot Having a dual boot system allows you boot your computer with a different operating system and get full access to all of the system resources unlike a virtual machine which may allow access to only some of the system resources. Configuring a dual boot system is easy but not without risks. Just to be on the safe side make sure to backup your data before continuing. 27.1 Dual Boot Preparations 27.2 Ubuntu Installation 27.3 Sharing Files Between Operating Systems

27.1 Dual Boot Preparations In order to setup a Windows and Ubuntu dual boot system you should install the Windows operating system first. During the installation be sure to leave enough unallocated space for the Ubuntu operating system to be installed on. I recommend at least 20GB of space. If you already have a Windows installation you will have to resize the Windows partition to make room for Ubuntu. You can use Disk Management in Windows 7 or later to shrink an existing partition. In Disk Management right click on the partition and select Shrink Volume and enter the amount of space to shrink the volume.

27.2 Ubuntu Installation Once the Windows installation of complete, or your shrink the volume of an existing installation, turn off the computer and start an Ubuntu install as covered in Chapter 2. When the installation gets to the Installation type screen, Figure 27-1, it will be different in a dual boot configuration. Ubuntu will detect the Windows installation and provide the option to Install Ubuntu alongside Windows.

Figure 27-1. Installation Type

The remainder of the installation will proceed as normal. Once you reboot to complete the installation, the GRUB menu will now contain an entry for your Window installation, Figure 27-2.

Figure 27-2. Installation Type

Use the arrow keys to move up and down in the GRUB menu, make your selection, and boot into the appropriate operating system. You will need to reboot each time you want to switch between operating systems.

27.3 Sharing Files Between Operating Systems If you want to share files between the operating systems in your dual boot configuration there are a few options. 1. Create a separate data partition and format the partition in either FAT32 or NTFS, both of which Linux can handle. You will have to mount the partition in Linux in order to gain access to the data. 2. Use an external USB thumb drive or external hard drive and format the partition in either FAT32 or NTFS. Both operating systems can detect and access removable media. 3. Use a cloud based storage service to store your files in the cloud. You will only need a browser to be able to access the files in both operating systems.

FINAL THOUGHTS

Final Thoughts I would like to thank all of my readers for purchasing this book and giving me a chance. I hope that you found what you were looking for. Please keep your eyes open for my future Linux and Network Security books.

ABOUT THE AUTHOR

About the Author Matt Vogel works in the field of and teaches Network Security. He is a dedicated Linux user and uses Linux in his Network Security classes. He lives in Virginia Beach, Virginia where he works for the government.