ELIAS SUOMENTAA TÄMÄN - SUOMENNOS TEHTY, OIKOLUEN VIELÄ SEN Command and Conquer
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.