Thursday, October 4, 2012

Getting to know your Linux Shell (Bash) in 1200 seconds or less

20 Second Guide...

My shell waits for me to make a command. It looks something like this:

steve@sheebs:~$

The user steve is logged in to the computer named sheebs and the user is at his home directory (~) and everything after $ will be executed as a single command.

40 Second Guide...(commands you should try)

steve@sheebs:~$ cd /

This brings you to the root of the file tree. In order words, you are now sitting at the top most level of your hard drive (or more accurately, the top level where your operating system is installed ). In windows this would be like being in the folder C:\

To go back to our home folder quickly:

steve@sheebs:/$ cd ~

To go back to our home folder less quickly

steve@sheebs:/$ cd /home/steve

*Usually, the name of your home folder will be your user name. My user name is steve and my home folder is called steve.

A few tricks

Ctrl + Shift + C = Copying in the shell
Crl + Shift + V = Pasting in the shell

Listing all the files and folders in your current directory

steve@sheebs:/$ ls

*ls stands for list, so it would be the letter l, not the number.

Listing all the files and folders in your current directory with tricks (or "Options")

steve@sheebs:/$ ls -ah

Everything after the dash - is an option. Here I am asking for:

  • -a all files (even .hidden files)
  • h human readable


* hidden files always start with a period:    .This_Would_be_a_hidden_file
*Human readable in this context means the program will format the output with a little care in mind.

How do I learn more tricks man?

GNU/Linux comes with an amazing industrial strength built-in manual. Sometimes the manual is a little too industrial strength.

steve@sheebs:/$ man ls

Use the home and end keys to go to the top or bottom of the manual. You can also use the arrows, spacebar and pageup and pagedown keys to navigate.

Hit the key q to quit or press Ctrl + z


1200 Second guide...

Follow this command line guide at Media Temple. Even though it's for SSH "Secure Shell", it's one of the best introductory guides I have come across.

Final Tips

Think of the shell as a file exploring ship. You can start by flying around the file tree. You can only see (read, write and execute) the files and folders of the folder you are currently in.

My last tip - if you are trying to cd into a new directory, type the first few letters of the directory and hit tab and watch the magic!

No comments:

Post a Comment