Introduction to Command Line

From DevSummit
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Command Line Session ---

Actions that you can take that are textual

Script -run this to keep a record of your journey -do commands -when don't type "exit" -to see record type "cat typescript"

where are we? -the location is the "working directory" -pwd (print working directory) -rm stands for remove and deletes a file

Command line is also a programming language -best name is the Bourne shell -the updated version was the GNU bourne shell or "bourne again shell" -BASH -people talk about bash prompts, bash scripting -also known as shell scripting -you create a script which is just a document of a set of commands -you can then call up that script to run it again

Command line is a good way to do the same thing to a large number of files

Shell -think of the scripting language as a shell -so there is a shell that protects the kernel -the kernel enforces the rules of who is allowed to read what file and what programs run when -the shell was the part that talks to the user -sometimes the "shell" is whatever you're using to get the unix line to do something

The Prompt -the text before where you type in your command

~ means home directory

cd means change directory /tmp is a directory that exists for temporary files

You usually have a command (e.g. cd) and an argument (e.g. /tmp)

The directory -like an upside down tree -the root directory is on the top

.. means the parent directory

How to go to the root

/ is the root -to go to the root: cd /

find . -type d -print -show all the directories from the root

control + c stops the command

language structure: -verb + adverb + noun(s) -command is the verb -adverb is "in what way" -adverbs and nouns collectively are called arguments -adverbs are called options

rm foo bar -delete the file foo and delete the file bar

you can type man for any command and it will show you the options for any command -in "grotesque" detail -e.g. man rm shows the manual for the rm command

q will quit out of the man because it's a "pager" program that allows you to scroll through the command line

commands are meant to work together -many designed to work with text files

cd will take you to your home directory if you don't specify a path or directory

How to create a new directory -we use the command mkdir -then say what we want to call it -e.g. mkdir cats dogs frogs -makes three folders

how to get into a folder? -cd cats

to create a directory with a space in the name you put quotes around it -e.g. mkdir "tabby cats"

ls will tell you what is the in the directories

echo meow puts the text you type in

echo meow > felix -save "meow" into the file Felix

cat shows you what's in the file

cp makes copies of files -you say where do you want to copy from and where do you want to copy to -cp felix ../less-cute/garfield

send the output of a command to a file with > -e.g. cat garfield garfield > large-cat -sends the output of cat garfield garfield to a file called large-cat -now we have a script called large-cat

echo echo hello > greeting.sh -put echo hello into the file greeting.sh

>> means append to

sh means run -e.g. sh greeting.sh

mv means move -e.g. mv ./less-cute/garfield . -move the file garfield, located in less-cute in the home directory to the home directory (.)

wc means word count -e.g. wc -w means how many words there are in the output (user types after command) -e.g. wc -l means how many lines are there