Show directories with trailing slash:
$ ls -F
LICENSE.txt conf/ data/ docs/ index.swc license.swc
Makefile config.mk depend.mk img/ lec/ press/
Show all files and directories, including those whose names begin with "." (by default, ls doesn't show things whose names begin with ".". This means . and .. don't always show up. (We'll see what the .svn directory is for later)
$ ls -a
. .svn Makefile config.mk depend.mk img lec
.. LICENSE.txt conf data docs index.swc
Flags can be combined
$ ls -a -F
. .svn/ Makefile config.mk depend.mk img/ lec/
.. LICENSE.txt conf/ data/ docs/ index.swc
Creating Files and Directories
Rather than messing with the course files, let's create a temporary directory and play around in there:
$ mkdir tmp
(Note: this produces no output, but -v (“verbose”) would tell mkdir to print a confirmation message)
Now go into that directory - there are no files there yet.
$ cd tmp
$ ls
Use the editor of your choice to create a file called earth.txt with the following contents:
Name: Earth
Period: 365.26 days
Inclination: 0.00
Eccentricity: 0.02
You can use Notepad (on Windows), which runs in a window of its own. You can also use Pico (on Unix), which takes over the shell window temporarily. The easiest way to create a similar file venus.txt is to copy earth.txt and edit it:
$ cp earth.txt venus.txt
$ edit venus.txt
$ ls -t
venus.txt earth.txt
Note: -t tells ls to list by modification time, instead of alphabetically
Looking at Files
You can check the contents of the file using cat (short for “concatenate”), which prints the contents of a file to the screen.
$ cat venus.txt
Name: Venus
Period: 224.70 days
Inclination: 3.39
Eccentricity: 0.01
You can also compare the sizes of the two files using: ls -l (“-l” meaning “long form”)
Note the fifth column is size in bytes:
$ ls -l
total 2
-rwxr-xr-x 1 gvwilson None 73 Jan 4 15:58 earth.txt
-rwxr-xr-x 1 gvwilson None 73 Jan 4 15:58 venus.txt
Another way to compare is using wc (for “word count”). The columns show lines, words, and characters:
$ wc earth.txt venus.txt
4 9 73 earth.txt
4 9 73 venus.txt
8 18 146 total
Basic Tools
man | Documentation for commands. |
cat | Concatenate and display text files. |
cd | Change working directory. |
clear | Clear the screen. |
cp | Copy files and directories. |
date | Display the current date and time. |
diff | Show differences between two text files. |
echo | Print arguments. |
head | Display the first few lines of a file. |
ls | List files and directories. |
mkdir | Make directories. |
more | Page through a text file. |
mv | Move (rename) files and directories. |
od | Display the bytes in a file. |
passwd | Change your password. |
pwd | Print current working directory. |
rm | Remove files. |
rmdir | Remove directories. |
sort | Sort lines. |
tail | Display the last few lines of a file. |
uniq | Remove adjacent duplicate lines. |
wc | Count lines, words, and characters in a file. |