Docsity

Command Line Basics: Directories, Files, and Environment Variables, Guías, Proyectos, Investigaciones de Programación de Red

Toggle sidebar
bg1
COMMAND LINE CRASH COURSE
1 | P a g e
The Command Line Crash Course:
http://cli.learncodethehardway.org/book/
1. Table Of Contents
2. Preface
3. Introduction: Shut Up And Shell
4. The Setup
5. Paths, Folders, Directories (pwd)
6. What's Your Computer's Name? (hostname)
7. Make A Directory (mkdir)
8. Change Directory (cd)
9. List Directory (ls)
10. Remove Directory (rmdir)
11. Moving Around (pushd, popd)
12. Making Empty Files (Touch, New-Item)
13. Copy A File (cp)
14. Moving A File (mv)
15. View A File (less, MORE)
16. Stream A File (cat)
17. Removing A File (rm)
18. Pipes And Redirection
19. Wildcard Matching
20. Finding Files (find, DIR -R)
21. Looking Inside Files (grep, select-string)
22. Getting Command Help (man, HELP)
23. Finding Help (apropos, HELP)
24. What's In Your Environment (env, echo, Env:)
25. Changing Environment Variables (export, Env:)
26. Exiting Your Terminal (exit)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b

Vista previa parcial del texto

¡Descarga Command Line Basics: Directories, Files, and Environment Variables y más Guías, Proyectos, Investigaciones en PDF de Programación de Red solo en Docsity!

The Command Line Crash Course: http://cli.learncodethehardway.org/book/

  1. Table Of Contents
  2. Preface
  3. Introduction: Shut Up And Shell
  4. The Setup
  5. Paths, Folders, Directories (pwd)
  6. What's Your Computer's Name? (hostname)
  7. Make A Directory (mkdir)
  8. Change Directory (cd)
  9. List Directory (ls)
  10. Remove Directory (rmdir)
  11. Moving Around (pushd, popd)
  12. Making Empty Files (Touch, New-Item)
  13. Copy A File (cp)
  14. Moving A File (mv)
  15. View A File (less, MORE)
  16. Stream A File (cat)
  17. Removing A File (rm)
  18. Pipes And Redirection
  19. Wildcard Matching
  20. Finding Files (find, DIR -R)
  21. Looking Inside Files (grep, select-string)
  22. Getting Command Help (man, HELP)
  23. Finding Help (apropos, HELP)
  24. What's In Your Environment (env, echo, Env:)
  25. Changing Environment Variables (export, Env:)
  26. Exiting Your Terminal (exit)

Preface I wrote this book really quickly as a way to bootstrap students for my other books. Many students don't know how to use the basics of the command line interface, and it was getting in the way of their learning. This book is designed to be something they can complete in about a day to a week and then get enough skill at the command line to graduate to other books.

This book isn't a book about master wizardry system administration. It's just a quick introduction to get newbies going

Introduction: Shut Up And Shell This book is a crash course in using the command line to make your computer perform tasks. As a crash course, it's not as detailed or extensive as my other books. It is simply designed to get you barely capable enough to start using your computer like a real programmer does. When you're done with this book, you will be able to give most of the basic commands that every shell user touches every day. You'll understand the basics of directories and a few other concepts.

The only piece of advice I am going to give you is this:

Shut up and type all of this in. Sorry to be mean, but that's what you have to do. If you have an irrational fear of the command line, the only way to conquer an irrational fear is to just shut up and fight through it.

You are not going to destroy your computer. You are not going to be thrown into some jail at the bottom of Microsoft's Redmond campus. Your friends won't laugh at you for being a nerd. Simply ignore any stupid weird reasons you have for fearing the command line.

Why? Because if you want to learn to code, then you must learn this. Programming languages are advanced ways to control your computer with language. The command line is the baby little brother of programming languages. Learning the command line teaches you to control the computer

Every day for about 15-30 minutes, drill yourself on the index cards, trying to recall each one. Put any cards you don't get right into a different pile, just drill those cards until you get bored, then try the whole deck and see if you improve. Before you go to bed, drill just the cards you got wrong for about 5 minutes, then go to sleep. There's other techniques, like you can write what you need to learn on a sheet of paper, laminate it, then stick it to the wall of your shower. While you're bathing drill the knowledge without looking, and when you get stuck glance at it to refresh your memory.

If you do this every day, you should be able to memorize most things I tell you to memorize in about a week to a month. Once you do, nearly everything else becomes easier and intuitive, which is the purpose of memorization. It's not to teach you abstract concepts, but rather to ingrain the basics so that they are intuitive and you don't have to think about them. Once you've memorized these basics they stop being speed bumps preventing you from learning more advanced abstract concepts.

License I (Zed A. Shaw) own the copyright on this book. You are free to give it to anyone you want, as long as you don't modify it and you don't make any money from the distribution of the book.

Thanks Thanks to Lauren Buchsbaum for editing this book and providing me with feedback. Also thanks to the many students who read the book and provided feedback.

The Setup In this book you will be instructed to do three things:

Do some things in your shell (command line, Terminal, PowerShell).

Learn about what you just did.

Do more on your own.

For this first exercise you'll be expected to get your Terminal open and working so that you can do the rest of the book.

Do This Get your terminal, shell, PowerShell working so you can access it quickly and know that it works.

Mac OSX For Mac OSX you'll need to do this:

Hold down COMMAND and hit the spacebar. In the top right the blue "search bar" will pop up. Type: terminal Click on the Terminal application that looks kind of like a black box. This will open Terminal. You can now go to your Dock and CTRL-click to pull up the menu, then select Options->Keep In Dock. Now you have your Terminal open and it's in your Dock so you can get to it.

Linux I'm assuming that if you have Linux then you already know how to get at your terminal. Look through the menu for your window manager for anything named "Shell" or "Terminal".

book by doing some memorization. Just trust me, this will make things silky smooth later on.

Linux/Mac OSX Take this list of commands and create index cards with the names on the left on one side, and the definitions on the other side. Drill them every day while you do this book for just 15 minutes or so.

pwd print working directory hostname my computer's network name mkdir make directory cd change directory ls list directory rmdir remove directory pushd push directory popd pop directory cp copy a file or directory mv move a file or directory less page through a file cat print the whole file xargs

execute arguments find find files grep find things inside files man read a manual page apropos find what man page is appropriate env look at your environment echo print some arguments export export/set a new environment variable exit exit the shell sudo DANGER! become super user root DANGER! chmod change permission modifiers chown change ownership

Windows If you're using Windows then here's your list of commands: pwd print working directory hostname my computer's network name mkdir make directory cd change directory ls list directory rmdir remove directory pushd push directory popd pop directory cp copy a file or directory robocopy robust copy mv move a file or directory more page through a file type

print the whole file forfiles run a command on lots of files dir -r find files select-string find things inside files help read a manual page helpctr find what man page is appropriate echo print some arguments set export/set a new environment variable exit exit the shell runas DANGER! become super user root DANGER! attrib change permission modifiers iCACLS change ownership

Drill, drill, drill! Drill until you can say these phrases right away when you see that word. Then drill the inverse, so that you read the phrase and know what command will do that. You're building your vocabulary by doing this, but don't spend so much time you go nuts and get bored.

Make A Directory (mkdir) Do This $ mkdir temp $ mkdir temp/stuff $ mkdir temp/stuff/things $ mkdir -p temp/stuff/things/frank/joe/alex/john $

mkdir temp

Directory: C:\Users\zed

Mode LastWriteTime Length Name


d---- 12/17/2011 9:02 AM temp

mkdir temp/stuff

Directory: C:\Users\zed\temp

Mode LastWriteTime Length Name


d---- 12/17/2011 9:02 AM stuff

mkdir temp/stuff/things

Directory: C:\Users\zed\temp\stuff

Mode LastWriteTime Length Name


d---- 12/17/2011 9:03 AM things

mkdir temp/stuff/things/frank/joe/alex/john

Directory: C:\Users\zed\temp\stuff\things\frank\joe\alex

Mode LastWriteTime Length Name


d---- 12/17/2011 9:03 AM john

You Learned This Now we get into typing more than one command. These are all the different ways you can run mkdir. What's mkdir do? It make directories. Why are you asking that? You should be doing your index cards and getting your commands memorized. If you don't know that "mkdir makes directories" then keep working the index cards.

What does it mean to make a directory? You might call directories "folders." They're the same thing. All you did above is create directories inside directories inside of more directories. This is called a "path" and it's a way of saying "first temp, then stuff, then things and that's where I want it." It's a set of directions to the computer of where you want to put something in the tree of folders (directories) that make up your computer's hard disk.

Note In this book I'm using the / (slash) character for all paths since they work the same on all computers now. However, Windows users will need to know that you can also use the \ (backslash) characters and other Windows users will typically expect those at times.

Do More The concept of a "path" might confuse you at this point. Don't worry. We'll do a lot more with them and then you'll get it. Make 20 other directories inside the temp directory in various levels. Go look at them with a graphical file browser. Make a directory with a space in the name by putting quotes around it: mkdir "I Have Fun" If the temp directory already exists then you'll get an error. Use cd to change to a work directory that you can control and try it there. On windows Desktop is a good place.

Remember that from now on I'll only have the > to tell you that's the prompt.

I'm doing the same thing for the Unix prompts, but Unix prompts are so varied that most people get used to $ meaning "just the prompt".

You Learned This

Your prompt will look different from mine. You may have your user name before the $ and the name of your computer. On Windows it will probably look different too. The key is that you see the pattern of:

There's a prompt.

You type a command there. In this case, it's pwd.

It printed something.

Repeat.

You just learned what pwd does, which means "print working directory." What's a directory? It's a folder. Folder and directory are the same thing, and they're used interchangeably. When you open your file browser on your computer to graphically find files, you are walking through folders. Those folders are the exact same things as these "directories" we're going to work with.

Do More

Type pwd 20 times and each time say "print working directory."

Type pwd 20 times and each time say "print working directory."

Write down the path that this command gives you. Find it with your graphical file browser of choice.

No, seriously, type it 20 times and say it out loud. Sssh. Just do it.

What's Your Computer's Name? (hostname)

Do This

$ hostname

Zeds-MacBook-Pro.local

$

hostname

zed-PC

You Learned This

This is the name of your computer, or at least one of its names. Your name will probably be different than mine, and it could be just about anything.

Do More

Just like the last exercise, type this command 20 times and say it out loud.

mkdir temp/stuff/things/frank/joe/alex/john

Directory: C:\Users\zed\temp\stuff\things\frank\joe\alex

Mode LastWriteTime Length Name


d---- 12/17/2011 9:03 AM john

You Learned This

Now we get into typing more than one command. These are all the different ways you can run mkdir. What's mkdir do? It make directories. Why are you asking that? You should be doing your index cards and getting your commands memorized. If you don't know that "mkdir makes directories" then keep working the index cards.

What does it mean to make a directory? You might call directories "folders." They're the same thing. All you did above is create directories inside directories inside of more directories. This is called a "path" and it's a way of saying "first temp, then stuff, then things and that's where I want it." It's a set of directions to the computer of where you want to put something in the tree of folders (directories) that make up your computer's hard disk.

Note

In this book I'm using the / (slash) character for all paths since they work the same on all computers now. However, Windows users will need to know that you can also use the \ (backslash) characters and other Windows users will typically expect those at times.

Do More

 The concept of a "path" might confuse you at this point. Don't worry. We'll do a lot more with them and then you'll get it.  Make 20 other directories inside the temp directory in various levels. Go look at them with a graphical file browser.

 Make a directory with a space in the name by putting quotes around it: mkdir "I Have Fun"  If the temp directory already exists then you'll get an error. Use cd to change to a work directory that you can control and try it there. On windows Desktop is a good place.

$ pwd

~/temp/stuff/things/frank/joe/alex

$ cd john/

$ pwd

~/temp/stuff/things/frank/joe/alex/john

$ cd ..

$ cd ..

$ pwd

~/temp/stuff/things/frank/joe

$ cd ..

$ cd ..

$ pwd

~/temp/stuff/things

$ cd ../../..

$ pwd

~/

$ cd temp/stuff/things/frank/joe/alex/john

$ pwd

~/temp/stuff/things/frank/joe/alex/john

$ cd ../../../../../../../

$ pwd

~/

$

cd temp

pwd

Path


C:\Users\zed\temp

cd stuff

pwd

Path


C:\Users\zed\temp\stuff

cd things

pwd

Path


C:\Users\zed\temp\stuff\things

cd frank

pwd

Path


C:\Users\zed\temp\stuff\things\frank

cd joe

pwd