cal Print a calendar.
who Show who is currently logged on to this machine.
The following commands give access to a variety of on-line help systems.
man cmd The official on-line manual.
man -k topic Keyword search of the manual.
apropos topic Equivalent to man -k.
gnome-help The (graphical) Gnome help system.
info The Gnu info system.
The manual (either using the man command or through the gnome-help interface) should be the first place you use to obtain information about the system. The info command will get you access to a set of longer documents about some of the installed software.
The File System
The Linux file system is organised as a set of nested containers called directories (or folders). Each directory can be used to hold other directories or files. The position of each file or directory is described by its pathname. This is a sequence of names separated by slashes (/).
/dir1/dir2/. . ./dirn/filename
At any given time there is a current working directory and simple names are taken to refer to files within this directory. File names can also be specified relative to the current directory using . to indicate the current directory and .. to indicate “up one level” from the current directory.
There are a large number of commands related to obtaining information about files and directories in the system.
pwd Print the path name of the current directory.
cd dir Change the working directory to the one specified.
ls List the names of the files in the current directory.
ls -l List file names with additional information.
du Report disk usage (in 1 kilobyte blocks).
quota Report on disk usage and quota.
wc Report lines, words and characters in a file.
wc -l Report the number of lines in a file.
wc -w Report the number of words in a file.
Copying, Moving and Removing Files
A number of commands can be used to copy and move files. Most of the file names here can be simple names or either relative or full pathnames.
cp old new Make a copy of a file under a new name.
mv old new Rename a file.
cp files dir Copy the specified files to the given directory.
mv files dir Move one or more files to a directory.
rm files Remove the named files.
rmdir dir Remove the named (empty) directories.
rm -r files Recursively remove the named files and directories.
Redirecting Output
The output of Linux commands can be redirected to and from files.
cmd > file Redirect output to the given file (overwrites).
cmd >> file Append output to the given file.
cmd < file Take input from the given file.
cmd1 | cmd2 Output from one program into another (a “pipe”).
The use of pipes is what makes Linux such a flexible system. For example,
who | wc -l
will count the number of users currently logged in.
Basic Operations on Files
cat Concatenate and print files (on screen).
tr Transliterate character sets.
grep Print lines matching a pattern.
sort Sort the lines of a file.
head First few lines of a file.
tail Last few lines of a file.
more Page at a time display.
less Alternative page at a time display.
These programs can be combined using the redirection operations above. Here is how to concatenate three files together.
cat file1 file2 file3 > combined
Here is how to convert all uppercase letters in a file to lower case.
tr [A-Z] [a-z] mixed > lcase
Here is to find the lines in a file which contain the word Unix
grep Unix file
Find the number of lines which contain the word Unix.
grep Unix file | wc -l