Wednesday, January 9, 2013

UNIX Basic commands


CAT Command


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

OptionDescription
-e$ is printed at the end of each line. This option must be used with -v.
-sSuppress messages pertaining to files that do not exist.
-tEach tab will display as ^I and each form feed will display as ^L. This option must be used with -v.
-uOutput is printed as unbuffered.
-vDisplay control characters and nonprinting characters

Examples

cat file1
cat file1 file2 > all
cat file1 >> file2
* Please note that there are many flavors of UNIX, so if in doubt, consult your man pages.


CD Command

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

Examples

cd tech
cd /tech


CHMOD Command


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

OptionDescription
-RDescend directory arguments recursively while setting modes.
-fSuppress error messages if command fails.

Mode

ModeDescription
Whou=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
Permissionr=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

FTP Command


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

OptionDescription
-dDebugging is enabled.
-gFilename globbing is disabled.
-iInteractive prompting is disabled.
-nWhen you are initially connecting, auto-login is disabled.
-vDisplay all responses from the server.

Examples

ftp tech
ftp -v tech

GREP Command


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

OptionDescription
-bDisplay the block number at the beginning of each line.
-cDisplay the number of matched lines.
-hDisplay the matched lines, but do not display the filenames.
-iIgnore case sensitivity.
-lDisplay the filenames, but do not display the matched lines.
-nDisplay the matched lines and their line numbers.
-sSilent mode.
-vDisplay all lines that do NOT match.
-wMatch whole word.

Examples

grep -c tech file1


KILL Command


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

OptionDescription
-lLists the signal names.
-signalThe signal number of name. Using the signal number of 9, means that the kill is absolute.

Examples

kill -9 78689



LS Command



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

OptionDescription
-aDisplays all files.
-bDisplays nonprinting characters in octal.
-cDisplays files by file timestamp.
-CDisplays files in a columnar format (default)
-dDisplays only directories.
-fInterprets each name as a directory, not a file.
-FFlags filenames.
-gDisplays the long format listing, but exclude the owner name.
-iDisplays the inode for each file.
-lDisplays the long format listing.
-LDisplays the file or directory referenced by a symbolic link.
-mDisplays the names as a comma-separated list.
-nDisplays the long format listing, with GID and UID numbers.
-oDisplays the long format listing, but excludes group name.
-pDisplays directories with /
-qDisplays all nonprinting characters as ?
-rDisplays files in reverse order.
-RDisplays subdirectories as well.
-tDisplays newest files first. (based on timestamp)
-uDisplays files by the file access time.
-xDisplays files as rows across the screen.
-1Displays each entry on a line.

Examples

ls -la

MAN Command



The man command displays the online manual pages.
The syntax for the man command is:
man [options] [ [section] subjects]

Options

OptionDescription
-Output is piped through the more command.
-dDebug.
-FSearch the MANPATH directories.
-f filesDisplay a summary (one line) for each file.
-k keywordsDisplays the header lines that contain any of the keywords.
-M pathSearchs in the path instead of the MANPATH directories.
-tFormat the pages with troff.
-T macDisplay using mac.

Examples

man -f tech



MKDIR Command


The mkdir command creates a single directories or multiple directories.
The syntax for the mkdir command is:
mkdir [options] directories

Options

OptionDescription
-m modeSets the access mode for the new directory.
-pIf the parent directories don't exist, this command creates them.

Examples

mkdir -m 444 tech
mkdir -p tech/net/faqs


MORE Command


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

OptionDescription
-cPage through the file by clearing the window. (not scrolling).
-dDisplays "Press space to continue, 'q' to quit"
-fCount logical lines rather than screen lines (wrapping text)
-lIgnores form feed (^L) characters.
-rDisplay all control characters.
-sDisplays multiple blank lines as one blank line.
-uDoes not display underline characters and backspace (^H).
-wWaits for a user to press a key before exiting.
-nDisplays n lines per window.
+numDisplays the file starting at line number num.
+/patternDisplays the file starting at two lines before the pattern.

Examples

more -d tech

 MV Command

The mv command allows you to move and rename files.
The syntax for the mv command is:
mv [options] sources target

Options

OptionDescription
-fForces the move.
-iPrompt for a confirmation before overwriting any files.

Examples

mv -f tech /usr


PASSWD Command

The passwd command changes the password for the user.
The syntax for the passwd command is:
passwd [options] [user]

Options

OptionDescription
-sDisplays password information.

Examples

passwd tech



PS Command


The ps command displays active processes.
The syntax for the ps command is:
ps [options]

Options

OptionDescription
-aDisplays all processes on a terminal, with the exception of group leaders.
-cDisplays scheduler data.
-dDisplays all processes with the exception of session leaders.
-eDisplays all processes.
-fDisplays a full listing.
-glistDisplays data for the list of group leader IDs.
-jDisplays the process group ID and session ID.
-lDisplays a long listing
-plistDisplays data for the list of process IDs.
-slistDisplays data for the list of session leader IDs.
-tlistDisplays data for the list of terminals.
-ulistDisplays data for the list of usernames.

Examples

ps -ef
ps -aux


PWD Command


The pwd command displays the full pathname of the current directory.
The syntax for the pwd command is:
pwd



SU Command


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

OptionDescription
-Complete the entire login sequence.

Examples

su root
su tech


TAIL Command


The tail command displays the last ten lines of the file.
The syntax for the tail command is:
tail [options] [file]

Options

OptionDescription
-fFollow the file as it grows.
-rDisplays 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


TELNET Command


The telnet command allows you to communicate to another host using the TELNET protocol.
The syntax for the telnet command is:
telnet [host [port]]



VI Command


The vi command launches the text editor called vi.
The syntax for the vi command is:
vi [options] [files]

Options

OptionDescription
-ccommandLaunch vi and execute the command in vi.
-lEdit a LISP file.
-LLists all files that were saved due to an editor or system crash.
-rfileRecover and open file after an editor or system crash.
-RRead-only.
+Position on last line of file in vi.
+nPosition on n line of the file in vi.

Examples

vi + tech


WHOAMI Command

The whoami command displays your username.
The syntax for the whoami command is:
whoami



WHOIS Command


The whois command searches for the person, login, handle, or organization called name.
The syntax for the whois command is:
whois [option] name

Options

OptionDescription
-h hostSearches on host name called host.

Examples

whois tech