Command and Conquer (suomennos)

Viime kuussa näytimme, kuinka komentoriviä käytetään turvallisesti. Nyt kun tiedätte sen, voitte aloittaa komentorivin hyödyllisen käytön. Seuraavien julkaisuiden aikana näytämme tiedostonhallinnan perusteita, joita käytetään myöhemmin haastavampia tehtäviä tehdessä.

Ensimmäinen komento tässä numerossa vain todistaa viime kuun kirjoituksen alkusanat, "olet kotihakemistossasi". Aina kun näet merkin, se tarkoittaa kotihakemistoasi. Todistaaksesi tämän, kirjoita päätteeseen "pwd". Minä saan seuraavanlaisen tulosteen:

$ pwd /home/robert

Komento näyttää tietenkin sinun kotihakemistosi, eikä minun. Mutta mitä käyttöä tällä on? Mitä merkitsee "olla kotihakemistossa"? Jokainen komento, jonka suoritat, suoritetaan hakemistossa, jossa olet. Tämä ei merkitse paljoa nyt, mutta on tärkeä asia muistaa myöhemmin. Yksi komento, joka käyttää hakemistoasi jossa olet, on "ls". Se tulostaa näytölle tiedot siitä, mitä tiedostoja ja hakemistoja määrittelemässäsi hakemistossa on tai nykyisessä hakemistossa, jos komensit "ls" ilman mitään valintoja.

Omassa kotihakemistossa oleminen ei aina ole tarpeellista, joten siirrytään muualle. Tähän käytämme hakemistonvaihtokomentoa, cd (change directory).

$ cd ~/Asiakirjat

Jos nyt komennat "pwd", näet, että olet hakemistossasi Asiakirjat. ~/ -merkki ei ollut tarpeellinen hakemiston polussa, mutta se on kätevä tapa säästää aikaa. Tässä esimerkissä olit valmiiksi kotihakemistossasi, joten "cd Asiakirjat" olisi myös toiminut. Jos olisit ollut jossain muussa hakemistossa, kuten hakemistossa "/home/robert/Kuvat/2007/Joulukuu/Joulu", olisi kestänyt kauan vaihtaa hakemistoa ilman ~/ -merkintää. Nyt olet Asiakirjat-hakemistossasi, joten miten vaihdat takaisin kotihakemistoon? Siihen on muutama tapa.

$ cd $ cd .. $ cd ~/ $ cd /home/robert

Näistä jokainen tekee saman asian, jos olet Asiakirjat-hakemistossa. "cd" ilman mitään valintoja vaihtaa aina kotihakemistoon. "cd .." vaihtaa sinut ylempään hakemistoon. Tässä tilanteessa vaihdoimme hakemistosta "/home/robert/Asiakirjat" edelliseen hakemistoon, "/home/robert. Kolmas käyttää ~-merkkiä, jota voidaan käyttää /-merkin kanssa tai olla käyttämättä. Viimeinen komento käyttää koko polkua, joka vaihtaa sinut aina siihen hakemistoon, jonka määrittelet, jos se vain on olemassa.

Nyt ajansäästövinkkejä. Sen sijaan, että kirjoittaisit pitkän hakemiston nimen kuten "~/Kuvat/2007/Joulukuu/Joulu", voit vain kirjoittaa hakemiston muutaman ensimmäisen kirjaimen.

$ cd ~/Ku<tab>

Korvaa <tab> painamalla tabulaattoria. Huomaat, kuinka hakemiston nimi täydentyy automaattisesti. Voit käyttää tätä tapaa useimpien hakemistojen kanssa ja näin säästää aikaa.

Ongelmanratkaisu

Voit kohdata joitain ongelmia näiden yksinkertaisten komentojen suorittamisessa. Älä huoli, ne ovat usein varsin yksinkertaisia. Ensimmäinen ongelma jonka kohtaat, on luultavasti silloin, kun yrität siirtyä Asiakirjat-hakemistoon:

-bash: cd: asiakirjat: No such file or directory

Komentorivillä isoilla ja pienillä kirjaimilla on eroa! "Asiakirjat" ja "asiakirjat" ovat kaksi ihan eri asiaa päätteen kannalta, joten käytä aina oikeaa kirjainkokoa. Voit saada tämän virheen myös, jos Asiakirjat-hakemistoa ei ole, jos olet vaikkapa poistanut sen. Toinen ongelma voi esiintyä, kun kokeilet tabulaattori-täydennystä. Jos tietokoneesi piippaa kun painat tabia, se voi merkitä kahta asiaa. Ensimmäinen on se, ettei hakemistoa ole olemassa. Jos hakemistoa ei ole olemassa, ei sen nimeäkään voida täydentää! Toinen syy voi olla, että sinulla on monta Ku-alkuista hakemistoa kotihakemistossasi. Jos asia on näin, paina tabulaattoria uudelleen, jolloin saat listan Ku-alkuisista hakemistoista. Tämän jälkeen voit kirjoittaa muutaman kirjaimen lisää ja painaa uudelleen tabulaattoria. Jos vaihtoehtoja on todella monta, voit nähdä tällainen viestin:

Display all 388 possibilities? (y or n)

Jos et halua nähdä kaikkia vaihtoehtoja, kirjoita n ja paina enteriä. Kirjoita tämän jälkeen muutama kirjain lisää, jotta vaihtoehdot vähenisivät, jonka jälkeen täydennys taas toimii.


Command and Conquer (englanniksi)

Last month we showed you how to stay safe using a command line. Now you know that, you can start using it to your advantage! Over the next few issues, we'll show you the basics of file management, which will be of use later on when doing more advanced things.

The first command in this issue will just prove a statement from the start of last months article, "you are in your home directory". Whenever you see ~ is means your home directory, so to prove this, type 'pwd' in a terminal. I get this output:

$ pwd /home/robert

Of course this will display your home directory, rather than mine. But what use is this to you? What does it mean to be 'in your home directory'? Any commands you execute, will be run in the current directory. This won't mean much for now, but will make all the difference later on. One command that uses your current directory is 'ls', which will give you a list of files in the directory you specify, or in the current directory if you don't specify one.

It's not always useful to be in your home directory though, so lets move away. To do this, we use the change directory command, cd.

$ cd ~/Documents

If you now type 'pwd', you will see you are now in your documents directory. The '~/' was not needed for that command, however it can be a handy shortcut to save time. In this example, you were already in your home directory, so 'cd Documents' would have worked. If you were in another directory though, say '/home/robert/Pictures/2007/December/Christmas' for example, it would take a long time to change to the documents directory without '~/'. Now you're in your Documents directory though, how do you move back to your home directory? There are several ways do to this.

$ cd $ cd .. $ cd ~/ $ cd /home/robert

These all do the same thing if you are in your Documents directory. 'cd' with no arguments will always take you to your home folder. 'cd ..' takes you to your previous directory, so here we moved from '/home/robert/Documents' to the previous directory, '/home/robert'. The third uses the ~ shortcut, and can be used with or without the trailing '/'. The final command uses the full path, which will always take you to the exact location providing it exists.

Now for some time saving! Rather than typing out a long directory like '~/Pictures/2007/December/Christmas', you can just type the first few letters!

$ cd ~/Pi<tab>

Replace <tab> with you pressing your tab key, and notice how it automatically changes to Pictures? You can use this technique with most directories to save time.

Troubleshooting

You may have encountered some problems, just performing these simple commands. Don't worry though, it is probably something very simple. The first problem you may have encountered probably happened when you tried changing to the Documents directory.

-bash: cd: documents: No such file or directory

Everything you enter at the command line is case sensitive! "Documents" and "documents" are two completely different directories in the eyes of the terminal, so make sure you have the correct capitalization! You may also have had this error if you don't have a Documents directory, for example if you have deleted it. The other error you may have encountered is when trying to use tab complete. If your computer gave a beep when you hit tab, it can mean one of two things. The first is that the directory doesn't exist. If the directory doesn't exist, it won't be able to tab complete it! The other possible reason is that you have multiple directories starting with Pi in your home directory. If this is the case then hit tab again, and you will get a list of possible files and directories, so you can type a few more letters and hit tab again. If there are a lot of possible matches, you will see something like:

Display all 388 possibilities? (y or n)

Unless you want to see them all, type 'n', then hit enter and type a few more letters to narrow down the number of possible matches.