Sunday, June 29, 2008

UNIX Commands

UNIX COMMANDS

The cat command reads one or more files and prints them to standard output. The operator > can be used to combine multiple files into one. The operator >> can be used to append to an existing file.
The syntax for the cat command is:
cat [options] [files]
options:
-e $ is printed at the end of each line. This option must be used with -v.
-s Suppress messages pertaining to files that do not exist.
-t Each tab will display as ^I and each form feed will display as ^L. This option must be used with -v.
-u Output is printed as unbuffered.
-v Display control characters and nonprinting characters

Examples:
cat file1
cat file1 file2 > all
cat file1 >> file2

The cd command changes directory.
The syntax for the cd command is:
cd [dir]

Examples:
cd tech
cd /tech
The chmod command changes the access mode of one file or multiple files.
The syntax for the chmod command is:
chmod [option] mode files

options:
-R Descend directory arguments recursively while setting modes.
-f Suppress error messages if command fails.
mode:
Who u=user, g=group, o=other, a=all (default)
Opcode + means add permission
- means remove permission
= means assign permission and remove the permission of unspecified fields
Permission r=Read, w=write, x=Execute, s=set uid bit, t=sticky bit
u=user, g=group, o=other, l=mandatory locking
Examples:
chmod 751 tech
chmod u=rwx, g=rx, o=x tech
chmod =r tech

The ftp command allows you to transfer files to and from a remote server.
The syntax for the ftp command is:
ftp [options] [hostname]
options:
-d Debugging is enabled.
-g Filename globbing is disabled.
-i Interactive prompting is disabled.
-n When you are initially connecting, auto-login is disabled.
-v Display all responses from the server.

Examples:
ftp tech
ftp -v tech

The grep command allows you to search one file or multiple files for lines that contain a pattern. Exit status is 0 if matches were found, 1 if no matches were found, and 2 if errors occurred.
The syntax for the grep command is:
grep [options] pattern [files]
options:
-b Display the block number at the beginning of each line.
-c Display the number of matched lines.
-h Display the matched lines, but do not display the filenames.
-i Ignore case sensitivity.
-l Display the filenames, but do not display the matched lines.
-n Display the matched lines and their line numbers.
-s Silent mode.
-v Display all lines that do NOT match.
-w Match whole word.

Examples:
grep -c tech file1


The kill command allows you to kill one process ID or multiple process IDs.
The syntax for the kill command is:
kill [options] IDs
options:
-l Lists the signal names.
-signal The signal number of name. Using the signal number of 9, means that the kill is absolute.

Examples:
kill -9 78689
The ls command lists all files in the directory that match the name. If name is left blank, it will list all of the files in the directory.
The syntax for the ls command is:
ls [options] [names]
options:
-a Displays all files.
-b Displays nonprinting characters in octal.
-c Displays files by file timestamp.
-C Displays files in a columnar format (default)
-d Displays only directories.
-f Interprets each name as a directory, not a file.
-F Flags filenames.
-g Displays the long format listing, but exclude the owner name.
-i Displays the inode for each file.
-l Displays the long format listing.
-L Displays the file or directory referenced by a symbolic link.
-m Displays the names as a comma-separated list.
-n Displays the long format listing, with GID and UID numbers.
-o Displays the long format listing, but excludes group name.
-p Displays directories with /
-q Displays all nonprinting characters as ?
-r Displays files in reverse order.
-R Displays subdirectories as well.
-t Displays newest files first. (based on timestamp)
-u Displays files by the file access time.
-x Displays files as rows across the screen.
-1 Displays each entry on a line.

Examples:
ls -la
The mail command allows you to read or send mail. If users is left blank, it allows you to read mail. If users has a value, then it allows you send mail to those users.
The syntax for the mail command is:
mail [options] [users]
options for reading mail:
-e Check if mail exists. Exit status is 0 if mail exists and 1 if mail does not exist.
-f file Read mail from mailbox called file.
-F names Forward mail to names.
-h Displays messages in a window.
-i Ignore interrupts
-p Displays all messages.
-P Displays all messages with header lines.
-q Terminate when an interrupt occurs.
-r Displays oldest messages first.
-U Convert uucp-type addresses to Internet format.
-v Verbose.

options for sending mail:
-m type Display a "Message-type:" line at the heading of the message, followed by type.
-t Display a "To:" line at the heading of the message with the names of the recipients.
-w Send mail to users without waiting for a remote transfer program to finish.
-F Save message in a file called the name of the first recipient.
-h n If message has not been sent after n network connections, do not send message.
-i Ignore interrupts
-r address address is the return address for mail messages.
-s subject Displays subject in the subject header.
-U Convert uucp-type addresses to Internet format.
-v Verbose.


The man command displays the online manual pages.
The syntax for the man command is:
man [options] [ [section] subjects]
options:
- Output is piped through the more command.
-d Debug.
-F Search the MANPATH directories.
-f files Display a summary (one line) for each file.
-k keywords Displays the header lines that contain any of the keywords.
-M path Searchs in the path instead of the MANPATH directories.
-t Format the pages with troff.
-T mac Display using mac.

Examples:
man -f tech
The mkdir command creates a single directories or multiple directories.
The syntax for the mkdir command is:
mkdir [options] directories
options:
-m mode Sets the access mode for the new directory.
-p If the parent directories don't exist, this command creates them.

Examples:
mkdir -m 444 tech
mkdir -p tech/net/faqs
The more command displays the file called name in the screen. The RETURN key displays the next line of the file. The spacebar displays the next screen of the file.
The syntax for the more command is:
more [options] [files]
options:
-c Page through the file by clearing the window. (not scrolling).
-d Displays "Press space to continue, 'q' to quit"
-f Count logical lines rather than screen lines (wrapping text)
-l Ignores form feed (^L) characters.
-r Display all control characters.
-s Displays multiple blank lines as one blank line.
-u Does not display underline characters and backspace (^H).
-w Waits for a user to press a key before exiting.
-n Displays n lines per window.
+num Displays the file starting at line number num.
+/pattern Displays the file starting at two lines before the pattern.

Examples:
more -d tech
The mv command allows you to move and rename files.
The syntax for the mv command is:
mv [options] sources target
options:
-f Forces the move.
-i Prompt for a confirmation before overwriting any files.

Examples:
mv -f tech /usr
The passwd command changes the password for the user.
The syntax for the passwd command is:
passwd [options] [user]
options:
-s Displays password information.

Examples:
passwd tech
The ps command displays active processes.
The syntax for the ps command is:
ps [options]
options:
-a Displays all processes on a terminal, with the exception of group leaders.
-c Displays scheduler data.
-d Displays all processes with the exception of session leaders.
-e Displays all processes.
-f Displays a full listing.
-glist Displays data for the list of group leader IDs.
-j Displays the process group ID and session ID.
-l Displays a long listing
-plist Displays data for the list of process IDs.
-slist Displays data for the list of session leader IDs.
-tlist Displays data for the list of terminals.
-ulist Displays data for the list of usernames.

Examples:
ps -ef
ps -aux
The pwd command displays the full pathname of the current directory.
The syntax for the pwd command is:
pwd
The su command creates a shell with the user ID of another user.
The syntax for the su command is:
su [option] [user] [shell_args]
options:
- Complete the entire login sequence.

Examples:
su root
su tech
The tail command displays the last ten lines of the file.
The syntax for the tail command is:
tail [options] [file]
options:
-f Follow the file as it grows.
-r Displays the lines in the reverse order.
-n[k] Displays the file at the nth item from the end of the file.
+n[k] Displays the file at the nth item from the beginning of the file.

Examples:
tail -r tech
The telnet command allows you to communicate to another host using the TELNET protocol.
The syntax for the telnet command is:
telnet [host [port]]
The vi command launches the text editor called vi.
The syntax for the vi command is:
vi [options] [files]
options:
-ccommand Launch vi and execute the command in vi.
-l Edit a LISP file.
-L Lists all files that were saved due to an editor or system crash.
-rfile Recover and open file after an editor or system crash.
-R Read-only.
+ Position on last line of file in vi.
+n Position on n line of the file in vi.

Examples:
vi + tech
The whoami command displays your username.
The syntax for the whoami command is:
whoami
The whois command searches for the person, login, handle, or organization called name.
The syntax for the whois command is:
whois [option] name
options:
-h host Searches on host name called host.

Examples:
whois tech

No comments:

Search 4 DataStage