Skip to content

Edit files#

But Jeff's age is wrong! Let's fix it, but in a slightly different way this time. Just type nano. We get nano again like we did before, but it looks like a new file again and not Jeff's details? That's because it is. Let's "read" the file from the file system: Ctrl+R

I'm asked this by nano in the same place it asked us for the jeff.txt file name earlier: File to insert [from ./]:.

What does ./ mean? We know that / means "root of the filesystem", but what does the . do? Let's exit nano and work this out: press Ctrl+C (cancel the "Read File") then Ctrl+X to exit nano. Now do ls -la

michael@develop:~/friends$ ls -la
total 12
drwxrwxr-x 2 michael michael 4096 Mar 18 09:30 .
drwxr-xr-x 5 michael michael 4096 Mar 18 09:23 ..
-rw-rw-r-- 1 michael michael   68 Mar 18 09:30 jeff.txt

That's interesting because now we have two new rows: . and ... That's because the -a flag showed us more information. Use the man ls page to find out what the -a flag does.

Could the . be related to ./? Yes. It means: the current directory. The .. means the "previous" directory or the parent directory - the one above the directory we're currently in - which is our home directory, right? Because we created a friends directory and then we moved into it and created jeff.txt.

So what happens if you do: cd ./?

michael@develop:~/friends$ cd ./
michael@develop:~/friends$ pwd

You stay where you are. And if we do: cd .. (note the lack / at the end? It's not needed)

michael@develop:~/friends$ cd ..
michael@develop:~$ pwd

Let's go back to friends and then we'll see why ./ is useful to have: cd friends. Now start the nano editor. Next press Ctrl+R again. I then type this in response to the question: File to insert [from ./]: jeff.txt and press Enter

This effectively translates to ./jeff.txt, but why is ./ useful? Because it's called a "relative path", which means it's a path that's relative to where we are on the file system. If this wasn't something we could do, we'd have to type: /home/michael/friends/jeff.txt (in my case.) That's long winded and would get annoying quickly.

Update Jeff's age to say 34, not 24. Use the arrow keys (Up, Down, Left, Right) to move to the end of the line and then use Backspace to delete 24 and replace it with 34. Now press Ctrl+O to save the file (write it to the file system) and Ctrl+X to exit nano.