7/26/2019 O'Reilly - Linux Pocket Guide
1/200
7/26/2019 O'Reilly - Linux Pocket Guide
2/200
7/26/2019 O'Reilly - Linux Pocket Guide
3/200
Linux
Pocket Guide
Daniel J. Barrett
Beijing Cambridge Farnham Kln Paris Sebastopol Taipei Tokyo
7/26/2019 O'Reilly - Linux Pocket Guide
4/200
Linux Pocket Guide
by Daniel J. Barrett
Copyright 2004 OReilly Media, Inc. All rights reserved.
Printed in the United States of America.Published by OReillyMedia, Inc., 1005 Gravenstein Highway North,Sebastopol, CA95472.
OReilly Media, Inc. books may be purchased for educational,business, orsales promotional use. Online editions are alsoavailable for most titles(safari.oreilly.com). For moreinformation, contact our corporate/institutional sales department:(800) 998-9938 [emailprotected].
Editor: Mike Loukides
Production Editor: Colleen Gorman
Cover Designer: Emma Colby
Interior Designer: David Futato
Printing History:
February 2004: First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the OReillylogo areregistered trademarks of OReilly Media, Inc. ThePocketGuideseries
designations,Linux Pocket Guide, the image of a roper, andrelated tradedress are trademarks of OReilly Media, Inc.
Many of the designations used by manufacturers and sellers todistinguishtheir products are claimed as trademarks. Where thosedesignations appearin this book, and OReilly Media, Inc. was awareof a trademark claim, thedesignations have been printed in caps orinitial caps.
While every precaution has been taken in the preparation of thisbook, thepublisher and author assume no responsibility for errorsor omissions, or for
damages resulting from the use of the information containedherein.
0-596-00628-4[C] [4/06]
7/26/2019 O'Reilly - Linux Pocket Guide
5/200
v
Contents
Whats in This Book? 1Whats Linux? 2Whats Fedora Linux? 2
Whats a Command? 3
Users and Superusers 4
Reading This Book 5
Getting Help 7
Fedora: A First View 9The Role of the Shell 10
How to Run a Shell 11
Logins, Logouts, and Shutdowns 11
The Filesystem 13Home Directories 14
System Directories 15
Operating System Directories 18
File Protections 19
The Shell 20The Shell Versus Programs 21
Selected bash Features 21
Job Control 29
7/26/2019 O'Reilly - Linux Pocket Guide
6/200
vi | Contents
Killing a Command in Progress 32
Terminating a Shell 33
Tailoring Shell Behavior 33
Installing Software 33
Basic File Operations 37
Directory Operations 41
File Viewing 43
File Creation and Editing 51
File Properties 56
File Location 65
File Text Manipulation 71
File Compression and Packaging 82
File Comparison 86
Disks and Filesystems 91
Backups and Remote Storage 95
File Printing 101
Spelling Operations 102
Viewing Processes 104
Controlling Processes 108
Users and Their Environment 110
Working with User Accounts 115
7/26/2019 O'Reilly - Linux Pocket Guide
7/200
Contents | vii
Becoming the Superuser 118
Working with Groups 119
Basic Host Information 121
Host Location 124
Network Connections 128
Email 132
Web Browsing 136
Usenet News 140
Instant Messaging 142
Screen Output 144
Math and Calculations 149
Dates and Times 152
Scheduling Jobs 155
Graphics and Screensavers 160
Audio and Video 163
Programming with Shell Scripts 166Whitespace and Linebreaks166
Variables 166
Input and Output 167
Booleans and Return Codes 167Conditionals 170
Loops 172
Break and Continue 174
7/26/2019 O'Reilly - Linux Pocket Guide
8/200
viii | Contents
Creating and Running Shell Scripts 176
Command-Line Arguments 177
Exiting with a Return Code 178
Beyond Shell Scripting 178
Final Words 179Acknowledgments 179
7/26/2019 O'Reilly - Linux Pocket Guide
9/200
1
Linux Pocket Guide
Welcome to Linux! If youre a new user, this book can serveas aquick introduction to Linux in general, and FedoraLinuxspecifically, as well as a guide to common and practi-cal commands.If you have Linux experience, feel free to skipthe introductorymaterial.
Whats in This Book?This book is a short guide, not acomprehensive reference. Wecover important, useful aspects of Linuxso you can workproductively. We do not, however, present everysingle com-mand and every last option (our apologies if yourfavoritewas omitted), nor delve into detail about operatingsysteminternals. Short, sweet, and essential, thats our motto.
We focus on commands, those pesky little words you type onacommand line to tell a Linux system what to do, like ls(listfiles), grep (search for text in a file), xmms (play audiofiles),and df(measure free disk space). We touch briefly ongraphicalwindowing environments like GNOME and KDE,each of which could filla Pocket Guide by itself.
Weve organized the material by function to provide a con-ciselearning path. For example, to help you view the con-tents of afile, we introduce all file-viewing commandstogether: catfor shorttext files, lessfor longer ones, odforbinary files, ghostview forPostscript, and so on. Then weexplain each of these commands inturn, briefly presentingits common uses and options.
7/26/2019 O'Reilly - Linux Pocket Guide
10/200
2 | Linux Pocket Guide
We assume you have an account on a Linux system andknow how tolog in with your username and password. Ifnot, speak with yoursystem administrator, or if the system is
your own, use the account created when you installed Linux.
Whats Linux?Linux is a popular, open-source computer softwareenviron-ment that competes with Microsoft Windows and theAppleMacintosh. It has four major parts:
The kernelThe low-level operating system, handling files, disks,net-working, and other necessities we take for granted.
Supplied programsThousands of programs for file manipulation,text edit-ing, mathematics, typesetting, audio, video,computerprogramming, web site creation, encryption, CD burn-
ing... you name it.
The shellA user interface for typing commands, executingthem,and displaying the results. There are various shellsinexistence: the Bourne shell, Korn shell, C shell, and oth-ers.This book focuses on bash, the Bourne Again Shell,
which is often the default for user accounts. However, alltheseshells have similar basic functions.
XA graphical system that provides windows, menus, icons,mousesupport, and other familiar GUI elements. Morecomplex graphicalenvironments are built on X; the mostpopular are KDE and GNOME.Throughout this book, wediscuss programs that open their own Xwindows to run.
Whats Fedora Linux?
Fedora Linux is one particular Linux distributionordistro,created by Red Hat, Inc. and the Fedora project (formore
7/26/2019 O'Reilly - Linux Pocket Guide
11/200
Whats in This Book? | 3
information, see http://fedora.redhat.com) and formerlycalledRed Hat Linux.* Our material is based on Fedora Core 1,thefirst official release (November 2003). We focus on the sup-
plied programs and the shell, with brief coverage of X andthekernel as needed.
Whats a Command?
A Linux command typically consists of a program namefol-lowed byoptionsand arguments, typed within a shell. The
program name refers to a program somewhere on disk(which theshell will locate and run). Options, which usuallybegin with adash, affect the behavior of the program, andarguments usuallyrepresent inputs and outputs. For exam-ple, this command to countthe lines in a file:
$ wc -l myfile
consists of a program (wc, the word count program), anoption(-l) saying to count lines, and an argument (myfile)indicating thefile to read. (The dollar sign is a promptfromthe shell, indicatingthat it is waiting for your command.)Options may be givenindividually:
$ myprogram -a -b -c myfile Three individual options
or combined behind a single dash:
$ myprogram -abc myfile Same as -a -b -c
though some programs are quirky and do not recognize com-binedoptions.
Commands can also be much more complex than running asingleprogram:
They can run several programs at once, either insequence (oneafter the other) or connected into a pipe-line with the output ofone command becoming theinput of the next.
* Red Hat now focuses on its Enterprise Linux products forhigher-end appli-cations. Most of this book applies to Enterpriseand other Linux distros.
7/26/2019 O'Reilly - Linux Pocket Guide
12/200
4 | Linux Pocket Guide
Options are not standardized. The same option (say, -l)may havedifferent meanings to different programs: in wc-lit means countlines of text, but in ls -lit means
produce longer output. In the other direction, two pro-gramsmight use different options to mean the samething, such as -q forrun quietly versus -s for runsilently.
Likewise, arguments are not standardized. They often rep-resentfilenames for input or output, but they can be otherthings too,like directory names or regular expressions.
The Linux command-line user interfacethe shellhasa programminglanguage built in. So instead of a com-mand saying run thisprogram, it might say, if today isTuesday, run this program,otherwise run another com-mand six times for each file whose nameends in .txt.
Users and SuperusersLinux is a multiuser operating system. On agiven computer,each user is identified by a unique username, likesmith orfunkyguy, and owns a (reasonably) private part of thesys-tem for doing work. There is also a specially designateduser,with username root, who has the privileges to do anythingatall on the system. Ordinary users are restricted: though they
can run most programs, in general they can modify only thefilesthey own. The superuser, on the other hand, can create,modify, ordelete any file and run any program.
Some commands in this book can be run successfully only bythesuperuser. In this case, we use a hash mark (#) as theshellprompt:
#command goes here
Otherwise, we will use the dollar sign prompt indicatinganordinary user:
$command goes here
7/26/2019 O'Reilly - Linux Pocket Guide
13/200
Whats in This Book? | 5
To become the superuser, you neednt log out and log backin; justrun the sucommand (seeBecoming the Superuseron page 118) andprovide the superuser password:
$ su -lPassword: ********#
Reading This Book
When we describe a command, we first present its generalusageinformation. For example, the wc (word count) pro-gram has thegeneral usage:
wc [options] [files]
which means youd type wc followed, if you choose, byoptions andthen filenames. You wouldnt type the squarebrackets [ and ]: theyjust indicate their contents areoptional; and words in italics meanyou have to fill in your
own specific values, like names of actual files. If you seeavertical bar between options or arguments, perhaps groupedbyparentheses:
ls (file|directory)
this indicates choice: when running the ls command, youmaysupply either a file or directory name as an argument.
Input and output
Most Linux programs accept data from standard input, whichisusually your keyboard, and produce output on standardoutput, whichis usually your screen. Additionally, error mes-sages are usuallydisplayed on standard error, which also isusually your screen butkept separate from standard output.*
Later well see how to redirectstandard input, output, anderrorto and from files or pipes. But lets get our vocabularystraight.When we say a command reads, we mean from
* For example, you can capture standard output in a file andstill have stan-dard error messages appear on screen.
7/26/2019 O'Reilly - Linux Pocket Guide
14/200
6 | Linux Pocket Guide
standard input unless we say otherwise. And when a com-mandprints, we mean on standard output, unless weretalking aboutcomputer printers.
Standard heading
Each command description begins with a heading like thisone forthe ls(list files) command.
ls [options] [files]/bin
coreutils
stdin stdout - file -- opt --help --version
The heading includes the command name (ls) and usage,thedirectory in which it is located (/bin), the RPM packagethatinstalled the command (coreutils), and six properties ofthecommand printed in black (supported) or gray (unsupported):
stdinThe command reads from standard input, i.e., yourkeyboard,by default.
stdoutThe command writes to standard output, i.e., your screen,bydefault.
- fileIf you supply a dash (-) argument in place of an inputfile-name, the command reads from standard input; and likewise,ifthe dash is supplied as an output filename, the commandwrites tostandard output. For example, the following wc(word count) commandline reads the filesfile1andfile2, thenstandard input,thenfile3:
$ wc file1 file2 - file3
-- optIf you supply the command-line option -- it means endofoptions: anything appearing later on the command line is
not an option. This is sometimes necessary to operate on afilewhose name begins with a dash, which otherwise wouldbe(mistakenly) treated as an option. For example, if you have afilenamed -foo, the command wc -foowill fail because -foowill betreated as an (invalid) option. wc -- -fooworks. If acommand doesnot support --, you can prepend the current
7/26/2019 O'Reilly - Linux Pocket Guide
15/200
Getting Help | 7
directory path ./ to the filename so the dash is no longerthefirst character:
$ wc ./-foo
--helpThe option --helpmakes the command print a helpmessageexplaining proper usage, then exit.
--versionThe option --versionmakes the command print itsversionnumber and exit.
Standard symbols
Throughout the book, we use certain symbols toindicatekeystrokes. Like many other Linux documents, we use the^symbol to mean press and hold the control (Ctrl) key, soforexample, ^D(pronounced control D) means press andhold the controlkey and type D. We also write ESC tomean press the Escape key. Keyslike Enter and Spacebar
should be self-explanatory.
Your friend, the echo command
In many of our examples, well print information to thescreenwith the echocommand, which well formally describeinScreen Outputon page 144. echois one of the simplestcommands: it merely printsits arguments on standard out-
put, once those arguments have been processed by the shell.
$ echo My dog has fleasMy dog has fleas$ echo My name shell is$USER Shell variable USERMy name is smith
Getting HelpIf you need more information than this bookprovides, thereare several things you can do.
7/26/2019 O'Reilly - Linux Pocket Guide
16/200
8 | Linux Pocket Guide
Run the man commandThe man command displays an online manualpage, ormanpage, for a given program. For example, to get docu-
mentation on listing files with ls, run:$ man ls
To search for manpages by keyword for a particulartopic, use the-koption followed by the keyword:
$ man -k database
Run the info command
The info command is an extended, hypertext help sys-tem coveringmany Linux programs.
$ info ls
If no documentation is found on a given program, infodisplaysthe programs manpage. For a listing of avail-able documentation,type infoby itself. To learn how tonavigate the info system, typeinfo info.
Use the --help option (if any)Many Linux commands respond to theoption --helpbyprinting a short help message. Try:
$ ls --help
Examine the directory /usr/share/docThis directory containssupporting documents for many
programs, usually organized by program name and ver-sion. Forexample, files for the text editor Emacs, Ver-sion 21.3, are foundin/usr/share/doc/emacs-21.3.
GNOME and KDE HelpFor help with GNOME or KDE, choose the Helpitem inthe main menu.
Fedora-specific web sitesThe official site ishttp://fedora.redhat.com. An unofficialFAQ has sprung up athttp://fedora.artoo.net. And ofcourse theres the web site for thisbook:
http://www.oreilly.com/catalog/linuxpg/
7/26/2019 O'Reilly - Linux Pocket Guide
17/200
Fedora: A First View | 9
Usenet newsgroupsUsenet has dozens of newsgroups on Linuxtopics, suchas comp.os.linux.misc and comp.os.linux.questions.For
Red Hat-specific information, tryalt.os.linux.redhat,comp.os.linux.redhat, linux.redhat, andlinux.redhat.misc.You can search through newsgroup postings atGoogleGroups, http://groups.google.com, which is a goldmineoftroubleshooting information.
GoogleSearch Google for further documentation and tutorialsat
http://www.google.com(if youve been living in a closet).
Fedora: A First ViewWhen you log into a Fedora (or other) Linuxsystem, yourelikely to be greeted by a graphical desktop* likeFigure 1,which contains:
A Windows-like taskbar across the bottom, with:
A red hat icon in the lower left, which whenclicked, pops up amain menu of programs
Icons to run various programs, such as the Mozillaweb browser,Evolution email program, and PrintManager for configuringprinters
A desktop switcher (the square with four boxes in it),which letsyou maintain and switch between multi-ple desktops
A blue checkmark indicating that your system soft-ware is up todate, or a red exclamation point warn-ing you that it isnt
A clock Other icons on the desktop, such as a trash can fordelet-
ing files, a floppy disk, and your home directory (folder)forstoring personal files
* Unless youre logging in remotely over the network, in whichcase youllsee a command line, prompting you to type a command.
7/26/2019 O'Reilly - Linux Pocket Guide
18/200
10 | Linux Pocket Guide
Fedora comes with several similar-looking interfaces, and theoneyoure viewing is either GNOME or KDE.* You can tellthe differenceby clicking the red hat icon to bring up themain menu, and choosingHelp. The Help window thatappears will clearly indicate GNOME orKDE.
The Role of the ShellExplore the environment of icons and menusin GNOMEand KDE. These graphical interfaces are, for some users,theprimary way to compute with Linux. Various distros, includ-ingFedora, simplify these interfaces so users can edit files,reademail, and browse the Web without much effort.
Nevertheless, the true power of Linux lies behind the scenes.Toget the most out of Linux, you should become proficient
Figure 1. Fedora graphical desktop
* Depending on your system configuration, the interface mightlook differ-ent. GNOME and KDE are very configurable, and Fedoraincludes a thirdinterface, twm, with yet another look and feel.(And Linux has other graph-ical interfaces, too.)
7/26/2019 O'Reilly - Linux Pocket Guide
19/200
Logins, Logouts, and Shutdowns | 11
in using the shell. It might initially be more difficultthanicons and menus, but once youre used to it, the shell isquiteeasy to use and very powerful. Most of this book discusses
Linux commands run via the shell.
How to Run a ShellTo run a shell within GNOME, KDE, or any othergraphicalinterface for Linux, youll need to open a shell window.Thisis done by programs like xterm, gnome-terminal, konsole,anduxterm. Each of these programs does the same basic thing:
open a window that is running a shell, awaiting your input.Torun a shell window using the three default windowinginterfaces forFedora:
Dont confuse the window program (like konsole) with theshellrunning inside it. The window is just a containeralbeit with fancyfeatures of its ownbut the shell is whatprompts you for commandsand runs them.
If youre not running a graphical interfacesay, youre log-ging inremotely over the network, or directly over an
attached terminala shell will run immediately when youlog in. Noshell window is required.
Logins, Logouts, and ShutdownsWe assume you know how to log intoyour Linux account. Tolog out from GNOME or KDE, click the red haticon in the
Interface Take this action... ...to run this shell windowprogram
GNOME Menu : System Tools : Terminalor on the desktop:
Right Mouse Button : Open Terminal
gnome-terminal
KDE Menu : System Tools : Terminalor on the desktop:Right MouseButton : Open Terminal
konsole
twm On the desktop:Right Mouse Button : XTerm
xterm
7/26/2019 O'Reilly - Linux Pocket Guide
20/200
12 | Linux Pocket Guide
taskbar and choose Logout from the main menu. To log outfrom aremote shell, just close the shell (type exitor logout).
Never simply turn off the power to a Linux system: it needsa
more graceful shutdown. To perform a shutdown fromGNOME, chooseLogout Shut Down. From KDE, first logout, then on the login screen,click the Shutdown icon. Toperform a shutdown from a shell, run theshutdown com-mand as the superuser, as follows.
shutdown [options] time[message]/sbin
SysVinit
stdin stdout - file -- opt --help --version
The shutdowncommand halts or reboots a Linux system; onlythesuperuser may run it. Heres a command to halt the system in10minutes, broadcasting the message scheduled maintenance toallusers logged in:
# shutdown -h +10 "scheduled maintenance"
Thetimemay be a number of minutes preceded by a plus sign,like+10, an absolute time in hours and minutes, like 16:25, or thewordnowto mean immediately.
With no options, shutdownputs the system into single-user mode,aspecial maintenance mode in which only one person is logged in(atthe system console), and all nonessential services are off. Toexitsingle-user mode, either perform another shutdownto halt orreboot,
or type ^Dto bring up the system in normal, multiuser mode.
Useful options
-r Reboot the system.
-h Halt the system.
-k Kidding: dont really perform a shutdown, just broadcastwarning messagesto all users as if the system were going down.
-c Cancel a shutdown in progress (omit the timeargument).
-f On reboot, skip the usual filesystem check performed by thefsckprogram(described in Disks and Filesystems on page 91).
-F On reboot, require the usual filesystem check.
7/26/2019 O'Reilly - Linux Pocket Guide
See AlsoSpacebar Counter 1 Minute / 60-secondsCorsair K65 PLUS WIRELESS ReviewMoebius: Empire Rising WalkthroughMicrosoft Office Bible 2013.pdf21/200
The Filesystem | 13
For technical information about shutdowns, single-usermode, andvarious system states, see the manpages for initand inittab.
The FilesystemTo make use of any Linux system, you need to becomfort-able with Linux files and their layout. Every Linux file iscon-tained in a collection called a directory. Directories arelikefolders on Windows and Macintosh systems. Directories
form a hierarchy, or tree: one directory may containotherdirectories, called subdirectories, which may themselvescon-tain other files and subdirectories, and so on, intoinfinity.The topmost directory is called the root directory andisdenoted by a slash (/).*
We refer to files and directories using a names and slashes
syntax called apath. For instance, thispath:/one/two/three/four
refers to the root directory /, which contains a directorycalledone, which contains a directory two, which contains adirectorythree, which contains a final file or directory, four.If a pathbegins with the root directory, its called an abso-lutepath, and ifnot, its a relativepath. More on this in amoment.
Whenever you are running a shell, that shell is in somedirec-tory (in an abstract sense). More technically, your shell hasacurrent working directory, and when you run commands in thatshell,they operate relative (theres that word again) to thedirectory.More specifically, if you refer to a relative file path in
that shell, it is relative to your current working directory.Forexample, if your shell is in the directory /one/two/three,andyou run a command that refers to a file myfile, then itsreally
* In Linux, allfiles and directories descend from the root. Thisis unlikeWindows or DOS, in which different devices are accessed bydrive letters.
7/26/2019 O'Reilly - Linux Pocket Guide
22/200
14 | Linux Pocket Guide
/one/two/three/myfile. Likewise, a relative path a/b/cwouldimply the true path/one/two/three/a/b/c.
Two special directories are denoted . (a single period) and..
(two periods in a row). The former means your currentdirec-tory, and the latter means your parent directory, onelevelabove. So if your current directory is /one/two/three, then.refers to this directory and .. refers to/one/two.
You move your shell from one directory to another usingthecdcommand:
$ cd /one/two/three
More technically, this command changes your shellscurrentworking directory to be /one/two/three. This is anabsolutechange (since the directory begins with /); of courseyoucan make relative moves as well:
$ cd d Enter subdirectoryd
$ cd ../mydir Go up to my parent, then into directorymydirFileand directory names may contain most characters youexpect: capitaland small letters,* numbers, periods, dashes,underscores, and mostother symbols (just not /; its reservedfor separating directories).In general, however, avoid usingspaces, asterisks, parentheses, andother characters that havespecial meaning to the shell. Otherwise,youll need to quote or
escape these characters all the time. (See Quoting on page27.)
Home Directories
Users personal files are often found in /home (forordinaryusers) or/root(for superusers). Your home directory istypically/home/your-username: /home/smith, /home/jones, etc. Thereare
several ways to locate or refer to your home directory.
cdWith no arguments, the cdcommand returns you (i.e., setstheshells working directory) to your home directory.
* These are not equivalent, since Linux filenames arecase-sensitive.
7/26/2019 O'Reilly - Linux Pocket Guide
23/200
The Filesystem | 15
HOME variableThe environment variable HOME(seeShell variablesonpage 23) contains the name of your home directory.
$ echo $HOME Theechocommand prints its arguments/home/smith
~When used in place of a directory, a lone tilde is expandedbythe shell to the name of your home directory.
$ echo ~/home/smith
When followed by a username (as in ~smith), the shellexpandsthis string to be the users home directory:
$ cd ~smith$ pwd The print working directorycommand/home/smith
System Directories
A typical Linux system has tens of thousands of systemdirec-tories. These directories contain operating system files,appli-cations, documentation, and just about everythingexceptprivate user files (which typically live in/home).
Unless youre a system administrator, youll rarely visitmostsystem directoriesbut with a little knowledge you canunderstandor guess their purposes. Their names often con-
tain three parts, which well call the scope, category,andapplication. (These are not standard terms, but theyll helpyouunderstand things.) For example, thedirectory/usr/local/share/emacs, which contains local data for theEmacs texteditor, has scope/usr/local(locally installed systemfiles), cat-egory share(program-specific data and documentation),andapplication emacs (a text editor), shown inFigure 2. Well
explain these three parts, slightly out of order.
Figure 2. Directory scope, category, and application
Scope
/usr/local/share/emacsCategory Application
7/26/2019 O'Reilly - Linux Pocket Guide
24/200
16 | Linux Pocket Guide
Directory path part 1: categoryA categorytells you the types offiles found in a directory. Forexample, if the category is bin, youcan be reasonably assured
that the directory contains programs. Common categoriesarelisted below.
Categories for programs
bin Programs (usually binary files)
sbin Programs (usually binary files) intended to be run by thesuperuser, root
lib Libraries of code used by programs
libexec Programs invoked by other programs, not usually byusers; thinklibrary of executable programs
Categories for documentation
doc Documentation
info Documentation files for Emacss built-in help system
man Documentationfiles(manualpages)displayedbythe manprogram;the
files are often compressed, or sprinkled with typesettingcommands formanto interpret
share Program-specific files, such as examples and installationinstructions
Categories for configuration
etc Configuration files for the system (and other miscellaneousstuff)
init.d
rc.d
Configuration files for booting Linux; also rc1.d, rc2.d,...
Categories for programming
include Header files for programming
src Source code for programs
Categories for web files
cgi-bin Scripts/programs that run on web pages
html Web pages
public_html Web pages, typically in users home directories
www Web pages
Categories for display
fonts Fonts (surprise!)
X11 X window system files
7/26/2019 O'Reilly - Linux Pocket Guide
25/200
The Filesystem | 17
Directory path part 2: scope
The scopeof a directory path describes, at a high level, thepur-pose of an entire directory hierarchy. Some common onesare:
So for a category like lib(libraries), your Linux systemmighthave directories/lib,/usr/lib,/usr/local/lib,/usr/games/lib,and/usr/X11R6/lib. You might have other scopes as suits the sys-temadministrator:/my-company/lib,/my-division/lib, and so on.
Categories for hardware
dev Device files for interfacing with disks and otherhardware
mntmisc
Mount points: directories that provide access to disks
Categories for runtime files
var Files specific to this computer, created and updated as thecomputer runs
lockLockfiles,createdbyprogramstosay,Iamrunning;theexistenceofalockfile may prevent another program, or another instance of thesameprogram, from running or performing an action
log Log files that track important system events, containingerror, warning,and informational messages
mail Mailboxes for incoming mail
run PID files, which contain the IDs of running processes; thesefiles areoften consulted to track or kill particular processes
spool Files queued or in transit, such as outgoing email, printjobs, andscheduled jobs
tmp Temporary storage for programs and/or people to useprocOperating system state: see Operating System Directories on page18
/ System files supplied with Linux (pronounced root)/usr Moresystem files supplied with Linux (pronounced user)
/usr/games Games (surprise!)
/usr/kerberos
Files pertaining to the Kerberos authentication system
/usr/local System files developed locally, either for yourorganization or yourindividual computer
/usr/X11R6 Files pertaining to the X window system
7/26/2019 O'Reilly - Linux Pocket Guide
26/200
18 | Linux Pocket Guide
There isnt a clear distinction between/and /usrin practice,butthere is a sense that /is lower-level and closer to theoperatingsystem. So /bin contains fundamental programs
like lsand cat, /usr/bincontains a wide variety of applica-tionssupplied with your Linux distribution, and /usr/local/bin containsprograms your system administrator chose toinstall. These are nothard-and-fast rules but typical cases.
Directory path part 3: application
The application part of a directory path is usually the name
of a program. After the scope and category (say,/usr/local/doc), a program may have its own subdirectory (say,/usr/local/doc/myprogram) containing files it needs.
Operating System Directories
/boot
Files for booting the system. This is where the kernellives,typically named/boot/vmlinuz.
/lost+foundDamaged files that were rescued by a disk recoverytool.
/procDescribes currently-running processes; for advanced
users.
The files in /procprovide views into the running kernel andhavespecial properties. They always appear to be zero sized,read-only,and dated now:
$ ls -l /proc/version-r--r--r-- 1 root root 0 Oct 3 22:55/proc/version
However, their contents magically contain information abouttheLinux kernel:
$ cat /proc/versionLinux version 2.4.22-1.2115.nptl ...
Mostly these files are used by programs. Go ahead andexplore.Here are some examples.
7/26/2019 O'Reilly - Linux Pocket Guide
27/200
The Filesystem | 19
File Protections
A Linux system may have many users with login accounts.Tomaintain privacy and security, each user can access onlysome fileson the system, not all. This access control isembodied in twoquestions:
Who has permission? Every file and directory has an ownerwho haspermission to do anything with it. Typically theuser who created afile is its owner, but relationships canget more complex.
Additionally, a predefined groupof users may have per-mission toaccess a file. Groups are defined by the sys-
tem administrator and are covered in Working withGroups on page119.
Finally, a file or directory can be opened to all userswithloginaccounts on the system. Youll also see this set ofusers called theworldor simply other.
What kind of permission is granted? File owners, groups,and theworld may each have permission to read, write(modify), andexecute(run) particular files. Permissionsalso extend todirectories, which users may read (accessfiles within thedirectory), write (create and delete fileswithin the directory),and execute (enter the directory).
To see the ownership and permissions of a file, run:
$ ls -lfilename
/proc/ioports A list of your computers input/outputhardware.
/proc/version The operating system version. The unamecommandprints the sameinformation.
/proc/uptime System uptime, i.e., seconds elapsed since thesystem was last booted.Run the uptimecommand for a morehuman-readable result.
/proc/nnn Where nnnis a positive integer, information about theLinux processwith process ID nnn.
/proc/self Information about the current process youre running;a symbolic linkto a/proc/nnnfile, automatically updated. Try ls -l/proc/selfa few times in a row: youll see/proc/selfchanging whereitpoints.
7/26/2019 O'Reilly - Linux Pocket Guide
28/200
20 | Linux Pocket Guide
To see the ownership and permissions of a directory, run:
$ ls -lddirectory_name
The file permissions are the 10 leftmost characters in theout-put, a string ofr(read), w(write), x(execute), and otherlet-ters. For example:
drwxr-x---
Heres what these letters and symbols mean.
We describe lsin more detail inBasic File Operations onpage 37.To change the owner, group ownership, or permis-sions of a file,use the chown, chgrp, and chmod commands,respectively, as describedin File Properties on page 56.
The ShellIn order to run commands on a Linux system, youllneedsomewhere to type them. That somewhere is called theshell,which is Linuxs command-line user interface: you typea command andpress Enter, and the shell runs whatever pro-gram (or programs)youve requested. To run a shell, seeFedora: A First View on page9.
For example, to see whos logged in, you could executethiscommand in a shell:
$ whobarrett :0 Sep 23 20:44byrnes pts/0 Sep 15 13:51silverpts/1 Sep 22 21:15silver pts/2 Sep 22 21:18
Position Meaning
1 File type: -= file, d= directory, l= symbolic link, p= namedpipe,c= character device, b= block device
24 Read, write, and execute permissions for the files owner
57 Read, write, and execute permissions for the files group
810 Read, write, and execute permissions for all other users
7/26/2019 O'Reilly - Linux Pocket Guide
29/200
The Shell | 21
(The dollar sign is the shell prompt, which means the shellisready to run a command.) A single command can also invokeseveralprograms at the same time, and even connect pro-
grams together so they interact. Heres a command that redi-rectsthe output of the whoprogram to become the input ofthe wcprogram,which counts lines of text in a file; the resultis the number oflines in the output ofwho:
$ who | wc -l4
telling you how many users are logged in.* The vertical bar,
called apipe, makes the connection between whoand wc.
A shell is actually a program itself, and Linux has several.Wefocus on Bash (the Bourne-Again Shell), located in /bin/bash,which is the Fedora Linux default.
The Shell Versus Programs
When you run a command, it might invoke a Linux program(likewho), or instead it might be a built-in command, a fea-ture of theshell itself. You can tell the difference with thetypecommand:
$ type whowho is /usr/bin/who
$ type cdcd is a shell builtin
It is helpful to know what the shell provides versus whatLinuxdoes. The next few sections describe features of theshell.
Selected bash Features
A shell does much more than simply run commands. It alsoprovidespowerful features to make this task easier. Examples
* Actually, how many interactive shells those users are running.If a user hasseveral shells running, like the user silver in ourexample, theyll have thatmany lines of output in who.
7/26/2019 O'Reilly - Linux Pocket Guide
30/200
22 | Linux Pocket Guide
are wildcards for matching filenames, redirection of com-mandoutput and input to and from files, pipes for makingthe output ofone command become the input of another,
aliases to run common commands quickly, variables for stor-ingvalues for use by the shell, and more. Were just scratch-ing thesurface to introduce you to a set of useful tools. Runinfo bashforfull documentation.
Wildcards
Wildcards provide a shorthand for specifying sets of files
with similar names. For example, a* means all files whosenamesbegin with lowercase a. Wildcards are expandedby the shell into theactual set of filenames they match. So ifyou type:
$ ls a*
the shell first expands a*into the filenames that begin with
a in your current directory, as if you had typed:ls aardvarkadamantium apple
lsnever knows you used a wildcard: it sees only the final listoffilenames after the shell expansion.
When using sets, if you want to include a literal dash intheset, put it first or last. To include a literal closingsquarebracket in the set, put it first. To include a ^ or !literally,dont put it first.
Wildcard Meaning
* Any set of characters except a leading period? Any singlecharacter
[set] Any single character in the given set, most commonly asequence ofcharacters, like [aeiouAEIOU]for all vowels, or a rangewith a dash,like [A-Z]for all capital letters
[^set][!set]
Any single character notin the given set(as above)
7/26/2019 O'Reilly - Linux Pocket Guide
31/200
The Shell | 23
Brace expansion
Similar to wildcards, expressions with curly braces alsoexpandto become multiple arguments to a command. The
comma-separated expression:{a,b,cc,ddd}
expands to:
a b cc dddd
Braces work with any strings, unlike wildcards which arelimitedto filenames. For example, sand{X,Y,ZZZ}wich
expands to:$ echo sand{X,Y,ZZZ}wichsandXwich sandYwichsandZZZwich
regardless of what files are in the current directory.
Tilde expansion
The shell treats tildes (~) as special characters if theyappearalone or at the beginning of a word.
Shell variables
You can define variables and their values by assigning them:$MYVAR=3
To refer to a value, simply place a dollar sign in front ofthevariable name:
$ echo $MYVAR3
Some variables are standard and commonly defined by yourshellupon login.
~ Your home directory
~smith User smiths home directory
Variable Meaning
DISPLAY The name of your X window display
HOME The name of your home directory
7/26/2019 O'Reilly - Linux Pocket Guide
32/200
24 | Linux Pocket Guide
To see a shells variables, run:
$ printenv
The scope of the variable (i.e., which programs know aboutit)is, by default, the shell in which its defined. To make a
variable and its value available to other programs yourshellinvokes (i.e., subshells), use the exportcommand:
$ export MYVAR
or the shorthand:
$ export MYVAR=3
Your variable is now called an environment variable, sinceits
available to other programs in your shells environment.To make aspecific value available to a specific program justonce,prependvariable=valueto the command line:
$ echo $HOME/home/smith$ HOME=/home/sallyecho "My home is$HOME"My home is /home/sally$ echo $HOME/home/smith The originalvalue is unaffected
Search path
A very important variable is PATH, which instructs theshellwhere to find programs. When you type any command:
$ who
LOGNAME Your login name
MAIL Path to your incoming mailbox
OLDPWD Your shell's previous directory
PATH Your shell search path: directories separated by colons
PWD Your shell's current directory
SHELL The path to your shell, e.g.,/bin/bash
TERM The type of your terminal, e.g., xterm or vt100
USER Your login name
Variable Meaning
7/26/2019 O'Reilly - Linux Pocket Guide
33/200
The Shell | 25
the shell has to find the program(s) in question. It consultsthevalue of PATH, which is a sequence of directories sepa-rated bycolons:
$ echo$PATH/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/smith/bin
and looks for the whocommand in each of these directories. Ifitfinds who(say,/usr/bin/who), it runs the command. Other-wise, itreports:
bash: who: command not found
To add directories to your shells search path temporarily,modifyits PATHvariable. For example, to append /usr/sbintoyour shellssearch path:
$ PATH=$PATH:/usr/sbin$ echo$PATH/usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin:/home/smith/bin:/usr/sbin
To make this change permanent, modify the PATHvariable inyourstartup file ~/.bash_profile, as explained inTailoringShellBehavior on page 33.Then log out and log back in.
Aliases
The built-in command aliasdefines a convenient shorthand
for a longer command, to save typing. For example:$ alias ll='ls-l'
defines a new command llthat runs ls -l:
$ lltotal 436-rw-r--r-- 1 smith 3584 Oct 11 14:59file1-rwxr-xr-x 1 smith 72 Aug 6 23:04 file2
...
Define aliases in your ~/.bashrcfile (seeTailoring ShellBehav-ior on page 33) to be available whenever you log in. To seeallyour aliases, type alias. If aliases dont seem powerfulenoughfor you (since they have no parameters or branching), see
7/26/2019 O'Reilly - Linux Pocket Guide
34/200
26 | Linux Pocket Guide
Programming with Shell Scripts on page 166,run info bash,andread up on shell functions.
Input/output redirectionThe shell can redirect standard input,standard output, andstandard error to and from files. In otherwords, any com-mand that reads from standard input can have itsinput comefrom a file instead with the shells < operator:
$ mycommand < infile
Likewise, any command that writes to standard output canwrite toa file instead:
$ mycommand > outfile Create/overwrite outfile$ mycommand>> outfile Append to outfile
A command that writes to standard error can have itsoutputredirected to a file as well:
$ mycommand 2> errorfileTo redirect both standard output andstandard error to files:
$ mycommand > outfile 2> errorfile Separate files$mycommand > outfile 2>&1 Single file
Pipes
Using the shell, you can redirect the standard output ofonecommand to be the standard input of another, using theshellspipe (|) operator. For example:
$ who | sort
sends the output of whointo the sort program, printinganalphabetically sorted list of logged-in users.
Combining commandsTo invoke several commands in sequence on asingle com-mand line, separate them with semicolons:
$command1;command2;command3
7/26/2019 O'Reilly - Linux Pocket Guide
35/200
The Shell | 27
To run a sequence of commands as above, but stop execu-tion ifany of them fails, separate them with && (and)symbols:
$command1&&command2&&command3
To run a sequence of commands, stopping execution as soonas onesucceeds, separate them with || (or) symbols:
$command1||command2||command3
Quoting
Normally, the shell treats whitespace simply as separatingthewords on the command line. If you want a word to con-tainwhitespace(e.g., a filename with a space in it), surroundit with single ordouble quotes to make the shell treat it as aunit. Single quotestreat their contents literally, while doublequotes let shellconstructs be evaluated, such as variables:
$ echo 'The variable HOME has value $HOME'The variable HOME hasvalue $HOME$ echo "The variable HOME has value $HOME"The variableHOME has value /home/smith
Backquotes cause their contents to be evaluated as a com-mand;the contents are then replaced by the standard outputof thecommand:
$ /usr/bin/whoamismith$ echo My name is `/usr/bin/whoami`My nameis smith
Escaping
If a character has special meaning to the shell but you wantitused literally (e.g., * as a literal asterisk rather than awild-card), precede the character with the backward slash\character. This is called escapingthe special character:
$ echo a* As a wildcard, matching a filenamesaardvark agnosticapple$ echo a\* As a literal asteriska*
See AlsoSpacebar Counter 60 Seconds7/26/2019 O'Reilly - Linux Pocket Guide
36/200
28 | Linux Pocket Guide
$ echo "I live in $HOME" Dollar sign means a variable valueIlive in /home/smith$ echo "I live in \$HOME" A literal dollar signIlive in $HOME
You can also escape control characters (tabs, newlines, ^D,andso forth) to have them used literally on the commandline, if youprecede them with ^V. This is particularly usefulfor tab (^I)characters, which the shell would otherwise usefor filenamecompletion (see Filename completion onpage 29).
$ echo "There is a tab between here^V^Iand here"There is a tabbetween here and here
Command-line editing
bashlets you edit the command line youre working on,usingkeystrokes inspired by the text editors emacsandvi(seeFileCreation and Editing on page 51). To enablecommand-line
editing with emacskeys, run this command (and place itinyour~/.bash_profileto make it permanent):
$ set -o emacs
For vikeys:
$ set -o vi
emacs keystrokevi keystroke(first type ESC) Meaning
^P or up arrow k Previous command line
^N or down arrow j Next command line
^F or right arrow l Forward one character
^B or left arrow h Backward one character
^A 0 Beginning of line^E $ End of line
^D x Delete next character
^U ^U Erase entire line
7/26/2019 O'Reilly - Linux Pocket Guide
37/200
The Shell | 29
Command history
You can recall previous commands youve runthat is, theshellshistoryand then edit and re-execute them. Some
useful history-related commands are listed below.
Filename completionPress the TAB key while you are in the middleof typing afilename, and the shell will automatically complete(finishtyping) the filename for you. If several filenames matchwhat
youve typed so far, the shell will beep, indicating the matchisambiguous. Immediately press TAB again and the shell willpresentthe alternatives. Try this:
$ cd /usr/bin$ ls un
Job Control
Command Meaning
history Print your history
historyN Print the most recent Ncommands in your history
history -c Clear (delete) your history
!! Previous command
!N Command number Nin your history
!-N The command you typed Ncommands ago
!$ The last parameter from the previous command; great forcheckingthat files are present before removing them:
$ ls a*
$ rm !$
!* All parameters from the previous command
jobs List your jobs
& Run a job in the background
^Z Suspend the current (foreground) job
suspend Suspend a shell
fg Unsuspend a job: bring it into the foreground
bg Make a suspended job run in the background
7/26/2019 O'Reilly - Linux Pocket Guide
38/200
30 | Linux Pocket Guide
All Linux shells havejob control: the ability to run programsinthe background (multitasking behind the scenes) and fore-ground(running as the active process at your shell prompt).
A job is simply the shells unit of work. When you run acommandinteractively, your current shell tracks it as a job.When thecommand completes, the associated job disap-pears. Jobs are at ahigher level than Linux processes; theLinux operating system knowsnothing about them. They aremerely constructs of the shell. Someimportant vocabularyabout job control is:
foreground jobRunning in a shell, occupying the shell prompt soyoucannot run another command
background jobRunning in a shell, but not occupying the shellprompt,so you can run another command in the same shell
suspendTo stop a foreground job temporarily
resumeTo cause a suspended job to start running again
jobs
The built-in command jobslists the jobs running in yourcurrentshell.
$ jobs[1]- Running emacs myfile &[2]+ Stopped su
The integer on the left is the job number, and the plus signidenti-fies the default job affected by the fg (foreground) andbg
(background) commands.
&
Placed at the end of a command-line, the ampersand causesthegiven command to run as a background job.
$ emacs myfile &[2] 28090
7/26/2019 O'Reilly - Linux Pocket Guide
39/200
The Shell | 31
The shells response includes the job number (2) and theprocessID of the command (28090).
^ZTyping ^Zin a shell, while a job is running in the foreground,willsuspend that job. It simply stops running, but its stateisremembered.
$ mybigprogram^Z[1]+ Stopped mybigprogram
$Now youre ready to type bgto put the command into theback-ground, or fgto resume it in the foreground.
suspend
The built-in command suspendwill suspend the current shellif
possible, as if youd typed ^Zto the shell itself. For instance,ifyouve run the sucommand and want to return to youroriginalshell:
$ whoamismith$ su -lPassword: *******# whoami
root# suspend[1]+ Stopped su$ whoamismith
bg [%jobnumber]
The built-in command bg sends a suspended job to run inthebackground. With no arguments, bgoperates on the mostrecentlysuspended job. To specify a particular job (shown by thejobscommand), supply the job number preceded by a percent sign:
$ bg %2
7/26/2019 O'Reilly - Linux Pocket Guide
40/200
32 | Linux Pocket Guide
Some types of interactive jobs cannot remain in thebackgroundfor instance, if they are waiting for input. If you try,the shell willsuspend the job and display:
[2]+ Stopped command line hereYou can now resume the job (withfg) and continue.
fg [%jobnumber]
The built-in command fg brings a suspended or backgroundedjobinto the foreground. With no arguments, it selects a job,usuallythe most recently suspended or backgrounded one. Tospecify aparticular job (as shown by the jobs command), supplythe job numberpreceded by a percent sign:
$ fg %2
Killing a Command in Progress
If youve launched a command from the shell running intheforeground, and want to kill it immediately, type ^C. Theshellrecognizes ^Cas meaning, terminate the currentforegroundcommand right now. So if you are displaying a very longfile(say, with the catcommand) and want to stop, type ^C:
$ cat bigfile
This is a very long file with many lines. Blah blah blahblahblah blah blahblahblah ^C$
To kill a program running in the background, you can bringitinto the foreground with fgand then type ^C, or alterna-tively, usethe kill command (seeControlling Processeson page 108).
In general, ^Cis not a friendly way to end a program. Iftheprogram has its own way to exit, use that when possible. Yousee,^C kills the program immediately, not giving it anychance to cleanup after itself. Killing a foreground programmay leave your shellin an odd or unresponsive state, per-haps not displaying thekeystrokes you type. If this happens:
7/26/2019 O'Reilly - Linux Pocket Guide
41/200
Installing Software | 33
1. Press ^Jto get a shell prompt. This produces thesamecharacter as the Enter key (a newline) but will work evenifEnter does not.
2. Type the word reset (even if the letters dont appearwhile youtype) and press ^Jagain to run this command.This should reset yourshell.
^Cworks only when typed into a shell. It will likely havenoeffect if typed in a window that is not a shell window.Addi-tionally, some programs are written to catch the ^C andignoreit: an example is the text editor emacs.
Terminating a Shell
To terminate a shell, either run the exit command ortype^D.*
$ exit
Tailoring Shell Behavior
To configure all your shells to work in a particular way,editthe files .bash_profile and .bashrc in your homedirectory.These files execute each time you log in(~/.bash_profile) oropen a shell (~/.bashrc). They can setvariables and aliases,run programs, print your horoscope, orwhatever you like.
These two files are examples of shell scripts: executablefilesthat contain shell commands. Well cover this feature inmoredetail in Programming with Shell Scripts on page 166.
Installing SoftwareYou will probably want to add furthersoftware to your Linuxsystem from time to time. The most commonforms of pack-aged software for Fedora and many other Linux distrosare:
* Control-D indicates end of file to any program reading fromstandardinput. In this case, the program is the shell itself, whichterminates.
7/26/2019 O'Reilly - Linux Pocket Guide
42/200
34 | Linux Pocket Guide
*.rpm filesRed Hat Package Manager (RPM) files. Theseareinstalled and managed with the programs rpm(manually)
and up2date(automatically).*.tar.gz files, *.tar.Z files, and*.tar.bz2 files
Compressed tar files. They are packaged with tar andcompressedwith gzip(.gz), compress(.Z), or bzip2(.bz2).
Most new software must be installed by the superuser, soyoullneed to run the su command (or equivalent) before
installation. For example:$ su -lPassword: ********# rpm -ivhmypackage.rpm...etc...
To locate new software, check your Linux CD-ROMs or visitfinesites like these:
http://freshmeat.net/http://freshrpms.net/http://rpmfind.net/http://sourceforge.net/
up2date [options] [packages]
/usr/bin
up2date
stdin stdout - file -- opt --help --version
up2dateis the easiest way to keep your Fedora system... well,upto date. As root, just run:
# up2date
and follow the prompts. This provides a graphical userinter-face. You can also run up2datein command-line mode:
# up2date -l
to list all updated RPM packages (if any) available foryoursystem. To download the given packages, run:
# up2date -dpackages
7/26/2019 O'Reilly - Linux Pocket Guide
43/200
Installing Software | 35
To install the given RPM packages you have already down-loadedwith up2date -d, run:
# up2date -ipackages
up2datedownloads RPM packages from Red Hat or Fedora-relatedservers over the Internet, so you might need to regis-ter yoursystem with them the first time you run up2date.
Some Linux users prefer other programs to up2date, such asyum(http://linux.duke.edu/projects/yum/) and apt(http://ayo.freshrpms.net/).
rpm [options] [files]/bin
rpm
stdin stdout - file -- opt --help --version
If you prefer to install RPM packages by hand, use rpm, thesamepackage-management program that up2dateruns behindthe scenes.rpmnot only installs the software, but also makes
sure your system has all prerequisites. For example, if pack-agesuperstuff requires package otherstuff that you haventinstalled,rpmwill not install superstuff. If your system passesthe test,however, rpmcompletely installs the software.
RPM filenames typically have the formname-version.architecture.rpm. For example,emacs-20.7-17.i386.rpmindicates the emacspackage, Version 20.7-17,for i386 (Intel
80386 and higher) machines. Be aware that rpmsometimesrequires afilename argument (like emacs-20.7-17.i386.rpm)and other times justthe package name (like emacs).
Common commands for manipulating RPM packages are:
rpm -qpackage_name
Find out ifpackage_nameis installed on your system, and
what version. Example: rpm -q textutils. If you dontknow thename of the package (a chicken-and-eggproblem), list all packagesand use grep to search forlikely names:
$ rpm -qa | grep -ilikely_name
7/26/2019 O'Reilly - Linux Pocket Guide
44/200
36 | Linux Pocket Guide
rpm -qlpackage_name
List the files included in the given, installed package. Tryrpm-ql emacs.
rpm -qipackage_nameGet general information about thepackage.
rpm -qlppackage.rpm
List the contents of an RPM file, not necessarily installedyet.Use -qipfor general information about the RPM file.
rpm -qa
List all installed RPM packages. Useful for pipingthrough greptolocate a package name:
rpm -qa | grep -i emacs
rpm -qffilename
Print the package that installed a given file on yoursystem.
$ rpm -qf /usr/bin/who
sh-utils-2.0-11
rpm -ivhpackage1.rpmpackage2.rpm...Install packages not alreadypresent on your system
rpm -Fvhpackage1.rpmpackage2.rpm...Update packages that arealready present on your system
rpm -epackage_names
Erase (delete) packages from your system. In this case, donotinclude the package version number, just the pack-age name. Forexample, if you install the GNU Emacspackageemacs-20.7-17.i386.rpm, you would uninstall itwith rpm -e emacs,not rpm -e emacs-20.7-17.rpm.
tar.gz and tar.bz2 filesPackaged software files with namesending .tar.gzand .tar.bz2typically contain source code that youllneed to compile(build) before installation.
1. List the package contents, one file per line. Assureyour-self that each file, when extracted, wont overwrite
7/26/2019 O'Reilly - Linux Pocket Guide
45/200
Basic File Operations | 37
something precious on your system, either accidentallyormaliciously:
$ tar tvzfpackage.tar.gz | less For gzip files
$ tar tvjfpackage.tar.bz2 | less For bzip2 files2. If satisfied,extract the files into a new directory:
$ mkdir newdir$ cd newdir$ tar xvzf/package.tar.gz For gzipfiles$ tar xvjf/package.tar.bz2 For bzip2 files
3. Look for an extracted file named INSTALLor README.
Read it to learn how to build the software, for example:$ cdnewdir$ less INSTALL
4. Usually the INSTALL or README file will tell you torun ascript called configure in the current directory,then run make,then run make install. Examine theoptions you may pass to theconfigurescript:
$ ./configure --help
Then install the software:
$ ./configureoptions$ make$ suPassword: *******# makeinstall
Basic File Operations
One of the first things youll need to do on a Linux systemismanipulate files: copying, renaming, deleting, and so forth.
ls List files in a directory
cp Copy a file
mv Rename (move) a file
rm Delete (remove) a fileln Create links (alternative names) toa file
7/26/2019 O'Reilly - Linux Pocket Guide
46/200
38 | Linux Pocket Guide
ls [options] [files]/bin
coreutils
stdin stdout - file -- opt --help --version
The ls command (pronounced as it is spelled, ell ess) lists
attributes of files and directories. You can list files in thecurrentdirectory:
$ ls
in given directories:
$ ls dir1 dir2 dir3
or individually:
$ ls file1 file2 file3
The most important options are -aand -l. By default,lshidesfiles whose names begin with a dot; the -aoption displaysall files.The -loption produces a long listing:
-rw-r--r-- 1 smith users 149 Oct 28 2002 my.data
that includes, from left to right: the files permissions(-rw-r--r--),
owner (smith), group (users), size (149 bytes), lastmodificationdate (Oct 28 2002) and name. SeeFile Protections onpage 19for more information on permissions.
Useful options
-a List all files, including those whose names begin with adot.
-l Longlisting,includingfileattributes.Addthe -h option(human-readable)
to print file sizes in kilobytes, megabytes and gigabytes,instead of bytes.-F Decorate certain filenames with meaningfulsymbols, indicating their types.
Appends / to directories, * to executables, @ to symbolic links,| tonamed pipes, and = to sockets. These are just visual indicatorsfor you, notpart of the filenames!
-i Prepend the inode numbers of the files.
-s Prepend the size of the file in blocks, useful for sortingfiles by their size:
$ ls -s | sort -n-R If listing a directory, list its contentsrecursively.
-d If listing a directory, do not list its contents, just thedirectory itself.
7/26/2019 O'Reilly - Linux Pocket Guide
47/200
Basic File Operations | 39
cp [options] files(file|dir)/bin
coreutils
stdin stdout - file -- opt --help --version
The cpcommand normally copies a file:
$ cp file file2
or copies multiple files into a directory:
$ cp file1 file2 file3 file4 dir
Using the -a or -R option, you can also recursivelycopydirectories.
Useful options
mv [options] source target/bin
coreutils
stdin stdout - file -- opt --help --version
The mv(move) command can rename a file:
$ mv file1 file2
or move files and directories into a destination directory:
$ mv file1 file2 dir3 dir4destination_directory
Useful options
rm [options] files| directories/bin
coreutils
stdin stdout - file -- opt --help --version
The rm(remove) command can delete files:
$ rm file1 file2 file3
-p Copy not only the file contents, but also the filespermissions, timestamps,and if you have sufficient permission to doso, its owner and group. (Normallythe copies will be owned by you,timestamped now, with permissions set byapplying your umask to theoriginal permissions.)
-a Copy a directory hierarchy recursively, preserving specialfiles, permissions,symbolic links, and hard link relationships.This combines the options -R(recursive copy including specialfiles), -p(permissions), and -d(links).
-i Interactive mode. Ask before overwriting destinationfiles.
-f Force the copy. If a destination file exists, overwrite itunconditionally.
-i Interactive mode. Ask before overwriting destinationfiles.
-f Force the move. If a destination file exists, overwrite itunconditionally.
7/26/2019 O'Reilly - Linux Pocket Guide
48/200
40 | Linux Pocket Guide
or recursively delete directories:
$ rm -r dir1 dir2
Useful options
ln [options] source target/bin coreutilsstdin stdout - file --opt --help --version
A linkis a reference to another file, created by thelncommand.There are two kinds of links. A symbolic linkrefers toanother fileby its path, much like a Windows shortcut or aMacintoshalias.
$ ln -s myfile softlink
If you delete the original file, the now-dangling link willbeinvalid, pointing to a nonexistent file path. A hard link, ontheother hand, is simply a second name for a physical file on disk(intech talk, it points to the same inode). Deleting the originalfiledoes not invalidate the link.
$ ln myfile hardlink
Symbolic links can cross disk partitions, since they are justrefer-ences to file paths; hard links cannot, since an inode on onediskhas no meaning on another. Symbolic links can also pointtodirectories, whereas hard links cannot... unless you are thesuper-user and use the -doption.
Useful options
-i Interactive mode. Ask before deleting each file.
-f Force the deletion, ignoring any errors or warnings.
-r Recursively remove a directory and its contents. Use withcaution, especiallyif combined with the -foption.
-s Make a symbolic link. The default is a hard link.
-i Interactive mode. Ask before overwriting destinationfiles.
-f Force the link. If a destination file exists, overwrite itunconditionally.
-d Allow the superuser to create a hard link to a directory.
7/26/2019 O'Reilly - Linux Pocket Guide
49/200
Directory Operations | 41
Its easy find out where a symbolic link points with either ofthesecommands:
$ readlink linkname
$ ls -l linkname
Directory Operations
We discussed the directory structure of Linux inThe Filesys-temon page 13. Now well cover commands that create, mod-ify, delete,and manipulate directories within that structure.
cd [directory]shell built-in
bash
stdin stdout - file -- opt --help --version
The cd (change directory) command sets your currentworkingdirectory. With no directory supplied, cddefaults to yourhomedirectory.
pwdshell built-in
bash
stdin stdout - file -- opt --help --version
The pwd command prints the absolute path of your currentworkingdirectory:
$ pwd/users/smith/mydir
cd Change your current directory
pwd Print the name of your current directory, i.e., where youare now inthe filesystem
basename Print the final part of a file path
dirname Remove the final part of a file path
mkdir Create a directory
rmdir Delete an empty directory
rm -r Delete a nonempty directory and its contents
7/26/2019 O'Reilly - Linux Pocket Guide
50/200
42 | Linux Pocket Guide
basenamepath/bin
coreutils
stdin stdout - file -- opt --help --version
The basenamecommand prints the final component in a filepath;
so for the example above:$ basename /users/smith/mydirmydir
dirnamepath/usr/bin
coreutils
stdin stdout - file -- opt --help --version
The dirnamecommand removes the final component from afilepath:
$ dirname /users/smith/mydir/users/smith
dirnamesimply manipulates a string that is a directory name.Itdoes not change your current working directory.
mkdir [options] directories/bin
coreutilsstdin stdout - file -- opt --help --version
mkdircreates one or more directories:
$ mkdir d1 d2 d3
Useful options
rmdir [options] directories/bin
coreutils
stdin stdout - file -- opt --help --version
The rmdir (remove directory) command deletes one or moreemptydirectories you name. To delete a nonempty directory anditscontents, use (carefully) rm -rdirectory. Use rm -ridirectory
-p If you supply a directory path (not just a simple directoryname), create anynecessary parent directories automatically: mkdir-p/one/two/threewill create/oneand/one/twoif they dont alreadyexist, then/one/two/three.
-mmode Create the directory with the given permissions:$ mkdir0755 mydir
Bydefault,yourshellsumaskcontrolsthepermissions.Seethechmodcommandin File Properties on page 56,and File Protections on page19.
7/26/2019 O'Reilly - Linux Pocket Guide
51/200
File Viewing | 43
to delete interactively, or rm -rfdirectoryto annihilatewithoutany error messages or confirmation.
Useful options
File Viewing
In Linux, youll encounter various types of files to view:plaintext, Postscript, binary data, and more. Here well explainhowto view them. Note that commands for viewing graph-ics files arecovered in Graphics and Screensavers onpage 160, and audio files inAudio and Video on page 163.
cat [options] [files]/bin
coreutils
stdin stdout - file -- opt --help --version
The simplest viewer is cat, which just copies its files tostandardoutput, concatenating them (hence the name). Note thatlargefiles will likely scroll off screen, so consider using lessifyou planto view the output. That being said, catis particularlyuseful forsending a set of files into a shell pipeline.
-p If you supply a directory path (not just a simple directoryname), delete notonly the given directory, but the specified parentdirectories automatically,all of which must be otherwise empty. Sormdir -p /one/two/threewill delete not only/one/two/three, butalso/one/twoand/oneifthey exist.
cat View files in their entirety
less View files one page at a time
head View the first lines of a file
tail View the last lines of a filenl View files with their linesnumbered
od View data in octal (or other formats)
xxd View data in hexadecimal
gv View Postscript or PDF files
xdvi View TeX DVI files
7/26/2019 O'Reilly - Linux Pocket Guide
52/200
44 | Linux Pocket Guide
cat can also manipulate its output in small ways,optionallydisplaying nonprinting characters, prepending linenumbers (thoughnlis more powerful for this purpose), andeliminating whitespace.
Useful options
less [options] [files]/usr/bin
less
stdin stdout* - file -- opt --help --version
Use less to view text one page at a time (or one window or
screenful at a time). Its great for text files, or as thefinalcommand in a shell pipeline with lengthy output.
$ command1 | command2 | command3 | command4 | less
While running less, type hfor a help message describing allitsfeatures. Here are some useful keystrokes for paging throughfiles.
-T Print tabs as ^I.
-E Print newlines as $.
-v Print other nonprinting characters in a human-readableformat.
-n Prepend line numbers to every line.
-b Prepend line numbers to nonblank lines.-s Squeeze eachsequence of blank lines into a single blank line.
* Although technically lesscan be plugged into the middle of apipeline, orits output redirected to a file, there isnt much pointto doing this.
Keystroke Meaning
h, H View a help page.
Spacebar, f, V, ^F Move forward one screenful.
Enter Move forward one line.
b, ^B, ESC-b Move backward one screenful.
/ Enter search mode. Follow it with a regular expressionandpress Enter, and lesswill look for the first line matchingit.
? Same as/, but it searches backward in the file.
n Repeat your most recent search forward.
N Repeat your most recent search backward.
7/26/2019 O'Reilly - Linux Pocket Guide
53/200
File Viewing | 45
less has a mind-boggling number of features; were presentingonlythe most common. The manpage is recommended reading.
Useful options
head [options] [files]/usr/bin coreutilsstdin stdout - file --opt --help --version
The head command prints the first 10 lines of a file: greatforpreviewing the contents.
$ head myfile$ head * | less Preview all files in thecurrentdirectory
Useful options
v Edit the current file with your default text editor (the valueof environment variable VISUAL, or if not defined, EDITOR, or
if not defined, vi.< Jump to beginning of file.
> Jump to end of file.
:n Jump to next file.
:p Jump to previous file.
-c Clear the screen before displaying the next page.
-m Print a more verbose prompt, displaying the percentage of thefile displayedso far.
-N Prepend line numbers to the output.-r Display controlcharacters literally; normally lessconverts them to a
human-readable format.
-s Squeeze multiple, adjacent blank lines into a single blankline.
-S Truncate long lines to the width of the screen, instead ofwrapping.
-N-n N
Print the first Nlines instead of 10.
-cN Print the first Nbytes of the file.
-q Quiet mode: when processing more than one file, dont print abanner aboveeach file. Normally headprints a banner containing thefilename.
Keystroke Meaning
7/26/2019 O'Reilly - Linux Pocket Guide
54/200
46 | Linux Pocket Guide
tail [options] [files]/usr/bin
coreutils
stdin stdout - file -- opt --help --version
The tailcommand prints the last 10 lines of a file, and doesother
tricks as well.$ tail myfile
Useful options
nl [options] [files]/usr/bin
coreutils
stdin stdout - file -- opt --help --version
nlcopies its files to standard output, prepending linenumbers.Its more flexible than catwith its -nand -boptions,providing analmost bizarre amount of control over the numbering.nlcan beused in two ways: on ordinary text files, and on speciallymarked-
up text files with predefined headers and footers.
Useful options
-N-nN
Print the last Nlines of the file instead of 10.
+N Print all lines except the first N.
-cN Print the last Nbytes of the file.
-f Keep the file open, and whenever lines are appended to thefile, print them.Thisisextremelyuseful.Addthe--retryoptionifthefiledoesntexistyet,but you want to wait for it toexist.
-q Quiet mode: when processing more than one file, dont print abanner aboveeach file. Normally tailprints a banner containing thefilename.
-b [a|t|n|pR] Prepend numbers to all lines (a), nonblank lines(t), no lines (n), oronly lines that contain regular expression R.(Default=a)
-vN Begin numbering with integer N. (Default=1)
-iN Increment the number by Nfor each line, so for example, youcould
use odd numbers only (-i2) or even numbers only (-v2-i2).(Default=1)
-n [ln|rn|rz] Format numbers as left-justified (ln),right-justified (rn), or right-justified with leading zeroes (rz).(Default=ln)
-wN Force the width of the number to be Ncolumns.(Default=6)
-sS Insert string Sbetween the line number and thetext.(Default=TAB)
7/26/2019 O'Reilly - Linux Pocket Guide
55/200
File Viewing | 47
Additionally, nl has the wacky ability to divide text filesintovirtual pages, each with a header, body, and footer withdifferentnumbering schemes. For this to work, however, you mustinsertnl-specific delimiter strings into the file: \:\:\:(start ofheader),\:\:(start of body), and \:(start of footer). Each mustappear ona line by itself. Then you can use additional options (seethemanpage) to affect line-numbering in the headers and footersofyour decorated file.
od [options] [files]/usr/bin
coreutils
stdin stdout - file -- opt --help --version
When you want to view a binary file, consider od(Octal Dump)forthe job. It copies one or more files to standard output,displayingtheir data in ASCII, octal, decimal, hexadecimal, orfloating point,in various sizes (byte, short, long). For example,this command:
$ od -w8 /usr/bin/who0000000 042577 043114 000401 000001
0000010 000000 000000 000000 0000000000020 000002 000003 0000010000000000030 106240 004004 000064 000000...
displays the bytes in binary file /usr/bin/whoin octal, eightbytesper line. The column on the left contains the file offset ofeachrow, again in octal.
Useful options
-N B Display only the first Bbytes of each file, specifiedindecimal, hexadecimal (by prepending 0x or 0X), 512-byte blocks(by appending b), kilobytes (byappendingk),ormegabytes(byappendingm).(Defaultistodisplaythe entirefile.)
-j B Begin the output at byte B+1 of each file; acceptable
formats are the same as in the -Noption. (Default=0)-w [B]DisplayB bytesperline;acceptableformatsarethesame
as in the -Noption. Using -wby itself is equivalent to -w32.(Default=16)
-s [B] Group each row of bytes into sequences ofBbytes,separatedby whitespace; acceptable formats are thesameasinthe -N option.Using -s byitselfisequivalentto -s3. (Default=2)
7/26/2019 O'Reilly - Linux Pocket Guide
56/200
48 | Linux Pocket Guide
xxd [options] [files]/usr/bin
vim-common
stdin stdout - file -- opt --help --version
Similar to od, xxdproduces a hexadecimal or binary dump of afilein several different formats. It can also do the reverse,converting
from its hex dump format back into the original data.Forexample, the command:
$ xxd /usr/bin/who0000000:7f45 4c46 0101 0100 0000 0000 00000000 .ELF............0000010:0200 0300 0100 0000 a08c 0408 34000000 ............4...0000020:6824 0000 0000 0000 3400 2000 06002800 h$......4. ...(.0000030:1900 1800 0600 0000 3400 0000 34800408 ........4...4......
displays a hex dump of binary file/usr/bin/who, 16 bytes perrow.The left column indicates the file offset of the row, the nexteightcolumns contain the data, and the final column displays theprint-able characters in the row, if any.
xxdproduces three-column output by default: file offsets, thedatain hex, and the data as text (printable characters only).
-A (d|o|x|n) Display file offsets in the leftmost column, indecimal(d), octal (o), hexadecimal (h), or not at all(n).(Default=o)
-t (a|c)[z] Display output in a character format,withnonalphanumeric characters printed as escapesequences (a) or byname (c). For z, see below.
-t (d|o|u|x)[SIZE[z]] Display output in an integer format,including octal (o),signed decimal (d), unsigned decimal (u),hexadecimal(x). (For binary output, usexxdinstead.) SIZErepresentsthe number of bytes per integer; it can be apositive integer or anyof the values C, S, I, or L, whichstand for the size of a char,short, int, or long datatype,respectively. For z, see below.
-t f[SIZE[z]] Display output in floating point. SIZErepresentsthenumber of bytes per integer; it can be a positive integeror anyof the values F, D, or L, which stand for the size ofa float,double, or long double datatype, respectively.For z, see below.If-tis omitted, the default is -to2.Appending zto the -tparameterprints a new columnon the right-hand side of the output, displayingthe
printable characters on each line, much like the defaultoutputofxxd.
7/26/2019 O'Reilly - Linux Pocket Guide
57/200
File Viewing | 49
Useful options
gv [options] file/usr/X11R6/bingv
stdin stdout - file -- opt --help --version
GhostView displays an Adobe Postscript or PDF file in anXwindow. You can invoke it as gvor ghostview. The basic opera-tionof the program is simple: click the desired page number to
jump to that page, and so forth. A few minutes of playingtimeand youll have the hang of it.
GhostView is the definitive Linux Postscript viewer, but otherfreePDF viewers include acroread(http://www.adobe.com/) andxpdf(http://www.foolabs.com/xpdf/).
-lN Display only the first Nbytes. (Default is to display theentire file)
-sN-s -N
Beginatapositionotherthanthefirstbyteofthefile.ThefirstformskipsthefirstNbytes. The second (-N) begins Nbytes from the end of the file.(Thereis also a +Nsyntax for more advanced skipping throughstandard input; seethe manpage.)
-cN Display Nbytes per row. (Default=16)
-gN GroupeachrowofbytesintosequencesofNbytes, separated bywhitespace,like od -s. (Default=2)
-b Display the output in binary instead of hexadecimal.
-u Display the output in uppercase hexadecimal instead oflowercase.
-p Display the output as a plain hexdump, 60 contiguous bytesper line.
-i Display the output as a C programming language datastructure. Whenreading from a file, it produces an array ofunsigned chars containing thedata, and an unsigned int containingthe array length. When reading fromstandard input, it produces onlya comma-separated list of hex bytes.
-rThe reverse operation: convert from an
xxdhex dump back into the originalfile format. Works with thedefault hexdump format and, if you add the -p
option, the plain hexdump format. If youre bored, try either ofthesecommands to convert and unconvert a file in a pipeline,reproducing theoriginal file on standard output:
$ xxd myfile | xxd -r$ xxd -p myfile | xxd -r -p
7/26/2019 O'Reilly - Linux Pocket Guide
58/200
50 | Linux Pocket Guide
Useful options
xdvi [options] file/usr/bin
tetex-xdvi
stdin stdout - file -- opt --help --version
The document processing system TeX produces binary outputfilesin a format called DVI, with suffix .dvi. The viewer xdvidisplays aDVI file in an X window. If you prefer, convert a DVIfile toPostscript via the dvipscommand and then use GhostView(gv) todisplay it:
$ dvips -o myfile.ps myfile.dvi$ gv myfile.ps
While displaying a file, xdvi has a column of buttons downtheright-hand side with obvious uses, such as Next to move to thenextpage. (You can hide the buttons by invoking xdviwith the-expertoption.) You can also navigate the file by keystroke.
-pageP Begin on page P. (Default=1)
-monochrome-grayscale-color
Use the given display mode.
-portrait-landscape-seascape-upsidedown
Choose the page orientation, which normallygvdeterminesautomatically.
-scaleN Set the scaling factor (i.e., the zoom) for the display.The integer Nmay
be positive (make the image larger) or negative(smaller).-watch-nowatch
Automatically reload the Postscript file (or dont) when itchanges.
Keystroke Meaning
q Quit.
n, Spacebar, Enter,Pagedown
Jumptonextpage.Precedeitwithanumber Ntojumpby Npages..
p, Backspace, Delete,Pageup
Jump to previous page. Precede it with a number Nto jumpbyNpages.
< Jump to first page.
> Jump to last page.
7/26/2019 O'Reilly - Linux Pocket Guide
59/200
File Creation and Editing | 51
xdvihas dozens of command-line options for tailoring itscolors,geometry, zoom, and overall behavior.
File Creation and Editing
To get far with Linux, you must become proficient with oneof itstext editors. The two major ones are emacs from theFree SoftwareFoundation, and vim, a successor to the Unixeditor vi. Teachingthese editors fully is beyond the scope of
this book, but both have online tutorials, and we list com-monoperations in Table 1. To edit a file, run either:
$ emacs myfile$ vim myfile
If myfile doesnt exist, it is created automatically. You canalsoquickly create an empty file (for later editing) using the
touchcommand (see File Properties on page 56):$ touchnewfile
or write data into a new file by redirecting the output ofaprogram (see Input/output redirection on page 26):
$ echo anything at all > newfile
^L Redisplay the page.
R Reread the DVI file, say, after youve modified it.
Press mouse buttons Magnify a rectangular region under the mousecursor.
emacs Text editor from Free Software Foundation
vim Text editor, extension of Unix vi
umask Set a default mode for new files and directories
soffice Office suite for editing Microsoft Word, Excel, andPowerPoint documents
abiword Edit Microsoft Word documentsgnumeric Edit Excelspreadsheets
Keystroke Meaning
7/26/2019 O'Reilly - Linux Pocket Guide
60/200
52 | Linux Pocket Guide
In case you share files with Microsoft Windows systems, wewillalso cover Linux programs that edit Microsoft Word,Excel, andPowerPoint documents.
Your Default Editor
Various Linux programs will run an editor when necessary,and bydefault the editor is vim. For example, your email pro-gram mayinvoke an editor to compose a new message, andlessinvokes an editorif you type v. But what if you dont
want vim to be your default editor? Set the environmentvari-ables VISUALand EDITORto your choice, for example:
$ EDITOR=emacs$ VISUAL=emacs$ export EDITOR VISUAL Optional
Both variables are necessary because different programscheck onevariable or the other. Set EDITOR and VISUAL in
your ~/.bash_profile startup file if you want your choicesmadepermanent. Any program can be made your defaulteditor as long as itaccepts a filename as an argument.
Regardless of how you set these variables, all systemadmin-istrators should know at least basic vim and emacs com-mandsin case a system tool suddenly runs an editor on a
critical file.
emacs [options] [files]/usr/bin
emacs
stdin stdout - file -- opt --help --version
emacs is an extremely powerful editing environment withmorecommands than you could possibly imagine, and acompleteprogramming language built in to define your ownediting
features. To invoke the emacstutorial, run:$ emacs
and type ^h t.
Most emacskeystroke commands involve the control key (like ^F)orthe metakey, which is usually the Escape key or the Altkey.emacssown documentation notates the meta key as M-(as inM-F
7/26/2019 O'Reilly - Linux Pocket Guide
61/200
File Creation and Editing | 53
to mean hold the meta key and type F) so we will too. Forbasickeystrokes, see Table 1.
vim [options] [files]/usr/bin
vim-enhanced
stdin stdout - file -- opt --help --version
vimis an enhanced version of the old standard Unix editorvi.Torun the vimtutorial, run:
$ vimtutor
vim is a mode-based editor. It operates in two modes,insertandnormal. Insert mode is for entering text in the usualmanner, while
normal mode is for running commands like delete a lineorcopy/paste. For basic keystrokes in normal mode, see Table 1.
Table 1. Basic keystrokes in emacs and vim
Task emacs vim
Run editor in current window $ emacs -nw[file] $ vim [file]
Run Editor in a new X window $ emacs[file] $ gvim [file]
Type text text itextESC
Save & quit ^x^sthen ^x^c :wq
Quit without saving ^x^cRespondnowhenaskedto save buffers
:q!
Save ^x^s :w
Save As ^x^w :wfilename
Undo ^_ u
Suspend editor (not in X) ^z ^z
Switch to edit mode (N/A) ESC
Switch to command mode M-x :
Abort command in progress ^g ESCMove forward ^f or right arrowlor right arrow
Move backward ^bor left arrow hor left arrow
Move up ^p or up arrow kor up arrow
Move down ^nor down arrow jor down arrow
Move to next word M-f w
7/26/2019 O'Reilly - Linux Pocket Guide
62/200
54 | Linux Pocket Guide
umask [options] [mask]shell built-in
bash
stdin stdout - file -- opt --help --version
The umaskcommand sets or prints your default mode forcreatingfiles and directories: whether they are readable, writable,and/orexecutable by yourself, your group, and the world. (SeeFileProtections on page 19, and the chmodcommand inFile Proper-tieson page 56,for more information.)
$ umask0002
Move to previous word M-b b
Mo
O'Reilly - Linux Pocket Guide - [PDF Document] (2024)
Top Articles
One-Pot Rustic Homemade German Goulash Recipe
19 Fermentation Recipes For Beginners
Marcus Cape West Cinema Ticket Price Information
Panaderia La Guadalupana Tulsa Ok
Latest Posts
Walnut & Blue Cheese Sourdough Bread Recipe - Strayed from the Table
49 Authentic Scottish Recipes You Should Try * The Homesteading Hippy
Article information
Author: Errol Quitzon
Last Updated:
Views: 5578
Rating: 4.9 / 5 (79 voted)
Reviews: 86% of readers found this page helpful
Author information
Name: Errol Quitzon
Birthday: 1993-04-02
Address: 70604 Haley Lane, Port Weldonside, TN 99233-0942
Phone: +9665282866296
Job: Product Retail Agent
Hobby: Computer programming, Horseback riding, Hooping, Dance, Ice skating, Backpacking, Rafting
Introduction: My name is Errol Quitzon, I am a fair, cute, fancy, clean, attractive, sparkling, kind person who loves writing and wants to share my knowledge and understanding with you.