CMD BASICS.pdf

5
David Baumgold: web developer, open source hacker, and code monkey. Getting to Know the Command Line  This tutorial is for beginner u sers who want to learn th e basics of how to use th e command line.  What Is the Command Line? Finding the Command Line Command Syntax Basic tilities !o"ing #round the Com$uter %eat Tric&s  Warnings 'ere(s another basic command line tutorial  with more information) if you(d li&e to learn more.  What Is the Command Li ne?  The command line is the u ltimate seat of $ower on you r com$uter. sing the comman d line) you can $erform ama*ing fe ats of wi*ardry and s$eed) taming your com$uter and getting it to do precisely  what you want. nfortunately) the $rice of this $ower is com$lexity+ nobody e"er said that ruling your com$uter would be easy.  The command line is) at its he art) sim$ly a $lace where you ty$ e commands to the com$uter. The com$uter is your obedient ser"ant) and will attem$t to carry out any command that it understands. nfortunately) the com$uter does not s$ea& ,nglish) or any other language s$o&en by humans -although it has recogni*able elements. In order to gi"e it commands) we must firs t start learning the language of the com$uter. NOTE: The command line) as with all $ower) has its ris&s. /ou ha"e the ca$ability to instruct the com$uter to do anything it has the ca$ability of doing. If you instruct the com$uter to erase all of your data) it will cheerfully $roceed to do so. Do not run a command just to see what it does.  !a&e sure you understand what the c ommand is su$$osed to do first) es$ecially if the command in"ol"es changing or remo"ing files. Finding the Command Line !ost $eo$le don(t use the command line on a regular basis) so it can be a bit difficult to find the first time. The Windows o$erating system doesn(t e"en have  a $ro$er command line built in 00 to execute these commands) you will ha"e to install one. Mac OS X: The !ac command line is a $rogram called Terminal. It li"es in the /Applications/Utilities/ folder. To find it) go to your #$$lications folder. %ear the bottom) there is a folder called tilities. 1o inside) and one of t he a$$lications listed is called Terminal. 2ouble0clic& that a$$lication to o$en it.  About Resume Portfolio utorials Página 1 de 5 Getting to Know the Command Line 01/04/2014 http://www.davidbaumgold.om/tuto!ial"/ommand#line/

Transcript of CMD BASICS.pdf

Page 1: CMD BASICS.pdf

8/11/2019 CMD BASICS.pdf

http://slidepdf.com/reader/full/cmd-basicspdf 1/5

David Baumgold: web developer, open source hacker, and code monkey.

Getting to Know the Command Line This tutorial is for beginner users who want to learn the basics of how to use the command

line.

 What Is the Command Line?

Finding the Command Line

Command Syntax

Basic tilities

!o"ing #round the Com$uter

%eat Tric&s

 Warnings

'ere(s another basic command line tutorial with more information) if you(d li&e to learn

more.

 What Is the Command Line? The command line is the ultimate seat of $ower on your com$uter. sing the command

line) you can $erform ama*ing feats of wi*ardry and s$eed) taming your com$uter and

getting it to do precisely  what you want. nfortunately) the $rice of this $ower is com$lexity+

nobody e"er said that ruling your com$uter would be easy. The command line is) at its heart) sim$ly a $lace where you ty$e commands to the

com$uter. The com$uter is your obedient ser"ant) and will attem$t to carry out any

command that it understands. nfortunately) the com$uter does not s$ea& ,nglish) or any

other language s$o&en by humans -although it has recogni*able elements. In order to gi"e

it commands) we must first start learning the language of the com$uter.

NOTE: The command line) as with all $ower) has its ris&s. /ou ha"e the ca$ability to

instruct the com$uter to do anything it has the ca$ability of doing. If you instruct the

com$uter to erase all of your data) it will cheerfully $roceed to do so. Do not run a

command just to see what it does. !a&e sure you understand what the command is

su$$osed to do first) es$ecially if the command in"ol"es changing or remo"ing files.

Finding the Command Line!ost $eo$le don(t use the command line on a regular basis) so it can be a bit difficult to

find the first time. The Windows o$erating system doesn(t e"en have  a $ro$er command line

built in 00 to execute these commands) you will ha"e to install one.

Mac OS X: The !ac command line is a $rogram called Terminal. It li"es in

the /Applications/Utilities/ folder. To find it) go to your #$$lications folder.

%ear the bottom) there is a folder called tilities. 1o inside) and one of the a$$lications

listed is called Terminal. 2ouble0clic& that a$$lication to o$en it.

 About Resume Portfolio utorials

Página 1 de 5Getting to Know the Command Line

01/04/2014http://www.davidbaumgold.om/tuto!ial"/ommand#line/

Page 2: CMD BASICS.pdf

8/11/2019 CMD BASICS.pdf

http://slidepdf.com/reader/full/cmd-basicspdf 2/5

Linux: The location of the command line de$ends on whether you are using the 1nome or

32, window manager. -If there is a big 3 icon on the bottom left of the screen) you are

using 32,4 if not) you are using 1nome. If you are using 32,) clic& the 3 button) select

System) and clic& on 3onsole. If you are using 1nome) clic& the #$$lications button at the

to$ left) select System Tools) and clic& on Terminal.

Windows: nfortunately) you will ha"e to install your own command line $rogram.

 Windows comes with a command line) but it is non0standard and more difficult to use.

Cygwin is a free) easy to install command line $rogram. Sim$ly download the Cygwin

installer) double0clic& it to install Cygwin) and then mo"e the installer to the recycle bin. To

use Cygwin) go to the Start menu) select 5rograms) and clic& on Cygwin.

Command Syntax %obody li&es grammar) so let(s get this o"er with 6uic&ly. #ll commands ha"e three $arts+

the utility) the flags) and the arguments. The utility always comes first. The other two $arts

ha"e different rules) de$ending on which command you are using+ you may not ha"e to useany flags or arguments at all.

'ere is a sam$le command that you might ty$e into a command line+

$ ls -l ~/Desktop

Let(s brea& this command down into $arts+

$ is a symbol commonly used to indicate the command line. It sim$ly means that the rest

of the line is a command) rather than a sentence. When you are ty$ing a command into

the command line) you do not ty$e in the $ because it is sim$ly an indication to the

reader) rather than $art of the command itself. In other words) if you see a commandthat starts with a dollar sign) don(t ty$e the dollar sign into the command line.

ls is a utility. tilities are also sometimes &nown as commands all on their own)

because they indicate the general idea of what you want. !ost of the time) you can

sim$ly run a utility all by itself) without any flags or arguments. !ost commands only

ha"e one utility.

-l is a la! that alters how the utility o$erates. Flags are li&e o$tions or $references+ the

utility will usually wor& $erfectly well with the defaults) but sometimes) you want to

modify how it wor&s slightly. Flags always start with either one or two dashes - - ) and

they usually come between the utility and the arguments.

~/Desktop is an ar!ument to the utility. #rguments are used when the utility needsto &now exactly what you want for a certain action) and there is no clear default setting.

 /ou can thin& of it more li&e a con"ersation than an argument+ The utility says 7I don(t

&now how I should do this87) and you use an argument to say) 7'ere) this is how you

should do it.7 #rguments usually come at the end of the command) after the utility and

the flags -if any flags are used. The number of arguments used generally de$ends on the

utility+ some don(t need any arguments) some re6uire exactly one argument) some re6uire

lots of arguments) and some are flexible in the number of arguments they can ta&e.

 This command uses the ls utility) which is used to list the contents of directories. We use

the -l flag to indicate to the utility that we want more information than it usually $ro"ides)

and so it should show us the directory contents in a long format - -l is short for 7long7.

Last) the utility wants to &now) 7But which directory should I list the contents of?7 sing

the argument) we re$ly) 7Show me the contents of my 2es&to$.7

Página 2 de 5Getting to Know the Command Line

01/04/2014http://www.davidbaumgold.om/tuto!ial"/ommand#line/

Page 3: CMD BASICS.pdf

8/11/2019 CMD BASICS.pdf

http://slidepdf.com/reader/full/cmd-basicspdf 3/5

In all cases) to submit a command to the com$uter) $ress enter. %ow) let(s start learning

some useful commands8

Basic Utilities

'ere is a list of basic utilities that you will use on a regular basis. #nything in ca$ital lettersthat starts with a dollar sign) li&e $THIS) is an argument to the utility. /ou should re$lace

$THIS with the actual argument you want to gi"e the com$uter.

man $UTIL

manual. 1et information for how to use any utility. 9e$lace $UTIL with any utility) li&e

ls) cd) or e"en man8 5ress the u$ and down arrows to scroll through the

documentation. 5ress : to 6uit and go bac& to the command line.

ls $DIR

list. Lists the contents of the directory $DIR. If no directory is s$ecified) lists the

contents of the current wor&ing directory. se the -l flag to get more information.

cd $DIRchange directory. Changes the current wor&ing directory to the directory $DIR. In

effect) mo"es you around the com$uter.

pwd

 "rint w or&ing directory. If you e"er get lost in the com$uter) run this command to get a

trail of breadcrumbs all the way down from the to$ le"el of the com$uter to see where

you are.

less $FILE

2is$lays the contents of a file. 5ress the u$ and down arrows to scroll though the file.

5ress : to 6uit and go bac& to the command line.

cp $FILE $LOATIO!co "y. Co$ies the $FILE to the $LOATIO!.

m" $FILE $LOATIO!

mo # e. !o"es the $FILE to the $LOATIO!.

#m $FILE

remo"e. 2eletes a file "ermanently+ there is no way to get it bac&. Be careful when using

this command8

sdo $%D

su$er user do. When you use this utility) you use an entire command as a single

argument+ for exam$le) $ sdo ls -l ~/Desktop. sdo as&s for your user

account $assword. #s a security measure) the screen does not dis$lay anything as youty$e) not e"en asteris&s - & . If the $assword is ty$ed in correctly) sdo executes the

$%D with ele"ated $ermissions. Be careful when using this command8

 # note about using sdo+ The com$uter has a few built0in safety restraints to $re"ent

normal users from doing bad things) li&e deleting critical files. The su$er user has no such

restraints. %ote that the su$er user is not necessarily bad+ you must use sdo to install

$rograms and do anything else that affects how your com$uter runs.

Moving Ao!nd the Com"!teLets start by using ls to loo& around your com$uter. Try ty$ing ls into the command line

and $ressing enter. The com$uter will re$ly with a list of names. These names are the

Página $ de 5Getting to Know the Command Line

01/04/2014http://www.davidbaumgold.om/tuto!ial"/ommand#line/

Page 4: CMD BASICS.pdf

8/11/2019 CMD BASICS.pdf

http://slidepdf.com/reader/full/cmd-basicspdf 4/5

names of files and folders in the directory you are currently in. Whene"er you o$en u$ a

new command line) you start in your home directory) which is the directory that generally

contains all of your files.

 Well) that(s nice. But what if we want to go some$lace else? That(s what cd is for. cd

re6uires an argument+ if you tell the com$uter you want to go somewhere) you also ha"e to

tell it where you are going. Try entering this command+

$ cd Docments

9emember) do not ty$e in the $ at the beginning) and $ress enter once you ha"e finished

ty$ing. The com$uter will not re$ly) but you are now sitting in your 2ocuments directory.

 /ou can test this by running ls again+ the list of names will be different.

So where do we go from here? 'ow do we &now which of these names are folders -that we

can go into and which are files -that we can(t? For that) we need more information from

the ls command. Let(s gi"e it the -F flag to tell us about  iles and  olders. Try entering this

command+

$ ls -F

 /ou will notice that this time) some of the names that the com$uter returns to you will ha"e

a slash after them. These names are folders+ the rest are files. /ou can always cd into a

folder by running cd with the folder name as an argument) as long as you can see that

folder with ls -F.

 When you(re done loo&ing in folders) it(s time to go bac& u$. But how? Luc&ily) e"ery folder

contains a hidden lin& bac& u$. To see these hidden lin&s) we will use the -a flag for ls to

see all. There are at least two hidden lin&s in e"ery folder. The ' -one $eriod lin& ta&es you

bac& to the same folder you are currently in ; it doesn(t ta&e you anywhere. The '' -two$eriods lin& ta&es you bac& u$ to the $arent folder. In fact) you can gi"e the ls command

multi$le flags) li&e so+

$ ls -aF

If you run this command) you will notice that the ' and '' hidden lin&s ha"e slashes next

to them) which means you can use them with cd8 To go bac& u$ a folder) you can always

run+

$ cd ''

9emember that if you e"er get lost in the com$uter) you can run pwd to see where you are.

#eat $ic%sCom$uter $rogrammers are la*y. Because they are la*y) they in"ented some techni6ues to

do more with less wor&. 'ere are some of those techni6ues+

Ta$ %utocom"letion: Whene"er you need to ty$e out a location in an argument -for

exam$le) in the cd command) you don(t ha"e to ty$e out the whole thing+ the first few

letters will do. <nce you("e ty$ed three or four letters) $ress the tab &ey) and the commandline will fill in the rest for you8 For exam$le) if you are in your home directory) and you ty$e

cd Desk and then $ress the tab &ey) the command line will automatically com$lete the

Página 4 de 5Getting to Know the Command Line

01/04/2014http://www.davidbaumgold.om/tuto!ial"/ommand#line/

Page 5: CMD BASICS.pdf

8/11/2019 CMD BASICS.pdf

http://slidepdf.com/reader/full/cmd-basicspdf 5/5

command to read cd Desktop8 /ou can also use this if you find yourself misty$ing

folder names+ tab autocom$letion will always fill it in correctly.

Shortcuts: The command line has a few shortcuts built in. For exam$le) to see your

$re"iously ty$ed command) =ust $ress the u$ button. /ou can do this to submit the same

command multi$le times) or to edit a command that you didn(t ty$e in 6uite right. #nother

shortcut+ you can use ~ -tilde to refer to your home directory+ cd ~ will ta&e you bac&

there.

 Wanings9emember) when you use the command line) the com$uter will cheerfully do anything it

can for you. If you as& it to do something bad) it will try to do so. Some $eo$le ta&e

ad"antage of this fact by telling no"ice command line users to run commands that do nasty

things to your com$uter. 'ere are a few to watch out for. Ne#er run any o these

commands& They can and will destroy your com"uter&

$ sdo #m -#( /

 The command to remo"e a file is #m. /ou can also use #m to remo"e multi$le files at a

time. This command tells the com$uter to start at the to$ of the file structure) and delete

every single file on the computer  without sto$$ing. #fter this command has run) your

com$uter be em$ty. If you turn it off) it will not be able to turn bac& on until you

reinstall an o$erating system on it.

$ )*+, )). 0)

 This interesting0loo&ing $iece of code is called a for& bomb. Li&e a "irus) it will

continually multi$ly and subdi"ide itself) as&ing for more and more resources from the

com$uter) until the entire com$uter is trying to $rocess this code. #s a result) the

com$uter has no resources left for any other $rograms or $rocesses) and will free*e orcrash. Fortunately) rebooting your com$uter should cure it.

ResumeCli% an ion below to download m& !e"ume.

Contact Me!Compute!" a!e nie' but "ometime" ( need "ome "oial inte!ation' too. Ca!e to d!op me a line)

Página 5 de 5Getting to Know the Command Line

01/04/2014h // d idb ld / i l / d li /