Mac Unix Command Basics for Beginners

These are useful unix commands that are entered through a Terminal shell prompt. These commands are actually names of Unix programs that usually sit in a folder called /bin

where am i? pwd

How to check the current directory $ pwd

learn more about anything – man

How to bring up the manual page for a command: $ man ls or $ man pwd

go somewhere –  cd

How to go to user root:  simply $ cd

How to go to root: $ cd ~ or $ cd /

list things ls

How to list files: $ ls

How to list files, one per line: $ ls -a1 (thats a one)

How to list hidden files also: $ ls -a

How to list only hidden files: $ ls -d .?*

How to list files in some other directory: $ ls /path/to/directory

reading a file cat

How to read a file to terminal: $ cat filename

copy things cp

How to copy a file: $ cp target_file copied_file

How to copy a directory: $ cp -R original_directory copied_directory

How to copy a directory contents into the current directory

$ cp -R original_directory/ .

remove/delete things rm

*** WARNING this bypasses the Trash bin and things cannot be undeleted ***

How to delete a file: $ rm target_file

How to carefully delete a directory: $ rm -r target_directory

How to FORCE delete a directory: $ rm -rf target_directory

open chrome (open)

open /Applications/Google\ Chrome.app/

open /Applications/<Tab><Tab> (to get a list of available options)

abort the current command (Ctrl – C)

delete the everything to the left of the cursor (Ctrl – U)

Basics Plus: bonus section

open files with open

Do you ever download PDFs on Chrome and the browser insists on opening the pdf IN BROWSER?

copy the url path file://path/to/pdf and simply run open on it

$ open file://path/to/pdf

run multiple commands ;

How to clear the screen, print the current working directory, print the date, print the weather from “wttr.in”

clear;pwd;date;curl wttr.in?0

pipe stdout to stdin |

How to pipe the contents of a file (“my_file.txt”) to your system clipboard

cat my_file.txt | pbcopy

pipe stdout ot stdin |

How to pipe the result of ls to vim

ls -1 | vim -

multiline commands \

rm -rf \

that/super/long/path/to_a_directory

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s