22.02.2017 Views

-ORIENTED

MagPi54

MagPi54

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

COMMAND LINE<br />

Tutorial<br />

nter pwd again and you’re back in the home folder.<br />

ow try it using an absolute path. nter<br />

cd /<br />

and youll be in the root directory. nter ls to view<br />

the folders at the base of your hard drive. nter<br />

cd /home/pi<br />

…to move back to your home folder. There’s a<br />

shortcut for this:<br />

cd ~<br />

The tilde (~) character is a shortcut for your home<br />

folder. You can use it at the start of an absolute<br />

directory too. For instance, entering:<br />

> Owner: Typically this will be the person who created<br />

the account.<br />

> Group: This is a group of users. You have only one<br />

group, pi, by default, containing just one<br />

user (also pi).<br />

> Other: These are users from other systems.<br />

ach of the three groups contains letters rw. hese<br />

letters are always in that order and each is either the<br />

letter or a hyphen. A letter indicates that the person,<br />

group, or other has access to read, write, or execute the<br />

file. hyphen means they dont have that level of access.<br />

Some examples include:<br />

> rwx read, write, and execute<br />

> rw- read, write, but don’t execute<br />

> r-x read and execute<br />

> r-- read only<br />

cd ~/Downloads<br />

…moves to your Downloads folder no matter where<br />

you are in the system.<br />

Files<br />

hroughout the file system, youll find various types<br />

of files. good selection is in the python_games<br />

folder, so enter:<br />

cd ~/python_games<br />

ls -l<br />

Now that you’ve discovered how to move around the<br />

file system from the command line, its time to learn<br />

what else you can do.<br />

Take command<br />

ne of the first commands you need to learn is mkdir.<br />

This stands for ‘make directory’. Move to the home<br />

folder and create a new directory called test:<br />

cd ~<br />

mkdir test<br />

cd test<br />

The -l part (an option) makes it use ‘long listing’<br />

mode, which displays items with lots of information:<br />

-rw-rw-r-- 1 pi pi 973 Jan 27 2015<br />

4row_arrow.png<br />

From left to right, each item is:<br />

> Permissions: The users and groups that<br />

can access a file.<br />

> Hard links: he number of files that<br />

are lined to this file.<br />

> Owner: he person who owns the file.<br />

Usually either pi or root.<br />

> Group: he group the file belongs to.<br />

> File size: he name of the file.<br />

> Modification hen the file was last changed.<br />

> File name: he name of the file.<br />

The most obscure item is the list of letters<br />

and hyphens that make up the permissions.<br />

he first letter will be either a or a d<br />

depending on whether its a file or a directory. ur<br />

4row_arrow.png is a file, so its a .<br />

After that are nine letters arranged into three<br />

groups of three (see Fig 1 overleaf):<br />

TAB COMPLETION<br />

The single most useful tip you’ll ever learn for the<br />

command line is tab completion. Pressing TAB at any<br />

time when entering a working path attempts to complete<br />

the le or irector name for o e cd python_games<br />

and enter xdg-open Tr, then press the TAB key. Notice<br />

ho it ll it ot to ‘xdg-open Tree_’. There are three<br />

le tarting ith ree ickl re TAB twice and you’ll<br />

see them: Tree_Short.png, Tree_Tall.png and Tree_Ugly.<br />

png. Enter S, T, or U and press TAB again to ll ot the<br />

hole le name Pre RETURN to open it.<br />

a comletion can e inalale for entering long le<br />

names packed with letters, numbers, and punctuation.<br />

raspberrypi.org/magpi<br />

February xxxxx 2016 2017<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!