Vous êtes sur la page 1sur 42

Basic UNIX commands Note: not all of these are actually part of UNIX itself, and you may

not find them on all UNIX machines. But they can all be used on turing in essentially the same way, by typing the command and hitting return. Note that some of these commands are different on nonSolaris machines - see SunOS differences. If you've made a typo, the easiest thing to do is hit CTRL-u to cancel the whole line. But you can also edit the command line (see the guide to More UNIX). UNIX is case-sensitive. Files ls --- lists your files ls -l --- lists your files in 'long format', which contains lots of useful information, e.g. the exact size of the file, who owns the file and who has the right to look at it, and when it was last modified. ls -a --- lists all files, including the ones whose filenames begin in a dot, which you do not always want to see. There are many more options, for example to list files by size, by date, recursively etc. more filename --- shows the first part of a file, just as much as will fit on one screen. Just hit the space bar to see more or q to quit. You can use /pattern to search for a pattern. emacs filename --- is an editor that lets you create and edit a file. See the emacs page. mv filename1 filename2 --- moves a file (i.e. gives it a different name, or moves it into a different directory (see below) cp filename1 filename2 --- copies a file rm filename --- removes a file. It is wise to use the option rm -i, which will ask you for confirmation before actually deleting anything. You can make this your default by making an alias in your .cshrc file. diff filename1 filename2 --- compares files, and shows where they differ wc filename --- tells you how many lines, words, and characters there are in a file chmod options filename --- lets you change the read, write, and execute permissions on your files. The default is that only you can look at them and change them, but you may sometimes want to change these permissions. For example, chmod o+r filename will make the file readable for everyone, and chmod o-r filename will make it unreadable for others again. Note that for someone to be able to actually look at the file the directories it is in need to be at least executable. See help protection for more details. File Compression gzip filename --- compresses files, so that they take up much less space. Usually text files compress to about half their original size, but it depends very much on the size of the file and the nature of the contents. There are other tools for this purpose, too (e.g. compress), but gzip usually gives the highest compression rate. Gzip produces files with the ending '.gz' appended to the original filename. gunzip filename --- uncompresses files compressed by gzip. gzcat filename --- lets you look at a gzipped file without actually having to gunzip it (same as gunzip -c). You can even print it directly, using gzcat filename | lpr printing lpr filename --- print. Use the -P option to specify the printer name if you want to use a printer other than your default printer. For example, if you want to print double-sided, use 'lpr -Pvalkyr-d', or if you're at CSLI, you may want to use 'lpr -Pcord115-d'. See 'help printers' for more information about printers and their locations.

lpq --- check out the printer queue, e.g. to get the number needed for removal, or to see how many other files will be printed before yours will come out lprm jobnumber --- remove something from the printer queue. You can find the job number by using lpq. Theoretically you also have to specify a printer name, but this isn't necessary as long as you use your default printer in the department. genscript --- converts plain text files into postscript for printing, and gives you some options for formatting. Consider making an alias like alias ecop 'genscript -2 -r \!* | lpr -h -Pvalkyr' to print two pages on one piece of paper. dvips filename --- print .dvi files (i.e. files produced by LaTeX). You can use dviselect to print only selected pages. See the LaTeX page for more information about how to save paper when printing drafts. Directories Directories, like folders on a Macintosh, are used to group files together in a hierarchical structure. mkdir dirname --- make a new directory cd dirname --- change directory. You basically 'go' to another directory, and you will see the files in that directory when you do 'ls'. You always start out in your 'home directory', and you can get back there by typing 'cd' without arguments. 'cd ..' will get you one level up from your current position. You don't have to walk along step by step - you can make big leaps or avoid walking around by specifying pathnames. pwd --- tells you where you currently are. Finding things ff --- find files anywhere on the system. This can be extremely useful if you've forgotten in which directory you put a file, but do remember the name. In fact, if you use ff -p you don't even need the full name, just the beginning. This can also be useful for finding other things on the system, e.g. documentation. grep string filename(s) --- looks for the string in the files. This can be useful a lot of purposes, e.g. finding the right file among many, figuring out which is the right version of something, and even doing serious corpus work. grep comes in several varieties (grep, egrep, and fgrep) and has a lot of very flexible options. Check out the man pages if this sounds good to you. About other people w --- tells you who's logged in, and what they're doing. Especially useful: the 'idle' part. This allows you to see whether they're actually sitting there typing away at their keyboards right at the moment. who --- tells you who's logged on, and where they're coming from. Useful if you're looking for someone who's actually physically in the same building as you, or in some other particular location. finger username --- gives you lots of information about that user, e.g. when they last read their mail and whether they're logged in. Often people put other practical information, such as phone numbers and addresses, in a file called .plan. This information is also displayed by 'finger'. last -1 username --- tells you when the user last logged on and off and from where. Without any options, last will give you a list of everyone's logins. talk username --- lets you have a (typed) conversation with another user write username --- lets you exchange one-line messages with another user elm --- lets you send e-mail messages to people around the world (and, of course, read them). It's not the only mailer you can use, but the one we recommend. See the elm page, and find out about the departmental mailing lists (which you can also find in /user/linguistics/helpfile). About your (electronic) self

whoami --- returns your username. Sounds useless, but isn't. You may need to find out who it is who forgot to log out somewhere, and make sure *you* have logged out. finger & .plan files of course you can finger yourself, too. That can be useful e.g. as a quick check whether you got new mail. Try to create a useful .plan file soon. Look at other people's .plan files for ideas. The file needs to be readable for everyone in order to be visible through 'finger'. Do 'chmod a+r .plan' if necessary. You should realize that this information is accessible from anywhere in the world, not just to other people on turing. passwd --- lets you change your password, which you should do regularly (at least once a year). See the LRB guide and/or look at help password. ps -u yourusername --- lists your processes. Contains lots of information about them, including the process ID, which you need if you have to kill a process. Normally, when you have been kicked out of a dialin session or have otherwise managed to get yourself disconnected abruptly, this list will contain the processes you need to kill. Those may include the shell (tcsh or whatever you're using), and anything you were running, for example emacs or elm. Be careful not to kill your current shell - the one with the number closer to the one of the ps command you're currently running. But if it happens, don't panic. Just try again :) If you're using an X-display you may have to kill some X processes before you can start them again. These will show only when you use ps -efl, because they're root processes. kill PID --- kills (ends) the processes with the ID you gave. This works only for your own processes, of course. Get the ID by using ps. If the process doesn't 'die' properly, use the option -9. But attempt without that option first, because it doesn't give the process a chance to finish possibly important business before dying. You may need to kill processes for example if your modem connection was interrupted and you didn't get logged out properly, which sometimes happens. quota -v --- show what your disk quota is (i.e. how much space you have to store files), how much you're actually using, and in case you've exceeded your quota (which you'll be given an automatic warning about by the system) how much time you have left to sort them out (by deleting or gzipping some, or moving them to your own computer). du filename --- shows the disk usage of the files and directories in filename (without argument the current directory is used). du -s gives only a total. last yourusername --- lists your last logins. Can be a useful memory aid for when you were where, how long you've been working for, and keeping track of your phonebill if you're making a non-local phonecall for dialling in. Connecting to the outside world nn --- allows you to read news. It will first let you read the news local to turing, and then the remote news. If you want to read only the local or remote news, you can use nnl or nnr, respectively. To learn more about nn type nn, then \tty{:man}, then \tty{=.*}, then \tty{Z}, then hit the space bar to step through the manual. Or look at the man page. Or check out the hypertext nn FAQ - probably the easiest and most fun way to go. rlogin hostname --- lets you connect to a remote host telnet hostname --- also lets you connect to a remote host. Use rlogin whenever possible. ftp hostname --- lets you download files from a remote host which is set up as an ftp-server. This is a common method for exchanging academic papers and drafts. If you need to make a paper of yours available in this way, you can (temporarily) put a copy in /user/ftp/pub/TMP. For more permanent solutions, ask Emma. The most important commands within ftp are get for getting files from the remote machine, and put for putting them there (mget and mput let you specify more than one file at once). Sounds straightforward, but be sure not to confuse the two, especially when your physical location doesn't correspond to the direction of the ftp

connection you're making. ftp just overwrites files with the same filename. If you're transferring anything other than ASCII text, use binary mode. lynx --- lets you browse the web from an ordinary terminal. Of course you can see only the text, not the pictures. You can type any URL as an argument to the G command. When you're doing this from any Stanford host you can leave out the .stanford.edu part of the URL when connecting to Stanford URLs. Type H at any time to learn more about lynx, and Q to exit. Miscellaneous tools webster word --- looks up the word in an electronic version of Webster's dictionary and returns the definition(s) date --- shows the current date and time. cal --- shows a calendar of the current month. Use e.g., 'cal 10 1995' to get that for October 95, or 'cal 1995' to get the whole year. You can find out more about these commands by looking up their manpages: man commandname --- shows you the manual page for the command For further ways of obtaining help, look at the pages with electronic sources of information and non-electronic sources. More UNIX commands -------------------------------------------------------------------------------Back up to the Main Computing Page --------------------------------------------------------------------------------

More UNIX Commands I have noticed that the overwhelming majority of visitors come to this page via a Lycos search. This page is probably *not* what you're looking for - see the links at the bottom of this page for more useful information! jobs --- lists your currently active jobs (those that you put in the background) and their job numbers. Useful to determine which one you want to foreground if you have lots of them. bg --- background a job after suspending it. fg %jobnumber --- foreground a job !! --- repeat the previous command (but CTRL-p, is safer, because you have hit return in addition) !pattern --- repeat the last command that starts with pattern echo $VARIABLE --- shows the value of an environment variable setenv --- lets you set environment variables. For example, if you typed a wrong value for the TERM variable when logging in, you don't have to log out and start over, but you can just do setenv TERM vt100 (or whatever). To see what all your environment variables are set to, type env. The one that you're most likely to have to set is the DISPLAY variable, when using an X-display. unset VAR --- lets you un-set environment variables. Useful, for example, if you've usually set autologout but want to stay logged on for a while without typing for some reason, or if you set the DISPLAY variable automatically but want to avoid opening windows for some reason. source filename --- you need to source your dotfiles after making changes for them to take effect (or log off and in again) load --- will show you the load average graphically

ispell filename --- will check the spelling in your file. If you're running it on a LaTeX file use the -T option to tell it to ignore the LaTeX commands. You can create and use your own dictionary to avoid having it tell you that your own name, those of fellow linguists, and linguistics terminology are a typos in every paper you write. weblint --- checks the syntax of html files latex2html --- translates LaTeX files into HTML wn word option --- lets you access the WordNet database and display, for example, synonyms, hypernyms, or hyponyms, depending on the option you select Command editing in the tcsh These things are the same as in emacs: Backspace --- delete previous character CTRL-d --- delete next character CTRL-k --- delete rest of line CTRL-a --- go to start of line CTRL-e --- go to end of line CTRL-b --- go backwards without deleting CTRL-f --- go forward without deleting Other useful things TAB --- complete filename or command up to the point of uniqueness CTRL-u --- cancel whole line CTRL-p --- show the last command typed, then the one before that, etc. (you can also use the cursor up key for this) CTRL-n --- go forwards in the history of commands (you can also use the cursor down key for this) CTRL-c --- cancel the processes after it has started CTRL-z --- suspend a running process (e.g. in order to do something else in between) you can then put the process in the background with bg CTRL-l --- redraws the screen | (piping) --- Lets you execute any number of commands in a sequence. The second command will be executed once the first is done, and so forth, using the previous command's output as input. You can achieve the same effect by putting the output in a file and giving the filename as an argument to the second command, but that would be much more complicated, and you'd have to remember to remove all the junkfiles afterwards. Some examples that show the usefulness of this: ls | more --- will show you one screenful at a time, which is useful with any command that will produce a lot of output, e.g. also ps -aux man ls | grep time --- checks whether the man page for ls has something to say about listing files by time - very useful when you have a suspicion some command may be capable of doing what you want, but you aren't sure. ls -lR | grep dvi --- will show you all your dvi files - useful to solve disk space problems, since they're large and usually can be deleted.

Learn UNIX in 10 minutes. Version 1.3 Preface This is something that I had given out to students (CAD user training) in years past. The purpose was to have on one page the basics commands for getting started using the UNIX shell (so that they didn't call me asking what to do the first time someone gave them a tape). This document is copyrighted but freely redistributable under the terms of the GFDL . Have an idea for this page? Send me patches, comments, corrections, about whatever you think is wrong or should be included. I am always happy to hear from you. Please include the word "UNIX" in your subject. Sections: Directories: Moving around the file system: Listing directory contents: Changing file permissions and attributes Moving, renaming, and copying files: Viewing and editing files: Shells Environment variables Interactive History Filename Completion Bash is the way cool shell. Redirection: Pipes: Command Substitution Searching for strings in files: The grep command Searching for files : The find command Reading and writing tapes, backups, and archives: The tar command File compression: compress, gzip, and bzip2 Looking for help: The man and apropos commands Basics of the vi editor FAQs ************************************************************************** **************** Basic UNIX Command Line (shell) navigation : Last revised May 17 2001 ************************************************************************** **************** Directories: File and directory paths in UNIX use the forward slash "/" to separate directory names in a path.

examples: / "root" directory /usr directory usr (sub-directory of / "root" directory) /usr/STRIM100 STRIM100 is a subdirectory of /usr Moving around the file system: pwd Show the "present working directory", or current directory. cd Change current directory to your HOME directory. cd /usr/STRIM100 Change current directory to /usr/STRIM100. cd INIT Change current directory to INIT which is a sub-directory of the current directory. cd .. Change current directory to the parent directory of the current directory. cd $STRMWORK Change current directory to the directory defined by the environment variable 'STRMWORK'. cd ~bob Change the current directory to the user bob's home directory (if you have permission). Listing directory contents: ls list a directory ls -l list a directory in long ( detailed ) format for example: $ ls -l drwxr-xr-x 4 cliff user 1024 Jun 18 09:40 WAITRON_EARNINGS -rw-r--r-- 1 cliff user 767392 Jun 6 14:28 scanlib.tar.gz ^^ ^ ^ ^ ^ ^ ^ ^ ^ ^ || | | | | | | | | | | | | | | owner group size date time name | | | | number of links to file or directory contents | | | permissions for world | | permissions for members of group | permissions for owner of file: r = read, w = write, x = execute -=no permission type of file: - = normal file, d=directory, l = symbolic link, and others... ls -a List the current directory including hidden files. Hidden files start with "." ls -ld * List all the file and directory names in the current directory using long format. Without the "d" option, ls would list the contents of any sub-directory of the current. With the "d" option, ls just lists them like regular files. Changing file permissions and attributes

chmod 755 file Changes the permissions of file to be rwx for the owner, and rx for the group and the world. (7 = rwx = 111 binary. 5 = r-x = 101 binary) chgrp user file Makes file belong to the group user. chown cliff file Makes cliff the owner of file. chown -R cliff dir Makes cliff the owner of dir and everything in its directory tree. You must be the owner of the file/directory or be root before you can do any of these things. Moving, renaming, and copying files: cp file1 file2 copy a file mv file1 newname move or rename a file mv file1 ~/AAA/ move file1 into sub-directory AAA in your home directory. rm file1 [file2 ...] remove or delete a file rm -r dir1 [dir2...] recursivly remove a directory and its contents BE CAREFUL! mkdir dir1 [dir2...] create directories mkdir -p dirpath create the directory dirpath, including all implied directories in the path. rmdir dir1 [dir2...] remove an empty directory Viewing and editing files: cat filename Dump a file to the screen in ascii. more filename Progressively dump a file to the screen: ENTER = one line down SPACEBAR = page down q=quit less filename Like more, but you can use Page-Up too. Not on all systems. vi filename Edit a file using the vi editor. All UNIX systems will have vi in some form. emacs filename Edit a file using the emacs editor. Not all systems will have emacs. head filename Show the first few lines of a file. head -n filename Show the first n lines of a file. tail filename Show the last few lines of a file. tail -n filename Show the last n lines of a file. Shells The behavior of the command line interface will differ slightly depending on the shell program that is being used. Depending on the shell used, some extra behaviors can be quite nifty. You can find out what shell you are using by the command: echo $SHELL Of course you can create a file with a list of shell commands and execute it like

a program to perform a task. This is called a shell script. This is in fact the primary purpose of most shells, not the interactive command line behavior. Environment variables You can teach your shell to remember things for later using environment variables. For example under the bash shell: export CASROOT=/usr/local/CAS3.0 Defines the variable CASROOT with the value /usr/local/CAS3.0. export LD_LIBRARY_PATH=$CASROOT/Linux/lib Defines the variable LD_LIBRARY_PATH with the value of CASROOT with /Linux/lib appended, or /usr/local/CAS3.0/Linux/lib By prefixing $ to the variable name, you can evaluate it in any command: cd $CASROOT Changes your present working directory to the value of CASROOT

echo $CASROOT Prints out the value of CASROOT, or /usr/local/CAS3.0 printenv CASROOT Does the same thing in bash and some other shells. Interactive History A feature of bash and tcsh (and sometimes others) you can use the up-arrow keys to access your previous commands, edit them, and re-execute them. Filename Completion A feature of bash and tcsh (and possibly others) you can use the TAB key to complete a partially typed filename. For example if you have a file called constantine-monks-and-willy-wonka.txt in your directory and want to edit it you can type 'vi const', hit the TAB key, and the shell will fill in the rest of the name for you (provided the completion is unique). Bash is the way cool shell. Bash will even complete the name of commands and environment variables. And if there are multiple completions, if you hit TAB twice bash will show you all the completions. Bash is the default user shell for most Linux systems.

Redirection: grep string filename > newfile Redirects the output of the above grep command to a file 'newfile'. grep string filename >> existfile Appends the output of the grep command to the end of 'existfile'. The redirection directives, > and >> can be used on the output of most commands to direct their output to a file. Pipes: The pipe symbol "|" is used to direct the output of one command to the input of another. For example: ls -l | more This commands takes the output of the long format directory list command "ls -l" and pipes it through the more command (also known as a filter). In this case a very long list of files can be viewed a page at a time. du -sc * | sort -n | tail The command "du -sc" lists the sizes of all files and directories in the current working directory. That is piped through "sort -n" which orders the output from smallest to largest size. Finally, that output is piped through "tail" which displays only the last few (which just happen to be the largest) results. Command Substitution You can use the output of one command as an input to another command in another way called command substitution. Command substitution is invoked when by enclosing the substituted command in backwards single quotes. For example: cat `find . -name aaa.txt` which will cat ( dump to the screen ) all the files named aaa.txt that exist in the current directory or in any subdirectory tree.

Searching for strings in files: The grep command grep string filename prints all the lines in a file that contain the string Searching for files : The find command

find search_path -name filename find . -name aaa.txt Finds all the files named aaa.txt in the current directory or any subdirectory tree. find / -name vimrc Find all the files named 'vimrc' anywhere on the system. find /usr/local/games -name "*xpilot*" Find all files whose names contain the string 'xpilot' which exist within the '/usr/local/games' directory tree. Reading and writing tapes, backups, and archives: The tar command The tar command stands for "tape archive". It is the "standard" way to read and write archives (collections of files and whole directory trees). Often you will find archives of stuff with names like stuff.tar, or stuff.tar.gz. This is stuff in a tar archive, and stuff in a tar archive which has been compressed using the gzip compression program respectivly. Chances are that if someone gives you a tape written on a UNIX system, it will be in tar format, and you will use tar (and your tape drive) to read it. Likewise, if you want to write a tape to give to someone else, you should probably use tar as well. Tar examples: tar xv Extracts (x) files from the default tape drive while listing (v = verbose) the file names to the screen. tar tv Lists the files from the default tape device without extracting them. tar cv file1 file2 Write files 'file1' and 'file2' to the default tape device. tar cvf archive.tar file1 [file2...] Create a tar archive as a file "archive.tar" containing file1, file2...etc. tar xvf archive.tar extract from the archive file tar cvfz archive.tar.gz dname Create a gzip compressed tar archive containing everything in the directory 'dname'. This does not work with all versions of tar. tar xvfz archive.tar.gz Extract a gzip compressed tar archive. Does not work with all versions of tar. tar cvfI archive.tar.bz2 dname Create a bz2 compressed tar archive. Does not work with all versions of tar File compression: compress, gzip, and bzip2

The standard UNIX compression commands are compress and uncompress. Compressed files have a suffix .Z added to their name. For example: compress part.igs Creates a compressed file part.igs.Z uncompress part.igs Uncompresseis part.igs from the compressed file part.igs.Z. Note the .Z is not required. Another common compression utility is gzip (and gunzip). These are the GNU compress and uncompress utilities. gzip usually gives better compression than standard compress, but may not be installed on all systems. The suffix for gzipped files is .gz gzip part.igs Creates a compressed file part.igs.gz gunzip part.igs Extracts the original file from part.igs.gz The bzip2 utility has (in general) even better compression than gzip, but at the cost of longer times to compress and uncompress the files. It is not as common a utility as gzip, but is becoming more generally available. bzip2 part.igs Create a compressed Iges file part.igs.bz2 bunzip2 part.igs.bz2 Uncompress the compressed iges file.

Looking for help: The man and apropos commands Most of the commands have a manual page which give sometimes useful, often more or less detailed, sometimes cryptic and unfathomable discriptions of their usage. Some say they are called man pages because they are only for real men. Example: man ls Shows the manual page for the ls command

You can search through the man pages using apropos Example: apropos build "build" Shows a list of all the man pages whose discriptions contain the word

Do a man apropos for detailed help on apropos. Basics of the vi editor Opening a file vi filename Creating text

Edit modes: These keys enter editing modes and type in the text of your document. i Insert before current cursor position I Insert at beginning of current line a Insert (append) after current cursor position A Append to end of line r Replace 1 character R Replace mode <ESC> Terminate insertion or overwrite mode Deletion of text x Delete single character dd Delete current line and put in buffer ndd Delete n lines (n is a number) and put them in buffer J Attaches the next line to the end of the current line (deletes carriage return). Oops u Undo last command

cut and paste yy Yank current line into buffer nyy Yank n lines into buffer p Put the contents of the buffer after the current line P Put the contents of the buffer before the current line cursor positioning ^d Page down ^u Page up :n Position cursor at line n :$ Position cursor at end of file ^g Display current line number h,j,k,l Left,Down,Up, and Right respectivly. Your arrow keys should also work if if your keyboard mappings are anywhere near sane. string substitution :n1,n2:s/string1/string2/[g] Substitute string2 for string1 on lines n1 to n2. If g is included (meaning global), all instances of string1 on each line are substituted. If g is not included, only the first instance per matching line is substituted. ^ matches start of line . matches any single character $ matches end of line These and other "special characters" (like the forward slash) can be "escaped" with \

i.e to match the string "/usr/STRIM100/SOFT" say "\/usr\/STRIM100\/SOFT" Examples: :1,$:s/dog/cat/g :23,25:/frog/bird/ Substitute 'cat' for 'dog', every instance for the entire file - lines 1 to $ (end of file) Substitute 'bird' for 'frog' on lines 23 through 25. Only the first instance on each line is substituted.

Saving and quitting and other "ex" commands These commands are all prefixed by pressing colon (:) and then entered in the lower left corner of the window. They are called "ex" commands because they are commands of the ex text editor - the precursor line editor to the screen editor vi. You cannot enter an "ex" command when you are in an edit mode (typing text onto the screen) Press <ESC> to exit from an editing mode. :w Write the current file. :w new.file Write the file to the name 'new.file'. :w! existing.file Overwrite an existing file with the file currently being edited. :wq Write the file and quit. :q Quit. :q! Quit with no changes. :e filename Open the file 'filename' for editing.

:set number Turns on line numbering :set nonumber Turns off line numbering FAQs The USENET FAQs should be the first place you look for an answer to specific questions. You can find most of them at RTFM The contents of this directory includes vi, bash, and comp.unix.questions FAQs. Searching USENET archives are very useful too. google.com has a USENET archive (formerly Deja.com's) . Advanced Group Search rules. This document was converted from plain text using Vim and then hacked. Vim is the best version of the one true text editor: vi. Copyright (c) 2000-2006 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation;

with Invariant Section: Preface, with Front-Cover Texts, and with no Back-Cover Texts. A copy of the license can be found on the GNU web site here.

Unix commands
Misc commands File management comparison and Text processing

searching Shell and other programming communications Storage commands System status

Misc commands
man,banner,cal, calendar,clear,nohup, tty .

Man

ual command. man man This is help command, and will explains you about online manual pages you can also use man in conjunction with any command to learn more about that command for example.

man ls will explain about the ls command and how you can use it. man -k pattern command will search for the pattern in given command.

Banner
# # # # # # # ## # ## ## # #

command. banner prints characters in a sort of ascii art poster, for example to print wait in big letters. I will type banner wait at unix command line or in my script. This is how it will look.

## # # ###### # # # # # #

# # # # # #

##### # # # # #

Cal

command cal command will print the calander on current month by default. If you want to print calander of august of 1965. That's eightht month of 1965. cal 8 1965 will print following results.

August 1965 S M Tu W Th F S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Clear command
clear command clears the screen and puts cursor at beginning of first line.

Calendar
calendar command reads your calendar For example in your calendar file if you have this file and

command displays

only

lines

with

current

day.

12/20 1/15

Test new software. Test newly developed 3270 product.

1/20

Install memory on HP 9000 machine.

On dec 20th the first line will be displayed. you can use this command with your crontab file or in your login files.

Nohup

command. nohup command if added in front of any command will continue running the command or process even if you shut down your terminal or close your session to machine. For exmaple, if I want to run a job that takes lot of time and must be run from terminal and is called update_entries_tonight . nohup update_entries_tonight will run the job even if terminal is shut down in middle of this job.

Tty
Tty tty options command will display

command your

terminal.

Syntax

is

Options

-l will print the synchronous line number. -s will return only the codes: 0 (a terminal), 1 (not a terminal), 2 (invalid options) (good for scripts)

back to top of misc commands back to top of page

File Management commands.


cat,cd, cp, file,head,tail, ln,ls,mkdir ,more,mv, pwd, rcp,rm, rmdir, wc.

Pwd

command. 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

command 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 -Fxwill list files and directory names will be followed by slash. ls -Rwill 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 Cd

command. mkdir sandeep will create new directory, i.e. here sandeep directory is created.

command. cd sandeep will change directory from current directory to sandeep directory. Use pwd to check your current directory and ls to see if sandeep directory is there or not. You can then use cd sandeep to change the directory to this new directory.

Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).

Head

command. head filename by default will display the first 10 lines of a If you want first 50 lines you can use head -50 filename or for 37 lines head -37 filename and so forth.

file.

Tail

command. tail filename by default will display the last If you want last 50 lines then you can use tail -50 filename.

10

lines

of

file.

More command. 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

command wc command counts the characters, words or lines in a file depending upon the option.

Options

wc -l filename will print total number of lines in a file. wc -w filename will print total number of words in a file. wc -c filename will print total number of characters in a file.

File

command. 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 binariy file in microsoft word. I will get file resume.doc

resume1.doc:

data ascii text

file cal.txt

cal.txt:

Cp

command.

cp command copies a file. If I want to copy a file named oldfile in a current directory to a file named newfile in a current directory. cp oldfile newfile If I want to copy oldfile to other directory for example /tmp then cp oldfile /tmp/newfile. Useful options available with cp are -p and -r . -p options preserves the modification time and permissions, -r recursively copy a directory and its files, duplicating the tree structure.

Rcp

command.

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.

Mv

command. mv command is used to move a file from one directory to another directory or to rename a file.

Some examples:

mv oldfile newfile will rename oldfile to newfile. mv -i oldfile newfile for confirmation prompt. mv -f oldfile newfile will force the rename even if target file exists. mv * /usr/bajwa/ will move all the files in current directory to /usr/bajwa directory.

Ln

command. 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.

Rm
To delete files use rm command.

command.

Options:

rm oldfile will delete file named oldfile. rm -f option will remove write-protected files without prompting.

rm -r option will delete the entire directory as well as all the subdirectories, very dangerous command.

Rmdir

command. rmdir command will remove directory or directories if a directory is empty.

Options:

rm -r directory_name will remove all files even if directory is not empty. rmdir sandeep is how you use it to remove sandeep directory. rmdir -p will remove directories and any parent directories that are empty. rmdir -s will suppress standard error messages caused by -p.

back to top of File management commands back to top of page

Comparison and Searching


diff,dircmp, cmp, grep, find.

Diff
diff command will compare Here I have two Contents of fileone are the two files ascii text

command. and print out files. fileone

the

differences and file

between. two.

This this this this this

is is is is is

first file second line third line different as;lkdjf not different

filetwo contains
This this this this this is is is is is first file second line third line different xxxxxxxas;lkdjf not different

diff fileone filetwo will give following output


4c4 < this is different --> this is different as;lkdjf xxxxxxxas;lkdjf

Cmp

command. cmp command compares the two files. For exmaple I have two different files fileone and filetwo. cmp fileone filetwo will give me

fileone filetwo differ: char 80, line 4

if I run cmp command on similar files nothing is returned. -s command can be used to return exit codes. i.e. return 0 if files are identical, 1 if files are different, 2 if files are inaccessible. This following command prints a message 'no changes' if files are same cmp -s fileone file1 && echo 'no changes' .
no changes

Dircmp
Dec

Command. dircmp command compares two directories. If i have two directories in my home directory named dirone and dirtwo and each has 5-10 files in it. Then dircmp dirone dirtwo will return this

9 16:06 1997

dirone only and dirtwo only Page 1 ./fourth.txt ./rmt.txt ./te.txt ./third.txt

./cal.txt ./dohazaar.txt ./four.txt ./junk.txt ./test.txt

Grep

Command

grep command is the most useful search command. You can use it to find processes running on system, to find a pattern in a file, etc. It can be used to search one or more files to match an expression. It can also be used in conjunction with other commands as in this following example, output of ps command is passed to grep command, here it means search all processes in system and find the pattern sleep. ps -ef | grep sleep will display all the sleep processes running in the system as follows. ops dxi ops ops ops dxi ops dxi ops ops ssb pjk 12964 12974 12941 12847 12894 13067 13046 12956 12965 12989 13069 27049 25853 15640 25688 25812 25834 27253 25761 13078 25737 25778 26758 3353 0 0 0 0 0 2 0 0 0 0 2 0 16:12:24 16:12:25 16:12:21 16:11:59 16:12:12 16:12:48 16:12:44 16:12:23 16:12:24 16:12:28 16:12:49 15:20:23 ttyAE/AAES ttyAH/AAHP ttyAE/AAEt ttyAH/AAH6 ttyAE/AAEX ttyAE/ABEY ttyAE/AAE0 ttyAG/AAG+ ttyAE/AAEp ttyAH/AAHv ttyAH/AAHs ? 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 0:00 sleep 60 sleep 60 sleep 60 sleep 60 sleep 60 sleep 1 sleep 60 sleep 60 sleep 60 sleep 60 grep sleep sleep 3600

Options:

-b option will precede each line with its block number. -c option will only print the count of matched lines. -i ignores uppercase and lowercase distinctions. -l lists filenames but not matched lines.

other associated commands with grep are egrep and fgrep. egrep typically runs faster. for more information type man egrep or man fgrep in your system.

Find

command. Find command is a extremely useful command. you can search for any file anywhere using this command provided that file and directory you are searching has read write attributes set to you ,your, group or all. Find descends directory tree beginning at each pathname and finds the files that meet the specified conditions. Here are some examples.

Some

Examples:
in named list your home directory. chapter1 in /work directory. all manpage directories.

find $HOME -print will lists all files find /work -name chapter1 -print will list all files find / -type d -name 'man*' -print will find / -size 0 -ok rm {} \; will remove all empty files on system.

conditions of find

-atime +n |-n| n will find files that were last accessed more than n or less than -n days or n days. -ctime +n or -n will find that were changed +n -n or n days ago. -depth descend the directory structure, working on actual files first and then directories. You can use it with cpio command. -exec commad {} \; run the Unix command on each file matched by find. Very useful condition. -print print or list to standard output (screen). -name pattern find the pattern. -perm nnnfind files whole permission flags match octal number nnn. -size n find files that contain n blocks. -type c Find file whole type is c. C could be b or block, c Character special file, d directory, p fifo or named pipe, l symbolic link, or f plain file.

back to top of misc commands back to top of page

Text processing
cut,paste, sort, uniq,awk,sed,vi.

Cut

command. cut command selects a list of columns or Option -c is for columns and -f for cut options for example if a file named testfile contains

fields fields.

from It [files]

one is

or more files. entered as

this is firstline this is secondline this is thirdline

Examples: cut -c1,4 testfile will print this to standard output (screen)
ts ts ts

It is printing columns 1 and 4 of this file which contains t and s (part of this).

Options:

-c list cut the column positions identified in list. -f list will cut the fields identified in list. -s could be used with -f to suppress lines without delimiters.

Paste

Command. paste command merge the lines of one or more files into vertical columns separated by a tab. for example if a file named testfile contains

this is firstline

and a file named testfile2 contains


this is testfile2

then running this command paste testfile testfile2 > outputfile will put this into outputfile
this is firstline this is testfile2

it contains contents of both files in columns. who | paste - - will list users in two columns.

Options:

-d'char' separate columns with char instead of a tab. -s merge subsequent lines from one file.

Sort
zzz aaa 1234 yuer wer qww wwe

command. sort command sort the lines of a file or files, in alphabetical order. for example if you have a file named testfile with these contents

Then running sort testfile will give us output of


1234 aaa qww wer wwe yuer zzz

Options:

-b ignores leading spaces and tabs. -c checks whether files are already sorted. -d ignores punctuation. -i ignores non-printing characters. -n sorts in arithmetic order. -ofile put output in a file.

+m[-m] skips n fields before sorting, and sort upto field position m. -r reverse the order of sort. -u identical lines in input file apear only one time in output.

Uniq

command. uniq command removes duplicate adjacent lines from sorted file while sending one copy of each second file.

Examples
sort names | uniq -d will show which lines appear more than once in names file.

Options:

-c print each line once, counting instances of each. -d print duplicate lines once, but no unique lines. -u print only unique lines.

Awk

and Nawk command. awk is more like a scripting language builtin on all unix systems. Although mostly used for text processing, etc. Here are some examples which are connected with other commands.

Examples:
df -t | awk 'BEGIN {tot=0} $2 == "total" {tot=tot+$1} END {print (tot*512)/1000000}' Will give total space in your system in megabytes. Here the output of command df -t is being passed into awk which is counting the field 1 after pattern "total" appears. Same way if you change $1 to $4 it will accumulate and display the addition of field 4 which is used space. for more information about awk and nawk command in your system enter man awk or man nawk.

Sed

command. sed command launches a stream line editor which you can use at command line. you can enter your sed commands in a file and then using -f option edit your text file. It works as sed [options] files

options:

-e 'instruction' Apply the editing instruction to the files. -f script Apply the set of instructions from the editing script. -n suppress default output.

for more information about sed, enter man sed at command line in your system.

Vi

editor. vi command launches a vi sual editor. To edit a file type vi filename vi editor is a default editor of all Unix systems. It has several modes. In order to write characters you will need to hit i to be in insert mode and then start typing. Make sure that your terminal has correct settings, vt100 emulation works good if you are logged in using pc. Once you are done typing then to be in command mode where you can write/search/ you need to hit :w filename to write and in case you are done writing and want to exit :w! will write and exit.

options:

i for insert mode. o I inserts text at the curson o A appends text at the end of the line. o a appends text after cursor. o O open a new line of text above the curson. o o open a new line of text below the curson. : for command mode. o <escape> to invoke command mode from insert mode. o :!sh to run unix commands. o x to delete a single character. o dd to delete an entire line o ndd to delete n number of lines. o d$ to delete from cursor to end of line. o yy to copy a line to buffer. o P to paste text from buffer. o nyy copy n number of lines to buffer. o :%s/stringA/stringb /g to replace stringA with stringB in whole file. o G to go to last line in file. o 1G to go to the first line in file. o w to move forward to next word. o b to move backwards to next word. o $ to move to the end of line. o J join a line with the one below it. /string to search string in file. n to search for next occurence of string.

back to top of Text processing commands back to top of page

Shell and programming


Shell programming,bourne shell, ksh, csh, echo,line,sleep, test,cc compiler.

Shell

programming

concepts

and

commands.

Shell programming is integral part of Unix operating systems. Shell is command line userinterface to Unix operating system, User have an option of picking an interface on Unix such as ksh, csh, or default sh., these are called shells(interface). Shell programming is used to automate many tasks. Shell programming is not a programming language in the truest sense of word since it is not compiled but rather an interpreted language. Unix was written in C language and thus c language is integral part of unix and available on all versions. Shells, like ksh and csh are popular shells on unix although there are 5 or 6 different shells available but I will only be discussing ksh and csh as well as sh. Common features among all shells are job control, for example if I am running a processes which is searching the whole system for .Z files and output is directed to a file named compressedfiles. example:

find / -name *.Z -print > compressedfiles then after entering this command hitting <control z> key will suspend this job, then entering bg at command line will put this job in background, entering fg will put this job in foreground. Entering jobs at command line will show me all my concurrent jobs that are running. Other common features
o o o o o o o o o o o o o o o o o o o o o

> will redirect output from standard out (screen) to file or printer or whatever you like. >> filename will append at the end of a file called filename. < will redirect input to a process or commnand. | pipe output, or redirect output, good for joining commands, i.e. find command with cpio, etc. & at the end of command will run command in background. ; will separate commands on same line. * will match any characters in a file or directories. junk* will match all files with first 4 letters ? will match single characters in a file. [] will match any characters enclosed. () execute in subshell. ` ` to run a command inside another command and use its output. " " partial quote for variables. ' ' full quote for variables. # begin comment (if #/bin/ksh or csh or sh is entered at first line of script it runs script in that shell) bg background execution. break break from loop statements. continue Resume a program loop. Kill pid number will terminate running jobs stop will stop background job. suspend will suspend foreground job. wait will wait for a background job to finish.

Bourne

(sh shell). sh or Bourne shell is default shell of Unix operating systems and is the most simplest shell in Unix systems.

Shell

Examples:

cd; ls execute one after another. (date;who;pwd)> logifile will redirect all the output from three commands to a filenamed logfile. sort file | lp will first sort a file and then print it. alias [options] [name[='command']] will let you create your own commands. i.e.

alias ll="ls -la" will execute `ls -la` command whenever ll is entered. let expressions is syntax of let statement. o let i=i+1 will work as a counter with i incrementing each time this statement is encountered. for x[in list] do commands done is syntax for for do loop. function name {commands;} is the syntax of a function which can be called from anywhere in program. if condition1 then commands1 elif condition2 then commands2 ... ... ... else commands3 fi
o

Ksh
Ksh or Korn shell is widely used shell.

shell

(Korn).

Csh
csh is second most used shell.

or

shell

Echo
echo command in shell programming.

command

Line
line command in shell programming.

command.

Sleep
sleep command in shell programming.

command.

Test
test command in shell programming.

Command.

CC

(c programming language compiler). Since Unix is itself written in C programming language, most Unix operating systems come with c compiler called cc.

compiler

back to top of Shell programming. back to top of page

Communications
cu,ftp,login, rlogin,talk,telnet, vacation and write .

Cu

command. cu command is used for communications over a modem or direct line with another Unix system. Syntax is cu options destination

Options

-bn process lines using n-bit characters (7 or 8). -cname Search UUCP's device file and select local area network that matches name. -d Prints diagnostics. -e sends even parity data to remote system -lline communicate on this device (line=/dev/tty001, etc) -n prompts for a telephone number. -sn set transmission rate to n(e.g 1200,2400,9600, BPS) Destination

telno is the telephone number of the modem to connect to. system is call the system known to uucp. aadr is an address specific to LAN.

Ftp

command (protocol). 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. Practice FTP by ftping to nic.funet.fi loggin in as anomymous with password being your e-mail address.

Login

command. login command invokes a login session to a Unix system, which then authenticates the login to a system. System prompts you to enter userid and password.

Rlogin

command. rlogin command is used to log on to remote Unix systems, user must have permissions on both systems as well as same userid, or an id defined in .rhosts file. Syntax is rlogin options host

options

-8 will allow 8 bit data to pass, instead of 7-bit data. -e c will let you use escape character c. -l user will let you to login as user to remote host, instead of same as local host.

Talk

command. talk command is used to invoke talk program available on all unix system which lets two users exchange information back and forth in real time. Syntax is talk userid@hostname

Telnet

command. Telnet command invokes a telnet protocol which lets you log on to different unix, vms or any machine connected over TCP/IP protocol, IPx protocol or otherwise. Syntax is telnet hostname

Vacation

command. vacation command is used when you are out of office. It returns a mail message to sender announcing that you are on vacation. to disable this feature, type mail -F " " . syntax is vacation options

Options

-d will append the date to the logfile. -F user will forward mail to user when unable to send mail to mailfile. -l logfile will record in the logfile the names of senders who received automatic reply. -m mailfile will save received messages in mailfile.

Write
write user tty

command

will

initiate

an

interactive

conversation

with

user.

Syntax

is

back to top of communications commands back to top of page

Storage commands
compress uncompress, cpio,dump,pack, tar, mt.

Compress
Options

command. 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

-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.

Uncompress
Options

command. Uncompress file uncompresses a file and return it to syntax is uncompress filename.Z this uncompresses the compressed file to its original name.

its

original

form.

-c write to standard output without changing files

Cpio

command. 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

copy files to another directory on the same system. Options

o o o o o o o o o o o o o o

-a reset access times of input files. -A append files to an archive (must use with -o). -b swap bytes and half-words. Words are 4 bytes. -B block input or output using 5120 bytes per record. -c Read or write header information as Ascii character. -d create directories as needed. -l link files instead of copying. -o file direct output to a file. -r rename files interactively. -R ID reassign file ownership and group information to the user's login ID. -V print a dot for each file read or written. -s swap bytes. -S swap half bytes. -v print a list of filenames.

Examples
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.

Dump

command is useful to backup the file systems. dump command copies all the files in filesystem that have been changed after a certain date. It is good for incremental backups. This information about date is derived from /var/adm/dumpdates and /etc/fstab . syntax for HP-UX dump is /usr/sbin/dump [option [argument ...] filesystem]

Options

0-9 This number is dump level. 0 option causes entire filesystem to be dumped. b blocking factor taken into argument. d density of tape default value is 1600. f place the dump on next argument file instead of tape. This example causes the entire file system (/mnt) to be dumped on /dev/rmt/c0t0d0BEST and specifies that the density of the tape is 6250 BPI. o /usr/sbin/dump 0df 6250 /dev/rmt/c0t0d0BEST /mnt for more info type man dump at command line.

Pack

command. 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 .

Tar

command.

tar command creates an archive of files into a single file. Tar copies and restore files to a tape or any storage media. Synopsis of tar is tar [options] [file]

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:

c creates a new tape. r append files to a tape. t print the names of files if they are stored on the tape. x extract files from tape.

Options:

b n use blocking factor of n. l print error messages about links not found. L follow symbolic links. v print function letter (x for extraction or a for archive) and name of files.

Mt command
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


eof write count EOF marks. fsf Forward space count files. fsr Forward space count records. bsf Backward space count files. bsr Backward space count records. rew Rewind tape. offl Rewind tape and go offline. eod Seek to end of data (DDS and QIC drives only). smk Write count setmarks (DDS drives only). fss Forward space count setmarks (DDS drives only). bss Backward space count setmarks (DDS drives only). Examples o mt -t /dev/rmt/0mnb rew will rewind the tape in this device. o mt -t /dev/rmt/0mnb offl will eject the tape in this device.

back to top of storage commands back to top of page

System Status
at, chmod,chgrp, chown,crontab,date, df,du, env, finger, ps,ruptime, shutdwon,stty, who.

At

command. at command along with crontab command is at options time [ddate] [+increment] is for example if I have a script named usersloggedin which contains.

used syntax

to of

schedule at

jobs. command.

#!/bin/ksh who | wc -l echo "are total number of people logged in at this time."

and I want to run this script at 8:00 AM. So I will first type at 8:00 %lt;enter> usersloggedin %lt;enter> I will get following output at 8:00 AM
30 are total number of people logged in at this time.

Options:

-f file will execute commands in a file. -m will send mail to user after job is completed. -l will report all jobs that are scheduled and their jobnumbers. -r jobnumber will remove specified jobs that were previously scheduled.

Chmod

command. chmod command is used to change permissions on a file. for example if I have a text file with calender in it called cal.txt. initially when this file will be created the permissions for this file depends upon umask set in your profile files. As you can see this file has 666 or -rw-rw-rw attributes. ls -la cal.txt

-rw-rw-rw-

1 ssb

dxidev

135 Dec

3 16:14 cal.txt

In this line above I have -rw-rw-rw- meaning respectively that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next ssb is owner of this file dxidev is the group of this file, there are 135 bytes in this file, this file was created on December 3 at time16:14 and at the end there is name of this file. Learn to read these permissions in binary, like this for example Decimal 644 which is 110 100 100 in binary meand rw-r--r-- or user can read,write this file, group can read only, everyone else can read only. Similarly, if permissions are 755 or 111 101 101 that means rwxr-xr-x or user can read, write and execute, group can read and execute, everyone else can read and execute. All directories have d in front of permissions. So if you don't want anyone to see your files or to do anything with it use chmod command and make permissions so that only you can read and write to that file, i.e. chmod 600 filename.

Chgrp

command. chgrp command is used to change the group You must own the file or chgrp [options] newgroup files is Newgroup is either a group Id or a group name located in /etc/group .

of a be syntax

file a of

or directory. superuser. chgrp.

Options:

-h will change the group on symbolic links. -R recursively descend through directory changing group of all files and subdirectories.

Chown
chown command to change Syntax chown options newowner files ownership of a

command. file or directory is

to

one

or

more

users.

Options

-h will change the owner on symbolic links. -R will recursively descend through the directory, including subdirectories and symbolic links.

Crontab
Minutes

command. crontab command is used to schedule jobs. You must have permission to run this command by unix Administrator. Jobs are scheduled in five numbers, as follows.

0-59

Hour Day of month month Day of week

0-23 1-31 1-12 0-6 (0 is sunday)

so for example you want to schedule a job which runs from script named backup_jobs in /usr/local/bin directory on sunday (day 0) at 11.25 (22:25) on 15th of month. The entry in crontab file will be. * represents all values.
25 22 15 * 0 /usr/local/bin/backup_jobs

The * here tells system to run this each month. Syntax is crontab file So a create a file with the scheduled jobs as above and then type crontab filename .This will scheduled the jobs.

Date
Date displays todays date, to use it type date at prompt.

command.

Sun Dec

7 14:23:08 EST 1997

is similar to what you should see on screen.

Df

command. df command displays information about mounted filesystems. It reports the number of free disk blocks. Typically a Disk block is 512 bytes (or 1/2 Kilobyte). syntax is df options name

Options

-b will print only the number of free blocks. -e will print only the number of free files. -f will report free blocks but not free inodes. -F type will report on an umounted file system specified by type. -k will print allocation in kilobytes. -l will report only on local file systems. -n will print only the file system name type, with no arguments it lists type of all filesystems

Du
du command displays disk usage.

command.

Env
env command displays all the variables.

command.

Finger
finger command.

command.

PS

command ps command is probably the most useful command for systems administrators. It reports information on active processes. ps options

options.

-a Lists all processes in system except processes not attached to terminals. -e Lists all processes in system. -f Lists a full listing. -j print process group ID and session ID.

Ruptime
ruptime command ruptime options tells the status

command. of

local

networked

machines.

options.

-a include user even if they've been idle for more than one hour. -l sort by load average. -r reverse the sort order. -t sort by uptime. -i sort by number of users.

Shutdown
options.

command. Shutdown command can only be executed by root. To gracefully bring down a system, shutdown command is used.

-gn use a grace-period of n seconds (default is 60). -ik tell the init command to place system in a state k. o s single-user state (default) o 0 shutdown for power-off. o 1 like s, but mount multi-user file systems.

5 stop system, go to firmware mode. 6 stop system then reboot. -y suppress the default prompt for confirmation.
o o

Stty

command stty command sets terminal input output options for the current terminal. without options stty reports terminal settings. stty options modes < device

options

-a report all options. -g report current settings. Modes

0 hang up phone. n set terminal baud. erase keyname, will change your keyname to be backspace key.

Who

command who command displays information about the who options Who as default prints login names of users currently logged in.

current file

status

of

system.

Options

-a use all options. -b Report information about last reboot. -d report expired processes. -H print headings. -p report previously spawned processes. -u report terminal usage.

back to top of systemstatus commands back to top of page

Advance unix command concepts


Put advance commands utilities, redirection, etc here. cal > cal.txt To create a new file called cal.txt that has calendar for current month. > sign redirects output from stdout (screen) to a file.

back to top of advance commands

back to top of page Top of page Fundamentals of Unix File Systems Installing software Unix commands Networking Installing Hardware User Accounts Backups Performance and Tuning Shell Programming Security Some Useful Scripts

Copyrighted by Sandeep singh Bajwa.

The fundamentals of Unix and Computers

System V Unix operating systems was developed by AT&T bell labs and it is the most widely used Unix operating systems. An operating system is that piece of software which lets you interact with hardware in your computer. For example, when to call CPU, when to store in Memory, when to read from Disk , how to connect to outside world is all being done on any Operating systems in any computer at all the time, oblivious to the user. Then this operating systems is put in a package before selling to us, just like when you buy chocolates. The package around which this operating systems is wrapped is called User Interface in computing terminology. Some developers like Microsoft spend more time on developing this user interface than the real operating systems, like Windows 95, others like Sun solaris had spend more time on reliability and strength of the operating systems rather then how user interacts with it. That's the big difference between Unix and Windows 95 (and all the other microsoft products). Unix is more powerful, more reliable, can do much more work, much faster and you do not need to reboot your computer everyday. Only problem is that many people get put off by the command line user interface. But things are changing now and even unix has its own version of X windows. Learning different command on Unix is quite an experience. Unix operating systems uses many different user interfaces depending upon the user, different command line interfaces are called Shells, you can use Ksh (korn shell), Bash, (bourne Again Shell), csh (C shell), etc.
The core of unix is called kernel. Kernel interacts with hardware, software and user interface (i.e. Shell). When you enter a command to add two numbers, kernel converts the ascii english like command to the binary language of central processing unit and then pass these binary bits of 1's and 0's to cpu byte by byte which then processes and give back the answer to kernel and kernel sends it out to standard output (screen) after converting them back to decimal number notation which we all use. In this document all the commands that appear in greenish blue color you can type and use in your Unix session.

The Basics

How do I login to Unix system? You need to have an account created by unix administrator for that particular system. For example if you want to login to unix systems named punjab1., open up a new session to punjab1 and at prompt enter your user name and password as supplied by Administrator. What do I do after login? Once logged in, you will see a shell prompt, actually a blank screen with on blinking cursor, that means you are ready to enter your commands. Here you can use These basic unix commands. For more information about that command you can use online help by typing man man. $ sign means shell prompt so you do not need to enter $. back Back to main page to top

Some common problems


One of the first common problem is incorrect TERM variable. To make sure that your terminal is set to correct emulation check your emulation by cal command which displays calendar for current month. Type cal at command line.

December S M Tu 1 2 7 8 9 14 15 16 21 22 23 28 29 30

1997 W Th F S 3 4 5 6 10 11 12 13 17 18 19 20 24 25 26 27 31

If you did not see nice and formatted like above then probably you need to set your terminal emulation.

To find out what your terminal is set to. $echo $TERM

vt100

(this is what you should get back, vt100 works well with ibm PCs)
To see what shell you are using echo $SHELL

/bin/ksh

is what you will get if using korn shell,


/bin/csh

if using c shell. You default login files if you are using korn shell are .profile and .kshrc and for c shell are .login and .cshrc. You can edit these files to put any additional variables you like to set when logging in .
To make your backspace key an erase key. stty erase backspace key

To set terminal emulation to vt100 if using ksh export TERM=vt100 if using csh

setenv TERM vt100

Other conecpts
What are files? The bits and bytes of data represented in electronic flip and flops are files. For example, an ascii character of A is represented by 41H or 0100 0001. Which is interpreted by CPU in the time period as one low one high one low one low one low one low one low one high. So here code for A which is 41 (in Hex) is actually one byte, since a 0 or 1 is one bit and one byte equals 8 bits. Two types of files exist in computing world, Ascii and Binary. ASCII is portable across many different operating systems (or platforms as some people call) it is a standard and its full form is American Standard Code for Information Interchange. Binary files depends upon the application on which it is used. For example this document you are reading is an ASCII file while the pictures you are seeing are binary files cause pictures depends upon few formats like gif or jpg which can be interpreted by the browser (Netscape, IE Explorer). So while transferring files from one system to another, using binary mode is safer, since bit by bit is transferred. As you are reading this document which is called index.html it is using ASCII characters with references to binary picture files and other html ASCII files here and there. Then there are permissions on each of these files which are divided into your permissions, your group's permissions, rest of world permissions, and extra permissions (sticky bit, suid bit, etc).

Unix for starters Fundamentals of Operating systems Other concepts Unix commands Back to Unix admin page The fundamentals of Unix and Computers

System V Unix operating systems was developed by AT&T bell labs and it is the most widely used Unix operating systems. An operating system is that piece of software which lets you interact with hardware in your computer. For example, when to call CPU, when to store in Memory, when to read from Disk , how to connect to outside world is all being done on any Operating systems in any computer at all the time, oblivious to the user. Then this operating systems is put in a package before selling to us, just like when you buy chocolates. The package around which this operating systems is wrapped is called User Interface in computing terminology. Some developers like Microsoft spend more time on developing this user interface than the real operating systems, like Windows 95, others like Sun solaris had spend more time on reliability and strength of the operating systems rather then how user interacts with it. That's the big difference between Unix and Windows 95 (and all the other microsoft products). Unix is more powerful, more reliable, can do much more work, much faster and you do not need to reboot your computer everyday. Only problem is that many people get put off by the command line user interface. But things are changing now and even unix has its own version of X windows. Learning different command on Unix is quite an experience. Unix operating systems uses many different user interfaces depending upon the user, different command line interfaces are called Shells, you can use Ksh (korn shell), Bash, (bourne Again Shell), csh (C shell), etc.
The core of unix is called kernel. Kernel interacts with hardware, software and user interface (i.e. Shell). When you enter a command to add two numbers, kernel converts the ascii english like command to the binary language of central processing unit and then pass these binary bits of 1's and 0's to cpu byte by byte which then processes and give back the answer to kernel and kernel sends it out to standard output (screen) after converting them back to decimal number notation which we all use. In this document all the commands that appear in greenish blue color you can type and use in your Unix session.

The Basics

How do I login to Unix system? You need to have an account created by unix administrator for that particular system. For example if you want to login to unix systems named punjab1., open up a new session to punjab1 and at prompt enter your user name and password as supplied by Administrator. What do I do after login? Once logged in, you will see a shell prompt, actually a blank screen with on blinking cursor, that means you are ready to enter your commands. Here you can use These basic unix commands. For more information about that command you can use online help by typing man man. $ sign means shell prompt so you do not need to enter $. back Back to main page to top

Some common problems


One of the first common problem is incorrect TERM variable. To make sure that your terminal is set to correct emulation check your emulation by cal command which displays calendar for current month. Type cal at command line.

December S M Tu 1 2 7 8 9 14 15 16 21 22 23 28 29 30

1997 W Th F S 3 4 5 6 10 11 12 13 17 18 19 20 24 25 26 27 31

If you did not see nice and formatted like above then probably you need to set your terminal emulation.

To find out what your terminal is set to. $echo $TERM

vt100

(this is what you should get back, vt100 works well with ibm PCs)
To see what shell you are using echo $SHELL

/bin/ksh

is what you will get if using korn shell,


/bin/csh

if using c shell. You default login files if you are using korn shell are .profile and .kshrc and for c shell are .login and .cshrc. You can edit these files to put any additional variables you like to set when logging in .
To make your backspace key an erase key. stty erase backspace key

To set terminal emulation to vt100 if using ksh export TERM=vt100 if using csh

setenv TERM vt100

Other conecpts
What are files? The bits and bytes of data represented in electronic flip and flops are files. For example, an ascii character of A is represented by 41H or 0100 0001. Which is interpreted by CPU in the time period as one low one high one low one low one low one low one low one high. So here code for A which is 41 (in Hex) is actually one byte, since a 0 or 1 is one bit and one byte equals 8 bits. Two types of files exist in computing world, Ascii and Binary. ASCII is portable across many different operating systems (or platforms as some people call) it is a standard and its full form is American Standard Code for Information Interchange. Binary files depends upon the application on which it is used. For example this document you are reading is an ASCII file while the pictures you are seeing are binary files cause pictures depends upon few formats like gif or jpg which can be interpreted by the browser (Netscape, IE Explorer). So while transferring files from one system to another, using binary mode is safer, since bit by bit is transferred. As you are reading this document which is called index.html it is using ASCII characters with references to binary picture files and other html ASCII files here and there. Then there are permissions on each of these files which are divided into your permissions, your group's permissions, rest of world permissions, and extra permissions (sticky bit, suid bit, etc). back to top Back to main page

I am going to create a new file using cal command which displays calendar and instead of seeing it on the screen I will put the output in a file called cal.txt using redirection > symbol. cal > cal.txt Now to see this file and permissions on it I will use ls command with -la option. ls -la cal.txt

-rw-rw-rw-

1 ssb

dxidev

135 Dec

3 16:14 cal.txt

In this line above I have -rw-rw-rw- meaning respectively that owner can read and write file, member of the owner's group can read and write this file and anyone else connected to this system can read and write this file., next ssb is owner of this file dxidev is the group of this file, there are 135 bytes in this file, this file was created on December 3 at time16:14 and at the end there is name of this file. Learn to read these permissions in binary, like this for example Decimal 644 which is 110 100 100 in binary meand rw-r--r-- or user can read,write this file, group can read only, everyone else can read only. Similarly, if permissions are 755 or 111 101 101 that means rwxr-xr-x or user can read, write and execute, group can read and execute, everyone else can read and execute. All directories have d in front of permissions. So if you don't want anyone to see your files or to do anything with it use chmod command and make permissions so that only you can read and write to that file, i.e. chmod 600 filename. For more information about how to change permissions and ownership of files read administration file system section. back to top of this page back to other concepts

Top of page fundamentals of unix

UNIX Topics
UNIX is a class of operating systems. There are various different implementations of UNIX. Each of which provides a core set of basic UNIX commands. Basic UNIX commands:

cat cd chmod ftp grep kill ls

mail man mkdir more mv passwd ps

pwd su tail telnet vi whoami whois

Vous aimerez peut-être aussi