Whatis UNIX: Topics

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

TOPICS:

 Whatis UNIX
 Filesystem

- navigating
- modifying
- permissions
- archiving / compression

 Helpers, alias and communication commands

- helpers
- commands
- process
- communication

 File processing

- simple commands
- piping
- devices

Whatis UNIX
UNIX is a so called operating system for workstations and has mainly ben developped at
Berkley University (BDS-UNIX). One of the striking difference between UNIX ans
many other operating systems is, that it has been a multiuser and multiprocess
environment from the very beginning. Multiprocess / multiuser means that different tasks
can be run on the same system by different people with different priviliges at the same
time. 
The system used by SGI is a derivate from the original UNIX, a so called dialect, named
IRIX.

Filesystem
The following commands are all crucial for navigating in the structure of the filetree.
Unlike other systems, in UNIX a filesystem cannot only incorporate files and directorys
that are stored locally on the hard drive. It can also merge (shared) drives on other
systems (hosts) or external devices like tape drives or printers, keyboards etc.

Navigation
Ls ls [-RadLCxmlnogrtucpFbqisf1AM] [names]
Lists the content of a directory
ls -ls List in short form
ls -la All files (including .-files)
ls ./mydir List content of mydir
 
Pwd pwd
Print working directory name
pwd
 
Cd cd [ directory ]
Change working directory
cd Change to home directory
cd ~ Change to home directory
cd .. Change to parent directory
cd /usr/lib Change to absolute path /usr/lib
cd doc/letters Change to relative path doc/letters
 
Du du [-sarklmL] [name . . .]
Summarize disk usage
du -k Show disk usage in kblocks (1024 bytes)
du -ks * Summarize all directorys (*) and show as kblocks
 
Df df [-b][-f][-i][-k][-l][file-system ...]
Report number of free disk blocks. Shows usage of disks. Usefull to find out
if there is enough room to save / copy a project or file.
df -k Display disk usage in kblocks

Modifying

Cp cp [ -irp ] file1 [file2 ...] target


Copy files or directory structures
cp file1 file2 Creates a copy of file1, named file2

cp old* archive/ Creates a copy of all files starting


with "old" into the directory archive

cp -R letters archive/. Creates a copy of all files under


“letters" and puts them into archive

ln ln [ -sif ] file1 [file2 ...] target


Link files. Links are like pointers that "point" to the original location of the
file. They thus, use less diskspace.
ln -s /serve/sgi/tools ~/SGItools symbolic link to
serve/sgi in your
homedirectory
 
mv mv [ -if ] file1 [file2 ...] target
Moves files to another location or rename them.
mv file1 file2 Renames file1, to file2

mv old* archive/ Moves all files starting with "old"


into the directory "archive"
 
rm rm [-f] [-i] file
Remove files
rm file1 file2 Removes file1 and file2
rm old* Removes all files starting with "old"
rm -r unused/* Removes all files recursively that
are under "unused"
 
mkdir mkdir [-m mode] [-p] dirname
Make directories
mkdir newthings Creates a directory named "newthings"
 
rmdir rmdir [-p] [-s] dirname
Removes an empty directory. If the directory is not empty, it will not be
removed.
rmdir oldstuff Removes a directory named "oldstuff"

Permissions

Chmod chmod [-R] mode file


Change the permissions of a file or directory. To do so, you have to be the
owner of the file or directory. The permissions are coded into a 6-digit
boolean string.
Permissions are coded into a 6-digit boolean string with the
values 1,2,4 according to their byte-positions:

chmod 644 owner:rw group:r other:r (typical dir)


chmod 755 owner.rwx group:rx other:rx (typical file)

File archiving / compression


tar tar key [directory] [tapefile] [blocksize] [ name ... ]
Tape archiver. Writes a single archive-file from a set of files. Tar is often
used to either backup data or move complete directory-structures around.
Tar usually adresses a tape device, can thoug, be rerouted with the f option
to write to a file.
tar cvf arch.tar docs/* Creates a file named arch.tar with
anything under docs/
tar xvf move.tar Explodes transport.tar and creates
all the directories that have been
packed into the tar file.
Compress data. Results will be stored into a file with the suffix .Z
compress oldfile.txt Will result in oldfile.txt.Z
compress * Will compress every file in the
directory
 
uncompress uncompress [ -f ] [ -v ] [ -c ] [ name ... ]
Expand data with the .Z suffix
uncompress oldfile.txt.Z Will result in oldfile.txt
uncompress * Will decompress every .Z file
in the directory
 
gzip gzip [ -acdfhlLnNrtvV19 ] [-S suffix] [ name ... ]
gunzip [ -acfhlLnNrtvV ] [-S suffix] [ name ... ]
Compress or expand files. Same as 'compress' but with a more efficient
algorithm.
gzip oldfile.txt Compress oldfile.txt to
oldfile.txt.gz
gzip -d oldfile.txt.gz Decompress oldfile.txt.gz to
oldfile.txt

Helpers, alias and communication commands


The commands below will help you to identify your command shell environment. You
can lookup the current user, find out about what command will be executed when you
type something and last, lookup the versions of installed programms.

who who [-uTlHqpdbrtas] [ file ]


who am i
Who is on the system, who owns the current shell?
who Show all logged users (optional -u)
who am i Displays the user of the current shell
 
man man [-cdwWtpr] [-M path] [-T macropackage] [section] title
man [-M path] -k keyword
Print entries from the on-line reference manuals; find manual entries by
keyword
man cp Will show the manpage for the copy ('cp')
command

man -k tape Will search for all helppages, in which the


keyword 'tape' appears

man man ... if ever you have forgotten how to use


'man'

Command interpretation

alias INTERNAL SHELL COMMAND


Creates an alias for a string. Useful if you want to create your own shell
commands. 'alias' will simply list all your defined aliases.
alias ll 'ls -la' Will create a command 'll' that
executes 'ls -la' when you punch 'll'

alias zipall 'gzip *' 'zipall' will gzip all files in the
current directory
 
which which [-a] [-f] [name...]
Locate a program file including aliases and path (csh only!) Searches the
command aliases and your binaries-path for the command that would have
been executed if you had entered the requested string. Sometimes, you
think that a command should be executed, but it is not. Then it is often
useful to check your aliases with 'which'.
which ll Will tell you that 'll' is aliased to 'ls -la'
(if defined like above)

Processes
ps ps [ options ]
Report process status
ps List all active processes
ps -al List all processes in long format
ps -aledf List all processes in long format with
additional information
 
top top [ -i interval ] [ -D fullpathname ]
Display processes having highest CPU usage. If your workstation seems to
be very slow it is often due to a running process. You can identify it using
'top' and close the application that causes the load. If the process is not yours,
you will have to ask either the owner of a superuser to shut down that
process for you.
top Updates every 5 seconds
top -i1 Updates every second
 
kill kill [-signal] pid
Terminate a process by default. To do so, you need the PID (process ID).
You can get that, using either the 'ps' or the 'top' command.
kill 42310 Kills the process with the number 42310 if
yours
kill -INT 42310 Sends the process 42310 the INT signal
(ctrl-c)

Communication

login login [ -d device ] [ name [ environ ... ]]


Sign on. Changes the owner of the current shell or logs you into a system
login
 
ftp ftp [ -v ] [ -d ] [ -i ] [ -n ] [ -g ] [ host ]
Internet file transfer program. One of the oldes ways of moving data from
one server to another. Ftp also allows you to create and remove directorys
remotely. Be careful when using mput/mget. Files with the same name will
be overwritten without asking!
ftp spielberg Opens a ftp connection to Spielberg For
ftp-internal commands, type 'help' at the
prompt.

The most useful are:


get document1 Fetches the file document1 to the local dir
mget doc* Fetches all files named doc* to the local
dir
ls lists the remote dir
cd changes the remote dir
lcd changes the local dir
bin changes the transfer protocol from ascii
to binary and back
 
finger finger [-bfhilmpqsw] [name...]
User information lookup program. Check if a user is logged in on the
remote host. Also used to find out if someone has read email recently.
finger scully@spielberg See if user 'scully' is logged
in on host 'spielberg'

File processing
Since UNIX systems base heavily on plain text files for configuration, there are many
powerful tools that allow you to process such files. Since processing such files often
requires executing many commands after each other, there is something called 'piping'
that allows you to direct the output of a command into the input of the next command.
You can thus execute command chains, without saving the intermediate results to a file. 
Below, you will find the simple commands first, and the chaining of them into complex
command sequences in the 'redirection & piping' section that follows.

Simple commands

echo echo [ arg ]


Echo arguments. Prints arguments to the shell.
echo hi Will print "hi" into your shell
 
grep grep [options] limited regular expression [file . . .]
Search a file for a pattern
grep 'ando' archi.txt Return every line of archi.txt in
which 'ando' appears
grep 'ando' archi/cv*.txt Search in all cv* files under
'archi' for the string 'ando'
 
cat cat [-u] [-s] [-v [-t] [-e]] file
Concatenate and print files. Often used to pipe input into another process.
cat letter3.txt Print file letter3.txt
cat letter*.txt Print all files that match letter*.txt
 
cut cut -clist [file ...]
cut -flist [-dchar] [-s] [file . . .]
Cut out selected fields or characters of each line of a file. Often used by
piping output from another process.
cut -c1-5 data.txt Get first 5 characters of every
line
cut -d/ -f1,4-6 data.txt Get fields 1,4,5,6 delimited by '/'
 
sort sort [-cmu][-ooutput][-ykmem][-zrecsz][-dfiMnr][-btx][+pos1[-pos2]][-
Ttdir][files]
Sort and/or merge files
sort archi.txt Sort the file archi.txt alphabetically
 
diff diff [-lrs] [-Sname] [-cefhn] [-xpat] [-biwt] dir1 dir2
diff [-cefhn] [-biwt] file1 file2
Differential file and directory comparator
diff oldfile newfile Searches the two files and seeks for
differences line by line
 
more more [-cdflrsuw] [-lines] [+linenumber] [+/pattern] [ filename ... ]
Browse or page through a text file
more longfile.txt Prints your file screen by screen
 

Piping and redirecting

Redirection:  
The first thing you can do when interlinking processes, is that you
redirect input or output from / to processes.
 

Redirected output:
ls -la > listing.txt List dir and output to
listing.txt

sort units.txt > sorted.txt Sort units.txt and output to


'sorted.txt'

Redirected input:
cat < data.txt Read the file data.txt as input
for 'cat'

Piping:
Another thing is piping data streams through a multitude of commands.

sort chaos.txt |grep 'apple' Sorts chaos.txt and seeks for


lines with 'apple'
ps -edalf |grep media |cut -c14-20 List all processes, find lines
with 'media' and cut the second f
field (PID)

You might also like