the mighty osx terminal

33
OSXs Free Swiss Army Knife The Mighty OSX Terminal

Upload: thane-thomson

Post on 21-Mar-2017

106 views

Category:

Technology


0 download

TRANSCRIPT

OSX’s Free Swiss Army Knife

The Mighty OSX Terminal

OSX Roots

Source:https://en.wikipedia.org/wiki/OS_X#/media/File:Unix_timeline.en.svg

The File System

/

/Applications /Library /System /Users /Volumes

/bin /etc /dev /opt /usr

user1

user2

App1

App2

… …

File System Properties

Name-Theunique(case-sensitive)nameofafile/directory.

Size-Howmanybytes/kB/MB/GBdoesafiletakeup?

Permissions-Strictcontrolofwhocanaccesswhichfiles/directories,and

whattheycan/can’tdowiththosefiles.

Timestamps-Whenfileswerecreatedorlastmodified.

Owner-Whichuser“owns”thisfile?(forpermissions)

Group-Whichsystem“group”hasaccesstothisfile?(permissions)

File System Permissions

Owner/Group/OtherSystem

Permissionsapplyseparatelytotheowner,thegroup,andotherusers(those

whofalloutsideofbeingtheownerorpartofthegroup).

Read/Write/ExecutePermissions

Cantheownerread/write/executethefile?

Canthegroupread/write/executethefile?

Canotherusersread/write/executethefile?

(Executedoesn’tapplytodirectories)

Fire it Up

cmd ⌘ + Space

Terminal Window

Current Folder

Prompt

Pro Tip!

http://brew.sh

Quick Reference

Paths (1)

.

Thecurrentdirectory.

..

Theparentdirectory.

/

Therootdirectory.

Paths (2)

~

Referstothecurrentuser’shomefolder.

~/Documents

Thefoldercalled“Documents”withinthecurrentuser’shomefolder.

Paths (3)

*

“Wildcard”usedinapath.Usedalone,referstoallfilesandsubfoldersin

thecurrentfolder.

*.txt

Allfileswhosenamesendin“.txt”.

some_file*

Allfiles/folderswhosenamesstartwith“some_file”.

Relative Paths (1)

./some_file.txt

A“relative”path,relativetothecurrentfolder.

./subfolder/other/folder/some_other_file.txt

Amorecomplex“relative”path.

../some_file.txt

Afilecalled“some_file.txt”intheparentfolder.

Relative Paths (2)

../../some_file.txt

Afilecalled“some_file.txt”intheparentfolderofourcurrentparent

folder(two“levels”up).

Basic Navigation (1)

pwd

Printthefullpathofthecurrentworkingdirectory.(“Printworking

directory”)

ls

Listthecontentsofthecurrentdirectory.

cd/path/to/other/directory

Changethecurrentworkingdirectoryto“/path/to/other/directory”.

Basic Navigation (2)

ls-lh

Listthecontentsofthecurrentdirectory,butshowthecontentsasalist

andinahuman-friendliermannerthanusual.

ls/other/folder

Listthecontentsof“/other/folder”.

ls..

Listthecontentsofthecurrentfolder’sparentfolder.

Basic Navigation (3)

ls.

Exactlythesameasjustrunning“ls”.

ls/

Listthecontentsofthefilesystemrootdirectory.

ls-a

Listallfiles,includinghiddenfiles,inthecurrentdirectory.

File Contents (1)

catsome_file.txt

Willdisplaythecontentsof“some_file.txt”,fromthecurrentfolder,in

theterminal.

catsome_file.txt|less

“Pipes”theoutputfromthe“cat”commandthroughthe“less”program,

effectivelyallowingyoutoscrollthroughthecontentof“some_file.txt”.

File Contents (2)

catfile1.txtfile2.txt

Firstoutputsthecontentsof“file1.txt”,thenthecontentsof“file2.txt”,

totheterminal.

echo“Helloworld!”>hello.txt

Willwritethetext“Helloworld!”intothetextfilecalled“hello.txt”in

thecurrentdirectory.Ifthatfiledoesnotexist,itwillbecreated.If

itdoesexist,itsexistingcontentswillbereplaced.

File Contents (3)

catfile1.txtfile2.txt>file_concatenated.txt

Dumpstheconcatenatedcontentsof“file1.txt”,followedbythecontentsof

“file2.txt”,intoanotherfilecalled“file_concatenated.txt”.

File Contents (4)

grep“Hello”*.txt

Searchfortheexactstring“Hello”(case-sensitive)inallofthe.txt

filesinthecurrentfolder.

grep-i“hello”*.txt

Searchforthestring“hello”(case-insensitive)inallofthe.txtfilesin

thecurrentfolder.

File Contents (5)

grep-ir“hello”*

Searchrecursively(throughallofthesubfoldersinthecurrentfoldertoo)

throughallfiles(*)forthestring“hello”(case-insensitive).

File Copying

cpsome_file.txt/other/folder

Copiesthefile“some_file.txt”inourcurrentfolderintothefolderwhose

pathis“/other/folder”.

cp*.txt/other/folder

Copiesallofthefiles,fromthecurrentfolder,whosenameendsin“.txt”

into“/other/folder”.

Folder Copying

cp-R./mysubfolder/other/folder

Recursivelycopiesallofthecontentsof“mysubfolder”(afolderwithinour

currentfolder)intothedirectorycalled“/other/folder”,resultingina

newfolder“/other/folder/mysubfolder”whosecontentswillbethesameas

“./mysubfolder”.

Deleting Files

rmsome_file.txt

Removesthefileinthecurrentdirectorycalled“some_file.txt”.

rm./subfolder/some_file.txt

Removesthefilecalled“some_file.txt”withinthisfolder’ssub-folder

called“subfolder”.

Deleting Folders

WARNING!Becarefulwiththesecommands.

rm-rf./subfolder/

Removesallofthecontentsofthesubfoldercalled“subfolder”,andremoves

thefolderitselfaswell.

Executing Commands

./some_executable

Executestheapplicationcalled“some_executable”inthecurrentdirectory.

some_executable

Assumesthattheexecutablecalled“some_executable”isinyoursystem

“path”-awell-knownlocationtotheshell.

Historical Commands

history

Givesanumbered,chronologicallyorderedlistingofallofthecommandsyou

havepreviouslyexecuted.

!321

Whenlookingattheoutputfromthe“history”command,runningthisexecutes

commandnumber321fromthelist.

Additional Commands

clear

Clearsthecontentsoftheterminal(usuallyforreadabilitypurposes).

whichsome_executable

Tellsyouthepathwherethebestcandidatefor“some_executable”willbe.

mancommand_name

Showsthehelpmanualforthecommand“command_name”(replacewithpretty

muchanycommand).