Вы находитесь на странице: 1из 13

Unix Lazydog 2000

2001-04-10 Written and collected by Burak Camursoy Rev R1A

Show the contents of a directory


ls a ls la ls l ls F # Show all files including the hidden ones # Show the files in a list including the hidden ones # Show the files in a list # lista filer som r bibliotek med /

Create Links
ln ls l ls li fil1 fil2 fil4 # creates a new link called fil2 to fil1 # gives info about the symbolic link fil4 ln s /usr/bin fil4# creates a symbolic link to the directory /usr/bin and gives the namne fil4 fil1# gives inodnumber to the file fil1 and you can see how many links are created to this file

Showe size of the directory


df # gives info about the physical filesystem in the unixmaschine du potatis# shows the size of the file potatis du k potatis# shows size in kbyte du b potatis# In bytes du ks df ek df k # shows in kilobyte all the disk partitions # shows the disk usage in % # displays capacity of filesystem

quot -af# displays diskspace being used by users on all mounted filesystems quot f /dev/dsk/c0t0d0s5# displays the number of files and space owned by each user in a specific disk slice

Harddrive information
c#t#d#s# c= controller number t= target number(scassi number) d= disk number s= slice number

c0t6d0s0 = cdrom

Copy of the files


cp a.out nya.out cp a.out /home # Copy the file a.out to nya.out # Copy a.out to directory /home cp i a.out nya.out# Give a warning before the copy

Rename the files/ move the files


mv i fil.txt nyfil.txt# rename fil.txt to nyfil.txt mv /home/potatis/fil.txt /home# move the file fil.txt to directory /home

Delete files
rm i fil.txt rmdir potatis \rm fR Site-data# deletes the whole directory including the under directories # delete the file fil.txt rm r manual test.txt # delete files and directories

See the content of a file


cat cat n cat b cat cat cat cat are. more pg file name file name # #stops after each page file name file name file name kap? a???a kap* ~/info # print the content of the file # print the content of the file with the line numbers # print the content of the file with the line numbers except the last line # print content of the files which the first letters starts with kap # print content of the files which has 5 letters which starts and ends with the letter a. # print content of the files which the first letters starts with kap # print content of the file info which is in your home directory no matter in which directory you

Cout the lines in a file


wc l wc w wc m fil.txt fil.txt fil.txt # prints number of lines in the file fil.txt # prints number of words in the file fil.txt # prints number of letters in the fil.txt

Find
find . name prog.c print find . name \*.c print find \ name prog.c print # dot means search in actual directory and below the actual directory # search all c files in actual directory and below the actual directory # search in all directories

File
file main.c a.out # gives info about the includings of the file

Grep
grep n unix c1.mm grep i unix c1.mm grep ni unix c1.mm grep c error c1.mm grep error *.mm # search the lines including unix in the text file # do the same as abowe but include bouth small and capital letters # print all the lines with line number including unix,Unix eller UNIX # print number of lines including the character error # search and print out all lines including the character error

Pkginfo
pkginfo | more pkgrm SUNWaudio pkgchk v SUNWaudio pkgchk p /etc/passwd admintool # displays info about installed program pakages # removes the program pakage # lists files including in the actuall program pakage # Displays the changes made on the actuall file

pkgadd d /cdrom/cdrom0/s0/Solaris# installs a program pakage # It is possible to check the installed pakages and install new pakages with admintool

Processer
ps fe ps e ps ax kill process number kill 9 process number # kill the process # kill the process brutally # list all the processes

The command at is used to do sum commands in a specified time. at 0300 at> lpr lista1 at> lpr lista2 <ctrl d> leave 1700 # jobb list can be ended with ctrl-d # this command sets a timer to 17:00 kl # in this example the print command will be executed 03:00 kl in the nite

X server applications
xhost + xprop xset xlock xwd # Control access to an X display # shows windows font properties # sets users preferences ( display, keyboard, and mouse ) # lockes the workspace # stores a screen image (window dump) in a file

Xterm
xterm sb & xkill xrefresh # xterm window with window list # shuts down the xterm window # if you get strange characters in the xterm window

xterm bg black fg yellow T Potatis& xterm geometry 132*50 10 10 & xterm sb title potatis display kudos:0.0&

# starts a xterm window with the title potatis

Tar and zip


tar cvf text.tar *.txt tar cvf katalog.tar katalog tar xvf katalog.tar tar tvf katalog.tar tar xzvf potatis.tar.Z # archive all the txt files under the arkive text.tar # archive the directory katalog under the archive katalog.tar # extract the archive katalog.tar # see the content of the archive katalog.tar # archive and compress the directory potatis # extract and uncompress the archive potatis

tar czvf potatis.tar.Z potatis

Compress the files


gzip test.pdf gunzip test.pdf.gz compress test.pdf uncompress test.pdf.Z pkzip test.pdf pkunzip test.pdf.zip If you want to compress a directory, change directoty to actual directory and; gzip * Katalog.gz # compress the file test.pdf # decompress the file test.pdf.gz # compress the file test.pdf # decompress the file

Display other unix workstation Display on your own display


xhosts + rlogin ipadress l anxadm echo $DISPLAY setenv own ipadress :0.0 /opt/anxms/0/bin/ovw_anx # all other workstations can access your workstation # logg in to the other workstation # show display # put the environment variable to other workstation #start HP Openview

Shuting down a unix workstation


init 0 init 5 init 6, reboot shutdown iS seconds before the shuting down shutdown i0 shutdown i5 halt poweroff # shutdown to ok prompt # Shutdown and turn the power off # Shutsdown to ok prompt with out terminating application processes # if there are applications using databases they can be curropted # Shutsdown and power off with out killing all the processes # shutdown to ok prompt # shutdown and turnoff the power # rebootes the workstation # shutdown, if this is done in a network the server broadcasts shutdown warning in 60

Check the adapter


pkg info adapter a # shows all the packages installed in the workstation # tests the adapter

Mail
dtmail & # starts the mail application in unix

How to see the actual shell you are using


Check the cursor If it looks like % = C Shell or TC Shell If its look like $ = Bourne Shell or Korn Shell

Filname expanding with noglob


In Korn Shell: set +o noglob set o noglob In C or TC Shell: set unset noglob noglob

Serial communication between two unix workstations


Cable connection: Serial A/1 on CPn and Serial B/2 on MS Start xterm In MS: xterm & tip hardwire Power on the CP Tips: Break signal in tip : Close tip : ~# ~.

When vi not works proprely in a terminal


To see what the terminal is defined to write the line below echo $TERM

If it does not showe vt100 write the lines below: TERM = vt100 export TERM setenv TERM vt100

If the screen turnes black on the Workstation


dtwm # maybe this letter combination on the keyboard will help

Text Editorn Vi
There are two modes: The one is write more The second one is commando-mode (esc) where you can move around the cursor Start vi: vi file name End vi: (esc) Shift ZZ, :wq! q! Till skriv-mode: i ( insert where the cursor is placed ) a ( insert after the cursor ) Moving in the text: (esc) Arrows or page up/down Delete: (esc) x In write mode (esc) dd (esc) :1,$/olle/kalle/g u # delete one line # Replace olle with kalle everywhere in the text # Undo # exit without saving # Creates a file with name file name

Frequently used VI commands:


H j k l w b 0 $ nG control-f control-b # move cursor one character to left # move cursor one line down # move cursor one line up # move cursor one character to right # move cursor one word to right # move cursor one word to left move cursor to beginning of line move cursor to end of line move cursor to line n scroll forward one screen scroll backward one screen

i a dw cw r ~ dd D x ma d`a `a p u . J :w :q! ZZ :r filename

insert to left of current cursor position (end with ESC) append to right of current cursor position (end with ESC) delete current word (end with ESC) change current word (end with ESC) change current character change case (upper-, lower-) of current character delete current line delete portion of current line to right of the cursor delete current character mark currrent position delete everything from the marked position to here go back to the marked position dump out at current place your last deletion (``paste'') undo the last command repeat the last command combine (``join'') next line with this one write file to disk, stay in vi quit VI, do not write file to disk, write file to disk, quit vi read in a copy of the specified file to the current buffer

/string ?string n :s/s1/s2

search forward for string (end with Enter) search backward for string (end with Enter) repeat the last search (``next search'') replace (``substitute'') (the first) s1 in this line by s2 (lr is of form `a,b', where a and b are either explicit line numbers, or . (current line) or $ (last line)

:lr/s/s1/s2/g replace all instances of s1 in the line range lr by s2

:map k s :abb s1 s2 %

map the key k to a string of vi commands s (see below) expand the string s1 in append/insert mode to a string s2 (see below) go to the "mate," if one exists, of this parenthesis or brace or bracket (very useful for programmers!)

How to remote login to a Unix maskin as root


Edit the file .login in /etc/default/.login There is a line including console Comment that line Then it is possible to login to the unix maskin as root. !! It is important that you do this only when it is nescessary !!

How to login to a unix maskin with out need of any passwd


Create the file .rlogin under the / and right the name of the host maskin that will be login with out need of any passwd.

Network info in Windows


Winipcfg way netstat r ping 192.168.18.19 t tracert 192.168.18.19 # Shows IP address info # continuous ping # trace this IP address # Write this in dos window or in run in the start menyn and it will shoe ipaddress,gate-

Network info in Unix


netstat a netstat rn netstat r netstat i netstat s ifconfig a tarceroute 192.168.10.20 arp a arp d ipaddress(hostname) nslookup dig x 128.32.130.2 finger @hugin finger m hugin finger m etxolle@hugin write hugin talk hugin snoop d hme0 snoop v # sends a message to host hugin # chat function # snoopes the network information # snoopes network info in verbose mode # displays information about all the users logged in in the hugin # lists routing tables with numbered information # lists routing tables with name of the hosts # lists the interfaces # lists counters # shows info about the IP addresses # trace this IP address # shows the content of the map tables # deletes the arp entry from the arp table for actuall host # finds the name servers in the network

To login to a CP in the labbnetwork from your unix account


rlogin labgw1.tb username: passwd: ypcat hosts anxadm anxadm # see all MS and CPs # 130.100.165.32

rlogin (name or the IP address of the actual cp or ms you want to login)

System administration stuff

more /etc/vfstab

# Displays the filesystem

How to Determine the Number of Tapes for Full Backup


1. Become root. # ufsdump S filesystem 2. Divide the estimated size by the capacity of the tape to see how many tapes you need. S Displays the estimated number of bytes needed to do the backup.

# ufsdump S /export/home 489472


$ ls | cpio -oc > /dev/rmt/n# Copy All Files in a Directory to a Tape (cpio) $ cpio -civt < /tmp/cpio.file # VerificationCopying All Files in a Directory to a Tape

ExampleCopying All Files in a Directory to a Tape (cpio) $ cd /export/home/kryten $ ls | cpio -oc > /dev/rmt/0 ExampleListing the Files on a Tape (cpio) $ cpio -civt < /dev/rmt/0

Before Backup
/usr/sbin/shutdown y g300 System is being shutdown for backup Unmount all file system exept / and /usr # umount /export/home Check the integrity of the file system data # fsck /export/home Perform a full level backup of the /export/home file system # ufsdump 0uf /dev/rmt/0 /export/home If the bacup tape is installed on another location # ufsdump 0uf host2:/dev/rmt/0 /export/home

Restoring Regular File Systems


# newfs /dev/rdsk/c#t#d#s# # mount /dev/dsk/c#t#d#s# /mnt # cd /mnt # ufrestore rf /dev/rmt/# # rm restoresymtable # cd / # umount /mnt

# fsck /dev/rdsk/c#t#d#s# # ufsdump 0uf /dev/rmt/# /dev/rdsk/c#t#d#s#

Creating a User
admintool & # it is possible to create and delete users and groups

Manually creating a user


useradd u 100 g other d /export/home/potatis m s /bin/ksh c potatis konto potatis usermod d /export/home/potatis1 m l potatis1 potatis# change loginname and home directory for potatis userdel r potatis1 find / -user UID exec rm { } \; groupadd g 301 class groupmod g 400 class # delete the user potatis1 and its home directory # this command will find and delete the user in the maskin # creates the group class with group id 301 # changes the group id for class to 400

User and group info are saved in following files


/etc/passwd /etc/shadow /etc/group

Howto create restricted user


Create the user and choose the shell as /usr/lib/rsh The user will not beable to change directories and with modifying .profile it is possible to define which directories the user will be alowed to do things.

Security
touch /var/adm/loginlog will be stored in to this file. who last last etxolle last reboot rusers l whoami #shows the users logged in to actuall system # shows a history list with all logins # shows information about actuall users logins # shows when the maskin has been rebooted # gives a list with all the users logged in to the remote host # shows the actuall user #Create this file to logg failed loggins to the maskin. After 5 failed atemts the login information

who am I# shows the original user /var/adm/sulog # includes information about all failed su atempts

Changing owner
chown user2 file1 chown R user2 dir1 chgrp ekonomi file1 # changes the owner to user2 for the file file1 # changes owner to user2 for the directory dir1 and including files # changes the group to ekonomi for the file1

Trusted user
Create the files below and add the name of the trusted users. They will be enabled to login with out any passwd. /etc/hosts.equiv /.rhosts

Mounting CDROM
ps ef|grep vold /etc/init.d/volmgt start cd /cdrom ls al #cehck that link has been created if not then we must mount the cdrom manually lrwxrwxrwx 1 root nobody 15 Dec 18:50 cdrom0 ->./disksuite_4_0/ /etc/init.d/volmgt stop # to stop the Volume Management deamon # check if Volume Management deamon is running # to start Volume management

mount F hsfs o ro /dev/dsk/c0t6d0s0 /cdrom#to mount the SCSI cdrom

DAT tape device in Solaris


/dev/rmt/0n (for no tape rewind); /dev/rmt/0 (for tape rewind). For example, to restore (with rewind) all files from a tar tape into the current directory the command is: tar xfv /dev/rmt/0 If using a DAT device attached to this Sun Solaris workstation <device_file> is: /dev/rmt/1n (for no tape rewind); /dev/rmt/1 (for tape rewind). Workstation B25B-07 (Engineering Building 25) If using a DAT device attached to this Sun Solaris workstation <device_file> is: /dev/rmt/0n (for no tape rewind); /dev/rmt/0 (for tape rewind). For example, to archive (with no rewind) the contents of the directory work onto a new tape with no rewind the tar command is: tar cfv /dev/rmt/0n work 13 UNIX Tape Handling Contents of this section Tapes are addressed under UNIX by writing data to and from device files associated with the tape unit. Here is a list of standard device files at IUCF. These device names are printed on most tape units. /dev/rmt/ct1_h tape unit 1, high density, rewind tape after operation /dev/rmt/ct1_hn tape unit 1, high density, no rewind /dev/rmt/ct1_l tape unit 1, low density, rewind tape after operation /dev/rmt/ct1_ln tape unit 1, low density, no rewind /dev/rmt/ct1_c tape unit 1, high density compressed, rewind tape after operation /dev/rmt/ct1_cn tape unit 1, high density compressed , no rewind /dev/rmt/ct2_cn tape unit 2, high density compressed , no rewind 13.1 Tar The standard way to archive data to tape under UNIX is to use the tar program. It can also be used to transport a directory of files as a single file. You can create or read a tar file on any UNIX host. Using tar has sev-

eral advantages. It preserves the directory structure, the ownership, permissions, and directory hierarchy of the files it saves. IUCF has two tar programs. The HP supplied tar, and the GNU version of tar. The GNU version has one nice advantage in that it is tightly integrated with gzip and gunzip, the GNU compression programs. tar cvf /dev/rmt/ct1_cn ~ make a backup of your home directory to the compressed tape device tar cvf /tmp/myfiles.tar ~ make a backup of your home directory to the file myfiles.tar in the tmp directory tar xvf /dev/rmt/ct1_cn restore your directory from tape tar cvf /tmp/my.tar ~ create a backup of your directory to /tmp/my.tar gtar cvzf /tmp/my.tar.gz ~ create a compressed backup of your directory gtar xvzf /tmp/my.tar.gz unpack your compressed backup from the root directory When you tar files the entire path you specify on the tar command line is written before each file name in the archive. Thus when you untar the archive, the files will be placed as the path is specified on the original command line. For example, if you tar up a directory like this: dwwillia@clio: $ pwd /users2/dwwillia/Projects *** CREATE TAR FILE *** dwwillia@clio: $ tar cf scripts.tar Scripts/ dwwillia@clio: $ ls -l scripts.tar -rw-r--r-- 1 dwwillia users 10240 Jun 15 15:10 scripts.tar *** LIST CONTENTS OF TAR, PATHS ARE STORED WITH FILES *** dwwillia@clio: $ tar tf scripts.tar Scripts/ Scripts/fix.my.account *** GO TO /TMP. UNTAR FILE. IT CREATES /tmp/Scripts *** dwwillia@clio: $ cd /tmp dwwillia@clio: $ tar xvf ~/Projects/scripts.tar Scripts/ Scripts/fix.my.account 13.2 Copytape Copytape is useful when you need to duplicate a tape. You should have access to a machine with two tape units. Copy the tapes with a command like copytape /dev/rmt/ct1_h /dev/rmt/ct2_h How to add the tape drive You add a tape drive by running "mkdev tape". This asks questions about the type of tape and its configuration. If you have more than one tape drive, you may want to make one of them the "default"- all that means is that / dev/rct0 and /dev/xct0 will be linked (using "ln") to point at that tape. If you have a SCSI tape drive, but aren't sure about its configuration, you can use "sconf" on modern releases (don't use this prior to OSR5.0.5 - it existed, but could crash your system). Here's the output of "sconf -v" on one of my machines: Sdskalad0000 Sdskalad0010 Stpalad0030 Sdskalad0040 Sromalad0060 Pushing the eject button doesn't work.

DAT tape doesn't eject

First, check that no process is using the tape: fuser /dev/rStp0 If that's not the case, the tape may have been misconfigured. Run mkdev tape and be sure that it knows that this is a DAT and not a Generic. It's easy to make that mistake when running 'mkdev tape': follow the prompts carefully and press "ENTER" for the defaults until you get to the menu that askes what kind of tape it is. I did once have a DAT tape that would not eject without rebooting, but I couldn't find any reason for it, so we replaced it. I took the unit to another machine (same OS and version), and there it would eject fine, but then you couldn't put a new tape in without rebooting, so it didn't help much! tape: can't open '/dev/xct0':No such device Using "tape status" (or any "tape" command) doesn't work and complains with this message. This could simply mean that this is not your default tape drive. If you can tar cvf /dev/rStp0 . (or rStp1 if this was the second drive), but cannot do "tape" commands, then run mkdev tape again and select the default tape drive. Or for a quicker test: rm /dev/xct0 mknod /dev/xct0 c 46 128 (assuming rStp0) and then try "tape status" etc. What's happening here is the tape commands use ioctl calls to query the tape device. Ioctl commands are just special commands that a device driver can use to get information from a device. Most drivers are written to recognize a special minor number as the ioctl device; this simplifies the driver and allows any data to be written to the ordinary device. For tapes, the minor number for ioctl is 128. The ioctl devices are /dev/xct0, /dev/xStp0, etc. If you have created a SCSI tape, but didn't set it as default, then the /dev/xct0 is crw-r--r-- 1 root sys 10,128 Sep 13 10:35 /dev/xct0 which has the right minor number, but the major (10) is for a cartridge tape, not SCSI. You could fix this as suggested above, or by editing /etc/default/tape and changing the device = /dev/xct0 to device = /dev/xStp0

Retensioning, formatting, erasing

Various tape commands work with different types of tapes. Some tapes require formatting, some have the ability to be retensioned, some don't. You can get a list of tape commands by typing tape 2>&1 | more or man tape

Tapes from other systems/drives

A DAT tape is a DAT tape, right? If you used cpio to create a tape on System A, you should be able to read it with a different DAT on system B. Yes, but.. The first problem you can run into is hardware compression. Different manufacturers can use different schemes. Therefore, if you are planning to transfer to another system, you want compression turned off. To do that on OSR5, you'd say tape -a 0 setcomp Another area of problem is hardware block size. The defaults can vary, so you need to explicitly set it to match. To find out what the block size is, do: tape getblk (note- you may need a tape in the drive to do this!) Once you know, you can set it to match on the other machine: tape -a 0 setblk tape -a 512 setblk

Вам также может понравиться