next up previous
Next: Text files Up: Introduction to the Linux Previous: Help!

Full-stops, Wildcards and Tab-Completion

By default ls lists every file in the current directory except those beginning with a full-stop. Files beginning with a full-stop are usually configuration files so we don't usually want to see those, though we can force ls to show all files by using ls -a.

[pjh503@bhuna Linux]$ ls -a
.                    first.txt   linux.dvi  linux.tex~            second.txt~
..                   first.txt~  linux.log  second_attendees.odt

Notice that the first two entries are simply a full-stop, and a double full-stop. These are special entries indicating the current directory and the parent directory respectively. We can use these as arguments to the cd command, e.g.

[phasnip@mijpnb1 Linux]$ pwd
[phasnip@mijpnb1 Linux]$ cd ..
[phasnip@mijpnb1 ~/Teaching]$ pwd

Notice that `..' takes you to the parent directory of your current directory, so it is a relative path. It is also sometimes useful to use cd with a special argument cd - which changes directory to the previous directory you were in.

There is another special character used in paths, the tilde `~'. This means `your home directory', so for example

[phasnip@mijpnb1 ~/Teaching]$ cd ~
[phasnip@mijpnb1 ~]$ pwd

Often we don't want to list all the files, just a selection. If we only want to see whether a particular file is there we can do

[phasnip@mijpnb1 ~]$ ls minimiser.tex

If the file isn't there, Linux will tell me:

[phasnip@mijpnb1 ~]$ ls rubbish.txt
ls: rubbish.txt: No such file or directory

Usually we are looking for all files of a certain kind of name, and in Linux this is straightforward by using wildcards. Wildcards are special characters that cannot be used in filenames, and are used by commands to look for patterns. There are two common ones, * and ?. The * matches any characters and is basically used to mean `anything', e.g.

[phasnip@mijpnb1 ~]$ ls *.tex
linux.tex  minimiser.tex
[phasnip@mijpnb1 ~]$ ls m*
minimiser.aux  minimiser.dvi  minimiser.log  minimiser.tex  minimiser.tex~
[phasnip@mijpnb1 ~]$ ls m*tex

Notice that the other characters are taken into account, so that `*txt' means `anything ending with txt', and `f*' means `anything starting with f'.

The `?' character means `any single character'. It can be repeated, e.g.

[phasnip@mijpnb1 ~]$ ls minimiser.???
minimiser.aux  minimiser.dvi  minimiser.log  minimiser.tex

Notice that this only reports filenames with three characters after the full-stop, and so is not the same as ls minimiser.* which would list everything starting `minimiser.'.

We can also use square brackets to indicate a possible selection of characters

[phasnip@mijpnb1 ~]$ ls minimiser.[ta]??
minimiser.aux  minimiser.tex

We can also include a range

[phasnip@mijpnb1 ~]$ ls minimiser.[a-l]*
minimiser.aux  minimiser.dvi  minimiser.log

Finally there is an extremely useful feature which is usually called tab-completion. If you type part of a filename or command in a terminal and press the TAB key once, Linux will look to see which files or commands start with the characters you've types, and fill in as many other characters as are common to them all - this can save a lot of typing! To see which files are consistent with what you've typed, you can use CTRL-d (on some systems pressing TAB twice does this).

Very occasionally you might come across a machine that uses the <ESC> key instead of TAB to do the completion - the operation is the same, it's just the key you press that is different.

next up previous
Next: Text files Up: Introduction to the Linux Previous: Help!
Phil Hasnip 2007-08-23