- cat --- for creating and displaying short files
- chmod --- change permissions
- cd --- change directory
- cp --- for copying files
- date --- display date
- echo --- echo argument
- ftp --- connect to a remote machine to download or upload files
- grep --- search file
- head --- display first part of file
- ls --- see what files you have
- lpr --- standard print command (see also print )
- more --- use to read files
- mkdir --- create directory
- mv --- for moving and renaming files
- print --- custom print command (see also lpr )
- pwd --- find out what directory you are in
- rm --- remove a file
- rmdir --- remove directory> %
- rsh --- remote shell
- setenv --- set an environment variable
- sort --- sort file
- tail --- display last part of file
- tar --- create an archive, add or extract files
- telnet --- log in to another machine
cat
This is one of the most flexible Unix commands. We can use
to create, view and concatenate files. For our first example we create a
three-item English-Spanish dictionary in a file called "dict."
% cat >dict
test1
test2
test3
<control-D>
%
chmod
This command is used to change the permissions of a file or
directory. For example to make a file new_file.pl readable by everyone, we do
this:
% chmod a+r new_file.pl
To make a file, e.g., a shell script mycommand executable,
we do this
% chmod +x
mycommand
Now we can run mycommand as a command.
To check the permissions of a file, use ls -l . For more
information on chmod, use man chmod.
cd
Use cd to change directory. Use pwd to see what directory
you are in.
% cd english
% pwd
%
/test_file/test
% ls
scrapbook
% cd
cp
Use cp to copy files or directories.
% cp test_file test_file.bk
This makes a copy of the file test_file.
% cp ~/new_file/new_file.bk
This copies the file jabber in the directory poems to the
current directory. The symbol "." stands for the current directory.
The symbol "~" stands for the home directory.
date
Use this command to check the date and time.
% date
Fri Nov 6 08:52:42
MST 2012
echo
The echo command echoes its arguments. Here are some
examples:
grep
Use this command to search for information in a file or
files. For example, suppose that we have a file dict whose contents are
redtest1
white test1
white test1
head
Use this command to look at the head of a file. For example,
% head test.pl
displays the first 10 lines of the file essay.001 To see a
specific number of lines, do this:
% head -n 20 test.pl
This displays the first 20 lines of the file.
ls
Use ls to see what files you have. Your files are kept in
something called a directory.
% ls
test letter2
test1 letter3
test3 maple-assignment1
lpr
This is the standard Unix command for printing a file. It
stands for the ancient "line printer." See
% man lpr
for information on how it works. See print for information
on our local intelligent print command.
mkdir
Use this command to create a directory.
% mkdir test
mv
Use this command to change the name of file and directories.
% mv foo foobar
The file that was named foo is now named foobar
print
This is a moderately intelligent print command.
% print foo
% print notes.ps
% print
manuscript.dvi
pwd
Use this command to find out what directory you are working
in.
% pwd
rm
Use rm to remove files from your directory.
% rm test.pl
remove test.pl? y
% rm letter*
remove letter1? y
remove letter2? y
rmdir
Use this command to remove a directory. For example, to
remove a directory called "essays", do this:
% rmdir essays
A directory must be empty before it can be removed. To empty
a directory, use rm.
rsh
Use this command if you want to work on a computer different
from the one you are currently working on. One reason to do this is that the
remote machine might be faster. For example, the command
% rsh solitude
connects you to the machine solitude. This is one of our
public workstations and is fairly fast.
sort
Use this commmand to sort a file. For example, suppose we
have a file dict with contents
red test
white test1
white test1
tail
Use this command to look at the tail of a file. For example,
% tail new_test.pl
displays the last 10 lines of the file new_test.pl To see a
specific number of lines, do this:
% tail -n 20 new_test.pl
This displays the last 20 lines of the file.
tar
Use create compressed archives of directories and files, and
also to extract directories and files from an archive. Example:
% tar -tvzf test.tar.gz
displays the file names in the compressed archive foo.tar.gz
while
% tar -xvzf test.tar.gz
extracts the files.
telnet
Use this command to log in to another machine from the
machine you are currently working on. For example, to log in to the machine
"solitude", do this:
% telnet solitude
See also: rsh.
wc
Use this command to count the number of characters, words,
and lines in a file. Suppose, for example, that we have a file dict with
contents
test file
test1 file1
Then we can do this
% wc dict
5 10
56 tmp
This shows that dict has 2 lines, 4 words, and 18 characters.