some basic unix commands
TRANSCRIPT
Basic UNIX Commands
Topics• Basics of UNIX
• Unix Command
• Unix File system
• Basic Commands▫ Directory commands▫ File management commands▫ Display contents of file commands▫ Shell Programming commands▫ Network commands
• Unix and Informatica
Overview :
• UNIX is UNiplexed Information Computing System (UNICS), later known as UNIX.
• Unix is a multi-user, multi-tasking operating system.
• Important characteristics are:▫ Simplicity▫Focus▫Reusable Components
Unix:
• A command is a program that tells the Unix system to do something. It has the form:
command [options] [arguments] where an argument indicates on what the
command is to perform its action, usually a file or series of files. An option modifies the command, changing the way it performs.
• Options are generally preceded by a hyphen (-), and for most commands, more than one option can be strung together, in the form
command -[option][option][option]
Unix Commands:
• Inverted tree structure• Each node is either a file or a directory of files• Eg: /user2/joe/classes
Unix File system:
Directory Commands:
• cd• mkdir• rmdir• mv• pwd
• cd : Change Directory
Syntax : cd [directory]
Examples:
$cd changes to user's home directory
$cd / changes directory to the system's root
$cd .. goes up one directory level
$cd ../.. goes up two directory levels
$cd /full/path/name/from/root changes directory to absolute path named
Directory Commands:
• mkdir : Make a directory
Syntax: mkdir [options] directory
Options:
-p create the intermediate (parent) directories, as needed.
-m mode access permissions.
Example: $mkdir /home/my/data
• rmdir : Remove a directory
Syntax: rmdir [directory]
Example: $rmdir /home/my/data or
$rmdir data
• mv : Move or rename files or directories
Syntax: mv [options] old_filename new_filename
Options: -i interactive (prompt and wait for confirmation before proceeding). -f Don’t prompt, even when copying over an existing target file. -b Make a backup of each file that would otherwise be overwritten or removed.
-v Print the name of each file before moving it.
Example: $mv –i /home/my/data /home/my/data_new
• pwd: Print the current working directory
Example:
test@localhost: $pwd /home/my/data
• dir: Briefly list directory contents
Example:
test@localhost: $dir
•cat•cp•chown• touch• ls
File Management Commands:
cat command
• Can be used to create, display, concatenate andappend files
• Syntax to create a filecat > filename
• Syntax to display a filecat filename [options]
• Syntax to concatenate filescat filename1 filename2 > filename3 [options]
cat command
Options :-n Precede each line output with its line number.
-b Number the lines, as -n, but omit the line numbers from blank lines.
-v Non-printing characters are printed visibly.
-e A $ character will be printed at the end of each line.
-t tabs will be printed as ^I's and formfeeds to be printed as ^L's.
-u The output is not buffered. (The default is buffered output.)
-s cat is silent about non-existent files.
Examples of cat command:
• To concatenate a file cat file1.txt file2.txt > file3.txt
• To create a filecat > file1.txt
• To display filecat file1.txt
cp command
• Copies a file or group of files
• Creates exact image of the file on the disk with different name
• Syntax to copy a file to another filecp [options] SourceFile TargetFile
• Syntax to copy a file to a directorycp [option] SourceFile ... TargetDirectory
• Syntax to copy a directory to a directory (-r or -R mustbe used)
cp [options] { -r | -R } SourceDirectory.. TargetDirectory
cp command
Options:
-i Interactive confirmation is required.
-p Preserve the characteristics of the source file.
-r Recursively copy any source directories
-f specifies removal of the target file if it cannot be opened for write operations
Examples of cp command
1. cp file1.txt file2.txt2. cp file1.txt newdir3. cp *.txt newdir4. cp prog.c prog.bak
chown command
• Change ownership of file• On most versions of Unix this can only be done by the super-user
Syntax: chown [options] user[.group] file
Options:
-R recursively descend through the directory structure
-f force, and don’t report any errors
Example:
# chown new_owner file
touch command
• Used to change a file's access and modification timestamp
• Creates a empty file
• Syntax touch [option] [-r ref_file | -t time ]file_name(s)
• Options -a change the access time only-m change the modification time only
• -r ref_file Use the corresponding times of the file named by ref_file instead of the current time.
• -t time Use the specified time instead of the current time. Time will be a decimal number of the form
• EXAMPLE▫ touch -am file3 ▫ touch -r file4 file5 ▫ touch file1 file2 file3
ls command
• Lists the directories and files
• Syntax: ls [options] [ argument]
• Many options are used along with ls command, commonly used are-l long format
-a lists all files in the given directory
-d list the name of the current directory
-F appends a character revealing the nature of a file, example: * for an executable, or / for a directory. regular files have
no suffix.
-g show group ownership of file in long listing
-R list all subdirectories encountered
-t sort by time modified instead of name
-h print sizes in human readable format.
Example:• 1. ls ~ List the contents of your home directory
• 2. ls / List the contents of your root directory.
• 3. ls -d */ Only list the directories in the current directory.
• More
• head
• Tail
• diff
• cmp
• comm
Commands to display contents of a file:
• more is a command to view the contents of a text file one screen at a time.
Syntax:more [options] <file_name>
Example:more < letter.txtletter.txt | more
more Command:
• -num: specifies the screen size (in lines).
• +num: Starts at specific line number
• -d: prompt the user with the message "[Press space to continue, 'q' to quit. And Press 'h' for instructions.]”
• -p: Do not scroll. Instead, clear the whole screen and then display the text.
• -s: Squeeze multiple blank lines into one
• -u: Suppress underlining.
• head is used to display the first few lines of a file
Syntax:head [options] <file_name>
By default it displays first 10 line of files
• tail is used to display the last few lines of a file
Syntaxtail [options] <file_name>
By default it displays last 10 line of files
head and tail Command:
• Oprtions:• -n: specifies the number of lines to be display on the
screen
• Examplehead -n 20 filename
It shows the first 20 lines of filename
tail -n 20 filename It shows the last 20 lines of filename
• diff is a file comparison utility that outputs the differences between two files.
• It displays the changes made per line for text files.
• If both are directories to compare, then diff will be run on each file that exists in both directories.
• Syntax:diff <file1_name> <file2_name>
diff Command:
• Example:
file_one contains: file_two contains :This is first file This is first fileThis is second line This is second line This is third line This is third line This is different as;lkdjf This is different xxxxxxxas;lkdjf This is not different This is not different
Then diff file_one file_two will be
4c4 < this is different as;lkdjf --- > this is different xxxxxxxas;lkdjf
• It compares two files of any type and writes the results to the standard output.
• if files differ, the byte and line number at which the first difference occurred is reported.
• Syntax:cmp <file1_name> <file2_name>
cmp Command:
• Options:-l: Print the byte number and the differing byte values for each difference.
-s: Print nothing for differing files; return exit status only.
• Examplecmp fileone filetwochar 80, line 4
• Comm is a utility that is used to compare two files for common and distinct lines
• The first two columns contain lines unique to the first and second file, respectively. The last column contains lines common to both.
• Syntax:comm <file1_name> <file2_name>
comm Command:
Example:File file1 contains: File file2 contains:
Apple AppleBanana BananaEggplant Banana
Zucchini
• The Comm file_1 file_2 willl be
AppleBanana
BananaEggplant
Zucchini
Shell scripts•A shell script is a text file with Unix commands in
it. •Shell scripts usually begin with a #! and a shell
name (complete pathname of shell).▫Pathname of shell be found using the which
command.▫The shell name is the shell that will execute this
script. E.g.: #!/bin/bash
•A shell script as a standalone is an executable program:▫Must use chmod to change the permissions of
the script to be executable also.•Can run script explicitly also, by specifying the
shell name.▫E.g: $ bash myscript▫E.g: $ csh myscript
•Why write shell scripts ?
▫ To avoid repetition: If you do a sequence of steps with standard Unix commands
over and over, why not do it all with just one command?
Or in other words, store all these commands in a file and execute them one by one.
▫ To automate difficult tasks: Many commands have subtle and difficult options that you
don’t want to figure out or remember every time .
Shell Programming Commands
• find command•grep command• test command•echo command•export command
find command
• full syntax : find [path] [options] [tests] [actions]
options
-depth
-follow
-mount
tests
-atime N
-mtime N
-newer otherfile
-type C
-user username
Actions
-exec command
-ok command
Examples of find command
•find . -newer other -type f -print
find . -newer other -type f -print
./elif3
./words.txt
./words2.txt
./_trap
find . \( -name “_*” -or -newer other \) -type f -print
./elif3
./words.txt
./words2.txt
./_trap
./_if
./_unset
./_until
find . -newer other –type f -exec ls -l {} \;
grep command•Grep – general regular expression parser•Full syntax : grep [options] PATTERN [files]
options
-c-i
-l
-v
grep command example• $grep in words.txt When shall we three meet again. In thunder, lightning,
or in rain? I come, Graymalkin!
• $ grep-c in words.txt words2.txt words.txt:2
Words2.txt:14
• $grep –c –v in words.txt words2.txt words.txt:9 Words2.txt:16
The test command
•Use for checking validity.•Three kinds:
▫Check on files.▫Check on strings.▫Check on integers
Notes on test
•Testing on files.▫test –f file: does file exist and is not a directory?▫test -d file: does file exist and is a directory?▫test –x file: does file exist and is executable?▫test –s file: does file exist and is longer than 0
bytes?
Example #!/bin/bashcount=0for i in *; doif test –x $i then count=`expr $count + 1`fidone
Notes on test
•Testing on strings.▫test –z string: is string of length 0? ▫test string1 = string2: does string1 equal string2?▫test string1 != string2: not equal?
Example #! /bin/bashif test -z $REMOTEHOSTthen:else DISPLAY="$REMOTEHOST:0“ export DISPLAYfi
Notes on test
•Testing on integers.▫ test int1 –eq int2: is int1 equal to int2 ? ▫ test int1 –ne int2: is int1 not equal to int2 ?▫ test int1 –lt int2: is int1 less than to int2 ?▫ test int1 –gt int2: is int1 greater than to int2 ?▫ test int1 –le int2: is int1 less than or equal to int2 ?▫ test int1 –ge int2: is int1 greater than or equal to int2 ?
Example #!/bin/bashsmallest=10000for i in 5 8 19 8 7 3doif test $i -lt $smallestthen smallest=$ifidoneecho $smallest
Notes on test• The test command has an alias ‘[]’.
▫Each bracket must be surrounded by spaces
#!/bin/bashsmallest=10000for i in 5 8 19 8 7 3doif [ $i -lt $smallest ]then smallest=$ifidoneecho $smallest
Echo command
•Full syntax : echo [OPTION]... [STRING]...Options -n do not output the trailing newline -e enable interpretation of the backslash-
escaped characters
Export command• syntax : export [variable]
• Once a variable exported from a shell, its exported to any scripts invoked from that shell and also to any shell they invoke in turn.
Example of export command• 1: List export2#!/bin/shecho “$foo”echo”$bar”• 2: Listing export1(export 2 has been invoked at the end)
foo=“ The first meta-syntactic variable”export bar=“ The second meta-syntactic variable”
export2If we run these we get$ export1
The second meta-syntactic variable
• telnet• ftp• rlogin•Write• rdesktop
Networking Commands:
telnet command• user interface to the TELNET protocol• Reliable connection oriented• Unsecure data transfer• Port no: 23
Syntax: telnet [options] [ remote_host [ port_number ] ]Options:
-8 Specify an 8-bit data path. This causes an attempt to negotiate the TELNET BINARY option on both input and output.
-E Stop any character from being recognized as an escape character.
-n tracefile Open tracefile for recording trace information.
-x Turn on encryption of the data stream.Example:To connect to your account on the remote system known as "castor":
telnet castor Trying 129.215.112.8 ...
Connected to castor.ucs.ed.ac.uk. Escape character is '^]'. SunOS UNIX (castor) login:
ftp command
• commonly used for copying files to and from other computersSyntax: ftp [options] [hostname] Options:
-v Verbose option forces ftp to show all responses from the remote server
-i Turns off interactive prompting during multiple file transfers.
-d Enables debugging.
-f Causes credentials to be forwarded to the remote host.
-t Enables packet tracing.
Example:1. ftp abc.xyz.edu2. ftp> get image1.jpg3. ftp> put image2.jpg4. mget *.jpg5. mput *.jpg6. mdelete *.jpg7. ftp> quit
rlogin command
• Allows access to another host in the local network
Syntax : $rlogin [-r username] remote_host
Options:
-8 Specify an 8-bit data path. This causes an attempt to negotiate the Rlogin BINARY option on both input and output.
-E Stop any character from being recognized as an escape character.
-ec Specify a different escape character, c, for the line used to disconnect from the remote host.
Example:$ rlogin abcxyzPassword:Last login: Mon jan 3 11:41:38 on pts/1
You have mail.
Write command• Write allows you to communicate with other users by copying lines
from your terminal to theirs.
• Receiver receives message of the form
Message from yourname @yourhost on yourtty at hh:mm:..
• Type EOF when done writing data.
• Use write command to reply
Syntax: $write user [ttyname]
Example
$write abc pts/1
rdesktop command rdesktop is a utility provided by unix to access windows desktop from unix
Syntax: rdesktop [options] server[:port]
Options:
-u <username>Username for authentication on the server.
-d <domain> Domain for authentication.
-p <password> The password to authenticate
-n <hostname>Client hostname. Normally rdesktop automatically obtains the hostname of the client.
-f Enable fullscreen mode, can be toggled at any time using Ctrl-Alt-Enter.
Example:
$ rdesktop xyz.mycorp.com
• Unix is secure and robust
• Shell script to manage repository
• Shell script to call and run informatica session
• Shell script to call sql files for staging and to create indexes
• Shell script to create and call parameter file
Unix and Informatica:
pmcmd command
• Session specific
pmcmd stoptask -s $server_name -u $user_name -p $pass -f $folder -w $wkf $sess
Keys :
stoptask : To stop a task
gettaskdetails : To retrieve task details
starttask : To Execute a task
aborttask : To abort a task
waittask : To Run a task in wait mode
• Workflow specific
pmcmd startworkflow-s $server_name -u $user_name -p $pass -f $folder $wkf
Keys : stopworkflow : To stop a workflow
getworkflowdetails : To retrieve workflow details
startworkflow : To Execute a workflow
abortworkflow : To abort a workflow
waitworkflow : To Run a workflow in wait mode pmcmd command with parameter file
pmrep command
• update repository information
• Installed in repository server installation directory, it is usually ($PM_HOME/repserver )
• pmrep connect -r <repository name> -n <repository user name> -x <repository password> -h <repserver host name> -o <repserver port number>
•How to run these commands?
Step1:> Goto bin directory on unix server where informatica is installed.
Step2:>run pmcmd You will get pmcmd prompt pmcmd>
Step3:>run connect command to connect to repository/ cd to go to informatica server directorypmcmd>connectit will ask repository name/password.
Step4:>run any command you need (startworkflow,stopworkflow,abortworkflow,starttask….)