Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Pwd - pwd command will print your home directory on screen, pwd means print
working directory.
/u0/ssb/sandeep - is output for the command when I use pwd in /u0/ssb/sandeep
directory.
Ls - ls command is most widely used command and it displays the contents of directory.
Options
ls will list all the files in your home directory, this command has many options.
ls -l will list all the file names, permissions, group, etc in long format.
ls -a will list all the files including hidden files that start with . .
ls -lt will list all files names based on the time of creation, newer files bring first.
ls Fx will list files and directory names will be followed by slash.
ls R will lists all the files and files in the all the directories, recursively.
ls -R | more will list all the files and files in all the directories, one page at a time.
Mkdir - mkdir sandeep will create new directory, i.e. here sandeep directory is
created.
Cat - cat cal.txt cat command displays the contents of a file here cal.txt on screen (or
standard out).
More - More command will display a page at a time and then wait for input which is
spacebar. For example if you have a file which is 500 lines and you want to read it all. So
you can use
more filename
Wc - wc command counts the characters, words or lines in a file depending upon the
option.
Options
File -File command displays about the contents of a given file, whether it is a text
(Ascii) or binary file. To use it type
file filename. For example I have cal.txt which has ascii characters about calander of
current month and I have resume1.doc file which is a binary file in Microsoft Word. I
will get
file resume.doc
resume1.doc: data
file cal.txt
cal.txt:
ascii text
Rcp - rcp command will copy files between two unix systems and works just like cp
command (-p and -i options too).
For example you are on a unix system that is called Cheetah and want to copy a file
which is in current directory to a system that is called lion in /usr/john/ directory then you
can use rcp command
rcp filename lion:/usr/john
You will also need permissions between the two machines. For more infor type man rcp
at command line.
Some examples:
Ln - Instead of copying you can also make links to existing files using ln command.
If you want to create a link to a file called coolfile in /usr/local/bin directory then you can
enter this command.
ln mycoolfile /usr/local/bin/coolfile
Some examples:
ln -s fileone filetwo will create a symbolic link and can exist across machines.
ln -n option will not overwrite existing files.
ln -f will force the link to occur.
Ftp - ftp command is used to execute ftp protocol using which files are transferred over
two systems.
Syntax is
ftp options hostname
options
-d enable debugging.
-g disable filename globbing.
-i turn off interactive prompts.
-v verbose on. show all responses from remote server.
ftp hostname by default will connect you to the system, you must have a login id to be
able to transfer the files. Two types of files can be transferred, ASCII or Binary.
bin at ftp> prompt will set the transfer to binary.
Steps:
1.
2.
3.
4.
ftp hostname
Connects to host
Login:
Password:
Advanced
Lcd - Changes your local directory (the directory from which you started 'ftp' from).
! - Allows to suspend ftp and use your command prompt, type 'exit' to return to 'ftp'.
Storage commands
Compress - compress command compresses a file and returns the original file
with .z extension, to uncompress this filename.Z file use uncompress filename command.
syntax for compress command is
compress options files
Options
-bn limit the number of bits in coding to n.
-c write to standard output (do not change files).
-f compress conditionally, do not prompt before overwriting files.
-v Print the resulting percentage of reduction for files.
Cpio - cpio command is useful to backup the file systems. It copy file archives in from
or out to tape or disk, or to another location on the local machine. Its syntax is
cpio flags [options]
It has three flags, -i, -o, -p
cpio -i [options] [patterns]
o cpio -i copy in files who names match selected patterns.
o If no pattern is used all files are copied in.
o It is used to write to a tape.
cpio -o
o Copy out a list of files whose name are given on standard output.
cpio -p
o copy files to another directory on the same system.
Options
o -a reset access times of input files.
o -A append files to an archive (must use with -o).
o -b swap bytes and half-words. Words are 4 bytes.
o -B block input or output using 5120 bytes per record.
o -c Read or write header information as Ascii character.
o
o
o
o
o
o
o
o
o
find . -name "*.old" -print | cpio -ocvB > /dev/rst8 will backup all *.old
files to a tape in /dev/rst8
cpio -icdv "save"" < /dev/rst8 will restore all files whose name contain
"save"
find . -depth -print | cpio -padm /mydir will move a directory tree.
Examples
o
o
Pack - pack command compacts each file and combine them together into a filename.z
file. The original file is replaced. Pcat and unpack will restore packed files to their
original form.
Syntax is
Pack options files
Options
- Print number of times each byte is used, relative frequency and byte code.
-f Force the pack even when disk space isn't saved.
To display Packed files in a file use pcat command
pcat filename.z
To unpack a packed file use unpack command as unpack filename.z .
Examples:
tar cvf /dev/rmt/0 /bin /usr/bin creates an archive of /bin and /usr/bin, and store on the
tape in /dev/rmt0.
tar tvf /dev/rmt0 will list the tape's content in a /dev/rmt0 drive.
tar cvf - 'find . -print' > backup.tar will creates an archive of current directory and store it
in file backup.tar.
Functions:
Options:
Mt - mt command is used for tape and other device functions like rewinding, ejecting,
etc. It give commands to tape device rather than tape itself. Mt command is BSD
command and is seldom found in system V unix versions.
syntax is
mt [-t tapename] command [count]
mt for HP-UX accept following commands
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
red rojo
green verde
blue azul
<control-D>
%
TCS Internal
<control-D> stands for "hold the control key down, then tap 'd'". The symbol > tells the
computer that what is typed is to be put into the file dict. To view a file we use cat in a
different way:
% cat dict
red rojo
green verde
blue azul
%
If we wish to add text to an existing file we do this:
% cat >>dict
white blanco
black negro
<control-D>
%
Now suppose that we have another file tmp that looks like this:
% cat tmp
cat gato
dog perro
%
Then we can join dict and tmp like this:
% cat dict tmp >dict2
We could check the number of lines in the new file like this:
% wc -l dict2
The command wc counts things --- the number of characters, words, and line in a file.
chmod
This command is used to change the permissions of a file or directory. For example to make a
file essay.001 readable by everyone, we do this:
% chmod a+r essay.001
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
TCS Internal
% pwd
% /u/ma/jeremy/english
% ls
novel poems
% cd novel
% pwd
% /u/ma/jeremy/english/novel
% ls
ch1 ch2 ch3 journal scrapbook
% cd ..
% pwd
% /u/ma/jeremy/english
% cd poems
% cd
% /u/ma/jeremy
cp
Use cp to copy files or directories.
% cp foo foo.2
This makes a copy of the file foo.
% cp ~/poems/jabber .
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 Jan 6 08:52:42 MST 1995
echo
The echo command echoes its arguments. Here are some examples:
% echo this
this
% echo $EDITOR
/usr/local/bin/emacs
% echo $PRINTER
b129lab1
Things like PRINTER are so-called environment variables. This one stores the name of the
default printer --- the one that print jobs will go to unless you take some action to change
things. The dollar sign before an environment variable is needed to get the value in the
variable. Try the following to verify this:
% echo PRINTER
PRINTER
ftp
Use ftp to connect to a remote machine, then upload or download files. See also: ncftp
TCS Internal
Example 1: We'll connect to the machine fubar.net, then change director to mystuff, then
download the file homework11:
% ftp solitude
Connected to fubar.net.
220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
Password:
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> get homework11
ftp> quit
Example 2: We'll connect to the machine fubar.net, then change director to mystuff, then
upload the file collected-letters:
% ftp solitude
Connected to fubar.net.
220 fubar.net FTP server (Version wu-2.4(11) Mon Apr 18 17:26:33 MDT 1994) ready.
Name (solitude:carlson): jeremy
331 Password required for jeremy.
Password:
230 User jeremy logged in.
ftp> cd mystuff
250 CWD command successful.
ftp> put collected-letters
ftp> quit
The ftp program sends files in ascii (text) format unless you specify binary mode:
ftp> binary
ftp> put foo
ftp> ascii
ftp> get bar
The file foo was transferred in binary mode, the file bar was transferred in ascii mode.
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
red rojo
green verde
blue azul
white blanco
black negro
Then we can look up items in our file like this;
% grep red dict
red rojo
% grep blanco dict
white blanco
% grep brown dict
%
TCS Internal
Notice that no output was returned by grep brown. This is because "brown" is not in our
dictionary file.
Grep can also be combined with other commands. For example, if one had a file of phone
numbers named "ph", one entry per line, then the following command would give an
alphabetical list of all persons whose name contains the string "Fred".
% grep Fred ph | sort
Alpha, Fred: 333-6565
Beta, Freddie: 656-0099
Frederickson, Molly: 444-0981
Gamma, Fred-George: 111-7676
Zeta, Frederick: 431-0987
The symbol "|" is called "pipe." It pipes the output of the grep command into the input of the
sort command.
For more information on grep, consult
% man grep
head
Use this command to look at the head of a file. For example,
% head essay.001
displays the first 10 lines of the file essay.001 To see a specific number of lines, do this:
% head -20 essay.001
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
foo
letter2
foobar letter3
letter1 maple-assignment1
%
Note that you have six files. There are some useful variants of the ls command:
% ls l*
letter1 letter2 letter3
%
Note what happened: all the files whose name begins with "l" are listed. The asterisk (*) is the
" wildcard" character. It matches any string.
lpr
This is the standard Unix command for printing a file. It stands for the ancient "line printer."
See
TCS Internal
% 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 essays
To get "into" this directory, do
% cd essays
To see what files are in essays, do this:
% ls
There shouldn't be any files there yet, since you just made it. To create files, see cat or emacs.
more
More is a command used to read text files. For example, we could do this:
% more poems
The effect of this to let you read the file "poems ". It probably will not fit in one screen, so you
need to know how to "turn pages". Here are the basic commands:
TCS Internal
TCS Internal
% 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.
See also: telnet
setenv
% echo $PRINTER
labprinter
% setenv PRINTER myprinter
% echo $PRINTER
myprinter
sort
Use this commmand to sort a file. For example, suppose we have a file dict with contents
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this:
% sort dict
black negro
blue azul
green verde
red rojo
white blanco
Here the output of sort went to the screen. To store the output in file we do this:
% sort dict >dict.sorted
You can check the contents of the file dict.sorted using cat , more , or emacs .
tail
Use this command to look at the tail of a file. For example,
% head essay.001
displays the last 10 lines of the file essay.001 To see a specific number of lines, do this:
% head -20 essay.001
This displays the last 20 lines of the file.
TCS Internal
tar
Use create compressed archives of directories and files, and also to extract directories and
files from an archive. Example:
% tar -tvzf foo.tar.gz
displays the file names in the compressed archive foo.tar.gz while
% tar -xvzf foo.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
red rojo
green verde
blue azul
white blanco
black negro
Then we can do this
% wc dict
5
10
56 tmp
This shows that dict has 5 lines, 10 words, and 56 characters.
The word count command has several options, as illustrated below:
% wc -l dict
5 tmp
% wc -w dict
10 tmp
% wc -c dict
56 tmp
dummy
Under construction
TCS Internal
Unix Commands
Command/Syntax
What it will do
cd [directory]
change directory
compare two files and list where differences occur (text or binary
files)
copy file1 into file2; file2 shouldn't already exist. This command
creates or overwrites file2.
date [options]
dd [if=infile] [of=outfile]
[operand=value]
compare the two files and display the differences (text files only)
df [options] [resource]
report the summary of disk blocks and inodes free and in use
du [options] [directory or
file]
ed or ex [options] file
full-screen editor
expr arguments
finger [options]
user[@hostname]
search the argument (in this case probably a file) for all
occurrences of the search string, and list them.
TCS Internal
hostname
ln [options] source_file
target
lpq [options]
show the status of print jobs
lpstat [options]
lpr [options] file
print to defined printer
lp [options] file
lprm [options]
remove a print job from the print queue
cancel [options]
ls [options] [directory or file] list directory contents or file permissions
mail [options] [user]
mailx [options] [user]
make a directory
pg [options] file
mv [options] file1 file2
od [options] file
passwd [options]
pr [options] file
ps [options]
pwd
rm [options] file
remove a directory
TCS Internal
script file
stream editor for editing files from a script or from the command
line
source file
. file
read commands from the file and execute them in the current
shell. source: C shell, .: Bourne shell.
stty [options]
uncompress file.Z
uudecode [file]
encode binary file to 7-bit ASCII, useful when sending via email,
to be decoded as new_name at destination
vi [options] file
wc [options] [file(s)]
report the binary, source, and man page locations for the
command named
which command
who or w
zcat file.Z
TCS Internal