Unix Commands:-
For any help on commands refer http://www.computerhope.com/unix.htm
ls -lart
Long list of all files and directories
l- list of files
a-all hidden file i.e starting with . and ..
r-reverse order while storing
t-sort with modification time
ls -d */
- List the directories in the current directory
cat > test_file1.txt
This is a test file
Ctrl+d;
-To create a file and write data into that file
Cat test_file1.txt
-To read the content of a file
Cat >> test_file1.txt
This is the line appended
Ctrl+d
-To append data into exiting file
Cd /gita/test1
-To change the directory
Cp file1.txt file2.txt
-To copy file1 content to file2 content
Mv file1.txt file2.txt
-move file1 content to file2 and file1 will not exit anywhere
Difference between move and copy
A move command is simply a copy command which deletes the original once it's
finished.
rm –rf file1.txt
To remove a directory/file forcefully
Clear
To clear the screen
Pwd
pwd command displays the name of the current working directory.
More file1.txt
Content of a file one screenful at a time.Hitting the space bar brings the next screenful of
text.Pressing “q” quits the more command and brings back to unix shell
Mkdir test
To create a directory
Ifconfig
To know the ipaddress of the system
Ping 192.168.1.59
To check connectivity to remote system
SED TUTORIAL:http://www.sedtutorial.com/
# the following uses the editor sed to find blank lines
# and delete them:
# in the regex ^ means beginning of line,
# and $ means end of line
sed '/^$/d' myfile.txt >newfile.txt
mv newfile.txt myfile.txt
To read particular single line from a file
Sed -n 4p text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
To read multiple line in range from a file
Sed -n '200,250p' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
To delete 10th line in a file
Sed '10 d' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
To delete range of lines in a file
Sed '100,300 d' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
To remove all of the lines containing "two" from the myfile.txt file:
$ sed '/two/ d' myfile.txt
one 1
three 1
one 1
three 1
$
Remove spaces in a file
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
sed -e "s/[ <tab>]*//g" text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- --
A common use for this is to delete a header. The following command will delete all lines
in a file, from the first line through to the first blank line:
sed '1,/^$/ d' {filename}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Remove all blank line in a file
sed '/^$/ d' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
To delete all lines except those that contain the phrase "two," the syntax becomes:
$ sed '/two/ !d' myfile.txt
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
echo
Echo's to the screen what you type after echo. Echo is useful for producing diagnostics
in command files, for sending known data into a pipe, and for displaying the contents of
environment variables.
Syntax
echo [-n] text
-n On BSD and some variants derived from BSD does not begin a new line
after the echoed text.
Text The text that you want to echo to the screen.
Examples
echo Hello world
The above example would return "Hello world" to the console
echo * | wc
The above example would list a count of all the files and directories in the current
directory..
===================================================================
====
compress
Compacts a file so that it is smaller. When compressing a file it will be replaced with a
file with the extension .Z, while keeping all the same ownership modes.
Syntax
compress [-c] [-f] [-v] filenames
-c Write to the standard output; no files are changed and no .Z files are
created. The behavior of zcat is identical to that of `uncompress -c'.
-f When compressing, force compression of file , even if it does not actually
reduce the size of the file, or if the corresponding file .Z file already exists. If
the -f option is not given, and the process is not running in the background,
prompt to verify whether an existing file .Z file should be overwritten. When
uncompressing, do not prompt for overwriting files. If the -f option is not
given, and the process is not running in the background, prompt to verify
whether an existing file should be overwritten. If the standard input is not a
terminal and -f is not given, write a diagnostic message to standard error
and exit with a status greater than 0.
-v Shows you how much the file shrank in size.
Filenames The name of the file(s) that you wish to compress.
Examples
compress -v bigfile.exe - Would compress bigfile.exe and rename that file to
bigfile.exe.Z.
===================================================================
==
cmp
Compares two files and tells you which line numbers are different.
Syntax
cmp [-c] [-i N] [-l] [-s] [-v] firstfile secondfile
-c Output differing bytes as characters.
-i N Ignore differences in the first N bytes of input.
-l Write the byte number (decimal) and the differing bytes (octal) for each
difference.
-s Write nothing for differing files; return exit statuses only.
-v Output version info.
Firstfile First file that you wish to compare.
Secondfile Second file that you wish to compare to.
Examples
cmp file1.txt file2.txt - Compares file1 to file2 and outputs results. Below is example of
how these results may look.
file.txt file2.txt differ: char 1011, line 112
comm
Select or reject lines common to two files.
Syntax
comm [-1] [-2] [-3 ] file1 file2
-1 Suppress the output column of lines unique to file1.
-2 Suppress the output column of lines unique to file2.
-3 Suppress the output column of lines duplicated in file1 and file2.
file1 Name of the first file to compare.
file2 Name of the second file to compare.
Examples
comm myfile1.txt myfile2.txt
The above example would compare the two files myfile1.txt and myfile2.txt.
===================================================================
====
chown
Command for system V that changes the owner of a file.
Syntax
chown [-R] newowner filenames
-R Change the permission on files that are in the subdirectories of the directory
that you are currently in.
newowner The alias/username of the new owner of the file.
Filenames The file that you are changing the rights to.
Examples
Give permissions as owner to user hope for the file file.txt.
chown chope file.txt
Give chown permissions to hope for all files in the work directory.
chown -R hope work
===================================================================
====
head -15 myfile.txt
- Would display the first fifteen lines of myfile.txt.
tail myfile.txt
Delivers the last part of the file.
Syntax
tail [+ number] [-l] [-b] [-c] [-r] [-f] [-c number | -n number] [file]
+number
-number
This option is only recognized if it is specified first. COUNT is a decimal
number optionally followed by a size letter (`b', `k', `m') as in `-c', or `l' to
mean count by lines, or other option letters (`cfqv').
-l Units of lines.
-b Units of blocks.
-c Units of bytes.
-r Reverse. Copies lines from the specified starting point in the file in reverse
order. The default for r is to print the entire file in reverse order.
-f Follow. If the input-file is not a pipe, the program will not terminate after the
line of the input-file has been copied, but will enter an endless loop, wherein
it sleeps for a second and then attempts to read and copy further records
from the input-file. Thus it may be used to monitor the growth of a file that is
being written by some other process.
-c number The number option-argument must be a decimal integer whose sign affects
the location in the file, measured in bytes, to begin the copying:
+ Copying starts relative to the beginning of the file.
- Copying starts relative to the end of the file.
none Copying starts relative to the end of the file.
The origin for counting is 1; that is, -c+1 represents the first byte of the file, -
c-1 the last.
-n number Equivalent to -c number, except the starting location in the file is measured
in lines instead of bytes. The origin for counting is 1; that is, -n+1 represents
the first line of the file, -n- 1 the last.
File Name of the file you wish to display
Examples
tail myfile.txt
The above example would list the last 10 (default) lines of the file myfile.txt.
tail myfile.txt -n 100
The above example would list the last 100 lines in the file myfile.txt.
===================================================================
====
Cut
Cut out selected fields of each line of a file.
Syntax
cut [-b] [-c] [-f] list [-n] [-d delim] [-s] [file]
-b list The list following -b specifies byte positions (for instance, -b1- 72 would pass
the first 72
bytes of each line). When -b and -n are used together, list is adjusted so
that no multi-byte character is split. If -b is used, the input line should
contain 1023 bytes or less.
-c list The list following -c specifies character positions (for instance, -c1- 72 would
pass the first 72 characters of each line).
-f list The list following -f is a list of fields assumed to be separated in the file by a
delimiter character (see -d ); for instance, -f1,7 copies the first and seventh
field only. Lines with no field delimiters will be passed through intact (useful
for table subheadings), unless -s is specified. If -f is used, the input line
should contain 1023 characters or less.
List A comma-separated or blank-character- separated list of integer field
numbers (in increasing order), with optional - to indicate ranges (for
instance, 1,4,7; 1-3,8; -5,10 (short for 1-5,10); or 3- (short for third through
last field)).
-n Do not split characters. When -b list and -n are used together, list is
adjusted so that no multi-byte character is split.
-d delim The character following -d is the field delimiter (-f option only). Default is tab.
Space or other characters with special meaning to the shell must be quoted.
delim can be a multi-byte character.
-s Suppresses lines with no delimiter characters in case of -f option. Unless
specified, lines with no delimiters will be passed through untouched.
File A path name of an input file. If no file operands are specified, or if a file
operand is -, the standard input will be used.
Examples
name=`who am i | cut -f1 -d' '` - set name to current login name.
egrep
Search a file for a pattern using full regular expressions.
Syntax
egrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list ] [-f file ] [ strings ] [ file]
-b Precede each line by the block number on which it was found. This can be
useful in locating block numbers by context (first block is 0).
-c Print only a count of the lines that contain the pattern.
-h Suppress printing of filenames when searching multiple files.
-i Ignore upper/lower case distinction during comparisons.
-l Print the names of files with matching lines once, separated by NEWLINEs.
Does not repeat the names of files when the pattern is found more than
once.
-n Precede each line by its line number in the file (first line is 1).
-s Work silently, that is, display nothing except error messages. This is useful
for checking the error status.
-v Print all lines except those that contain the pattern.
-x Consider only input lines that use all characters in the line to match an
entire fixed string or regular expression to be matching lines.
-e
pattern_list
Search for a pattern_list (full regular expression that begins with a -).
-f file Take the list of full regular expressions from file.
Strings Specify a pattern to be used during the search for input.
File A path name of a file to be searched for the patterns. If no file operands are
specified, the standard input will be used.
Examples
egrep "support|help|windows" myfile.txt - Would search for patterns of support help and
windows in the file myfile.txt.
===================================================================
====
Grep –in “kk” test1.txt
Gives the line number of the first match of “kk” in test1.txt without case sensitivity
Finds text within a file.
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
-A NUM, -- after-
context=NUM
Print NUM lines of trailing context after matching lines. Places a
line containing -- between contiguous groups of matches.
-a, -- text Process a binary file as if it were text; this is equivalent to the --
binary-files=text option.
-B NUM, -- before-
context=NUM
Print NUM lines of leading context before matching lines. Places a
line containing -- between contiguous groups of matches.
-b, -- byte-offset Print the byte offset within the input file before each line of output.
-- binary-files=TYPE If the first few bytes of a file indicate that the file contains binary
data, assume that the file is of type TYPE. By default, TYPE is
binary, and grep normally outputs either a one-line message
saying that a binary file matches, or no message if there is no
match. If TYPE is without-match, grep assumes that a binary file
does not match; this is equivalent to the -I option. If TYPE is text,
grep processes a binary file as if it were text; this is equivalent to
the -a option. Warning: grep -- binary-files=text might output binary
garbage, which can have nasty side effects if the output is a
terminal and if the terminal driver interprets some of it as
commands.
-C NUM, --
context=NUM
Print NUM lines of output context. Places a line containing --
between contiguous groups of matches.
-c, -- count Suppress normal output; instead print a count of matching lines for
each input file. With the -v, -- invert-match option (see below),
count non-matching lines.
-- colour[=WHEN], --
color[=WHEN]
Surround the matching string with the marker find in
GREP_COLOR environment variable. WHEN may be `never',
`always', or `auto'
-D ACTION, --
devices=ACTION
If an input file is a device, FIFO or socket, use ACTION to process
it. By default, ACTION is read, which means that devices are read
just as if they were ordinary files. If ACTION is skip, devices are
silently skipped.
-d ACTION, --
directories=ACTION
If an input file is a directory, use ACTION to process it. By default,
ACTION is read, which means that directories are read just as if
they were ordinary files. If ACTION is skip, directories are silently
skipped. If ACTION is recurse, grep reads all files under each
directory, recursively; this is equivalent to the -r option.
-E, -- extended-
regexp
Interpret PATTERN as an extended regular expression (see
below).
-e PATTERN, -- Use PATTERN as the pattern; useful to protect patterns beginning
regexp=PATTERN with -.
-F, -- fixed-strings Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched.
-f FILE, -- file=FILE Obtain patterns from FILE, one per line. The empty file contains
zero patterns, and therefore matches nothing.
-G, -- basic-regexp Interpret PATTERN as a basic regular expression (see below).
This is the default.
-H, -- with-filename Print the filename for each match.
-h, -- no-filename Suppress the prefixing of filenames on output when multiple files
are searched.
-- help Output a brief help message.
-I Process a binary file as if it did not contain matching data; this is
equivalent to the -- binary-files=without match option.
-i, -- ignore-case Ignore case distinctions in both the PATTERN and the input files.
-L, -- files-without-
match
Suppress normal output; instead print the name of each input file
from which no output would normally have been printed. The
scanning will stop on the first match.
-l, -- files-with-
matches
Suppress normal output; instead print the name of each input file
from which output would normally have been printed. The
scanning will stop on the first match.
-- label=LABEL Displays input actually coming from standard input as input
coming from file LABEL. This is especially useful for tools like
zgrep, e.g. gzip -cd foo.gz |grep -- label=foo something
-- line-buffered Use line buffering, it can be a performance penalty.
-m NUM, -- max-
count=NUM
Stop reading a file after NUM matching lines. If the input is
standard input from a regular file, and NUM matching lines are
output, grep ensures that the standard input is positioned to just
after the last matching line before exiting, regardless of the
presence of trailing context lines. This enables a calling process to
resume a search. When grep stops after NUM matching lines, it
outputs any trailing context lines. When the -c or -- count option is
also used, grep does not output a count greater than NUM. When
the -v or -- invert-match option is also used, grep stops after
outputting NUM non-matching lines.
-- mmap ations, -- mmap yields better performance. However, -- mmap can
cause undefined behavior (including core dumps) if an input file
shrinks while grep is operating, or if an I/O error occurs.
-n, -- line-number Prefix each line of output with the line number within its input file.
-o, -- only-matching Show only the part of a matching line that matches PATTERN.
-P, -- perl-regexp Interpret PATTERN as a Perl regular expression.
-q, -- quiet, -- silent Quiet; do not write anything to standard output. Exit immediately
with zero status if any match is found, even if an error was
detected. Also see the -s or -- no-messages option.
-R, -r, -- recursive Read all files under each directory, recursively; this is equivalent to
the -d recurse option.
--
include=PATTERN
Recurse in directories only searching file matching PATTERN.
--
exclude=PATTERN
Recurse in directories skip file matching PATTERN.
-s, -- no-messages Suppress error messages about nonexistent or unreadable files.
Portability note: unlike GNU grep, traditional grep did not conform
to POSIX.2, because traditional grep lacked a -q option and its -s
option behaved like GNU grep's -q option. Shell scripts intended to
be portable to traditional grep should avoid both -q and -s and
should redirect output to /dev/null instead.
-U, -- binary Treat the file(s) as binary. By default, under MS-DOS and MS-
Windows, grep guesses the file type by looking at
the contents of the first 32KB read from the file. If grep decides the
file is a text file, it strips the CR characters from the original file
contents (to make regular expressions with ^ and $ work
correctly). Specifying -U overrules this guesswork, causing all files
to be read and passed to the matching mechanism verbatim; if the
file is a text file with CR/LF pairs at the end of each line, this will
cause some regular expressions to fail. This option has no effect
on platforms other than MS-DOS and MS-Windows.
-u, -- unix-byte-
offsets
Report Unix-style byte offsets. This switch causes grep to report
byte offsets as if the file were Unix-style text file, i.e. with CR
characters stripped off. This will produce results identical to
running grep on a Unix machine. This option has no effect unless -
b option is also used; it has no effect on platforms other than MS-
DOS and MS-Windows.
-V, -- version Print the version number of grep to standard error. This version
number should be included in all bug reports (see below).
-v, -- invert-match Invert the sense of matching, to select non-matching lines.
-w, -- word-regexp Select only those lines containing matches that form whole words.
The test is that the matching substring must either be at the
beginning of the line, or preceded by a non-word constituent
character. Similarly, it must be either at the end of the line or
followed by a non-word constituent character. Word-constituent
characters are letters, digits, and the underscore.
-x, -- line-regexp Select only those matches that exactly match the whole line.
-y Obsolete synonym for -i.
-Z, -- null Output a zero byte (the ASCII NUL character) instead of the
character that normally follows a file name. For example, grep -lZ
outputs a zero byte after each file name instead of the usual
newline. This option makes the output unambiguous, even in the
presence of file names containing unusual characters like
newlines. This option can be used with commands like find -print0,
perl -0, sort -z, and xargs -0 to process arbitrary file names, even
those that contain newline characters.
-z, -- null-data Treat the input as a set of lines, each terminated by a zero byte
(the ASCII NUL character) instead of a newline. Like the -Z or --
null option, this option can be used with commands like sort -z to
process arbitrary file names.
Patterns for searching.
. Matches single character.
* Wild character Example C* if found would pull up CC or CAT...
{} Matches any character contained within the bracket.
^ Represents the beginning of the line, so if you did ^T it would search for any
sentence starting with a T.
$ Represents the end of the line, so if you did $. then it would pull up any lines
that ended with .
\ Means to take the next character serious so you could search for C\ C.
Note: Be careful using the characters $, *, [, ^, |, (, ), and \ in the pattern list because
they are also meaningful to the shell. It is safest to enclose the entire pattern list in single
quotes '... '.
Examples
grep "unix" *.htm
search all .htm files in the current directory for any reference of unix and give results
similar to the below example text.
asoftwar.htm: href="win95.htm">Windows 95</a>, <a href="unix.htm">Unix</a>, <a
href="msdos.htm">MS-DOS</a>,
asoftwar.htm: <td><font face="Times New Roman"><a name="U"></a><a
href="unix.htm"><strong>Unix</strong></a></font></td>
learnhtm.htm: <a href="unix.htm">Unix help</a><br>
os.htm: <a href="unix.htm">Unix</a><br>
As seen above the grep command has found references of unix in some of the HTML
files in our home directory. The file name that contains unix is listed at the beginning of
the line followed by a colon and the text continuing unix.
chmod –R 644 files
Changes the permission of a file.
-R change files and directories recursively
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
Examples
The above numeric permissions can be added to set a certain permission, for example,
a common HTML file on a Unix server to be only viewed over the Internet would be:
chmod 644 file.htm
This gives the file read/write by the owner and only read by everyone else (-rw- r-- r-- ).
Files such as scripts that need to be executed need more permissions. Below is another
example of a common permission given to scripts.
chmod 755 file.cgi
This would be the following 400+040+004+200+100+010+001 = 755 where you are
giving all the rights except the capability for anyone to write to the file.cgi file(-rwxr- xr-x).
Finally, another common CHMOD permission is 666, as shown below, which is read and
write by everyone.
chmod 666 file.txt
Additional information
Below is an example of how a file may be listed when typing ( ls -l ) at the prompt as well
as information on how to interpret it.
-rw- rw-r- - 1 hope 123 Feb 03 15:36 file.txt
- Rw rw- r-- 1 hope 123 Feb 03 15:36 file.txt
File owner group everyone else links owner size mod date file name
Display or list all directories
Type the following command:
$ ls -l | egrep `^d'
Display or list only files
Type the following command:
$ ls -l | egrep -v `^d'
grep command used to searches input. It will filter out directories name by matching first
character d. To reverse effect (just to display files) you need to pass -v option. It invert
the sense of matching, to select non-matching lines.
crontab
List of files that you want to run on a regular schedule.
Syntax
crontab [-e] [-l] [-r] [filename]
-e edit a copy of the current user's crontab file, or creates an empty file to edit
if crontab does not exist. When editing is complete, the file is installed as the
user's crontab file. If a user- name is given, the specified user's crontab file
is edited, rather than the current user's crontab file; this may only be done
by a super-user. The environment variable EDITOR determines which editor
is invoked with the -e option. The default editor is ed. Note that all crontab
jobs should be submitted using crontab ; you should not add jobs by just
editing the crontab file because cron will not be aware of changes made this
way.
-l list the crontab file for the invoking user. Only a super-user can specify a
username following the -r or -l options to remove or list the crontab file of the
specified user.
-r remove a user's crontab from the crontab
Filename The filename that contains the commands to run.
Lines that can be in the crontab file.
minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).
Examples
crontab -e = edits the crontab file to be used.
0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.
Below is a table that represents what each of the above fields are for.
min hour dayofmonth monthofyear dayofweek command
0 12 14 2 * mailx john%Happy Birthday!%Time
for lunch.
Options Explanation
* Is treated as a wild card. Meaning any possible value.
*/5 Is treated as ever 5 minutes, hours, days, or months. Replacing the 5 with
another numerical value will change this option.
2,4,6 Treated as an OR, so if placed in the hours, this could mean at 2, 4, or 6 o-
clock.
9-17 Treats for any value between 9 and 17. So if placed in day of month this would
be days 9 through 17. Or if put in hours it would be between 9 and 5.
If you wish to create a task to be performed once later during the day you may wish to
consider using the at command.
kill
Cancels a job.
Syntax
kill [-s] [-l] %pid
-s Specify the signal to send, using one of the symbolic names defined in the
<signal.h> description. Values of signal will be recognized in a case
independent fashion, without the SIG prefix. In addition, the symbolic name
0 will be recognized, representing the signal value zero. The corresponding
signal will be sent instead of SIGTERM.
-l Write all values of signal sup ported by the implementation, if no operand is
given. If an exit_status operand is given and it is a value of the ? shell
special parameter and wait corresponding to a process that was ter minated
by a signal, the signal corresponding to the signal that terminated the
process will be written. If an exit_status operand is given and it is the
unsigned decimal integer value of a signal number, the signal corresponding
to that signal will be written. Otherwise, the results are unspecified.
pid One of the following:
1. A decimal integer specifying a process or process group to be signaled.
The process or processes selected by positive, negative and zero values of
the pid operand will be as
described for the kill function. If process number 0 is specified, all processes
in the process group are signaled. If the first pid operand is negative, it
should be preceded by -- to keep it from being interpreted as an option.
2. A job control job ID that identifies a background process group to be
signaled. The job control job ID notation is applicable only for invocations of
kill in the current shell execution environment.
Note the job control job ID type of pid is available only on systems
supporting the job control option.
Examples
kill -s kill 100 -165
Kills job 1 of uid 165
When running the kill command you may receive the error "Operation not permitted", this
is often encountered when you're killing the wrong group id (often 1,2,3 or low number
jobs) that you don't have permission to kill. If you wish to see the group id of the
background task run jobs -l
find
Finds one or more files assuming that you know their approximate filenames.
Syntax
find path expressions
path A path name of a starting point in the directory hierarchy.
-atime n True if the file was accessed n days ago. The access time of directories in
path is changed by find itself.
-cpio
device
Always true; write the current file on device in cpio format (5120-byte
records).
-ctime n True if the file's status was changed n days ago.
-depth Always true; causes descent of the directory hierarchy to be done so that all
entries in a directory are acted on before the directory itself. This can be
useful when find is used with cpio to transfer files that are contain edin
directories without write permission.
-exec
command
True if the executed command returns a zero value as exit status. The end
of command must be punctuated by an escaped semicolon. A command
argument {} is replaced by the current path name.
-follow Always true; causes symbolic links to be followed. When following symbolic
links, find keeps track of the directories visited so that it can detect infinite
loops; for example, such a loop would occur if a symbolic link pointed to an
ancestor. This expression should not be used with the -type l expression.
-fstype
type
True if the filesystem to which the file belongs is of type type .
-group
gname
True if the file belongs to the group gname. If gname is numeric and does
not appear in the /etc/group file, it is taken as a group ID.
-inum n True if the file has inode number n.
-links True if the file has n links.
-local True if the file system type is not a remote file system type as defined in the
/etc/dfs/fstypes file. nfsis used as the default remote filesystem type if
the/etc/dfs/fstypes file is not present.
-ls Always true; prints current path name together
with its associated statistics. These include
(respectively):
inode number
size in kilobytes (1024 bytes)
protection mode
number of hard links
user
group
size in bytes
modification time.
If the file is a special file the size field will instead contain the major and
minor device numbers.
If the file is a symbolic link the pathname of the linked-to file is printed
preceded by `->'. The format is identical to that of ls -gilds ls Note:
Formatting is done internally, without executing the ls program.
-mount Always true; restricts the search to the file system containing the directory
specified. Does not list mount points to other file systems.
-mtime n True if the file's data was modified n days ago.
-name
pattern
True if pattern matches the current file name. Normal shell file name
generation characters (see sh) may be used. A backslash (\) is used as an
escape character within the pattern. The pattern should be escaped or
quoted when find is invoked from the shell.
-ncpio
device
Always true; write the current file on device in cpio -c format (5120 byte
records).
-newer file True if the current file has been modified more recently than the argument
file.
-nogroup True if the file belongs to a group not in the /etc/group file.
-nouser True if the file belongs to a user not in the /etc/passwd file.
-ok
command
Like -exec except that the generated command line is printed with a
question mark first, and is executed only if the user responds by typing y.
-perm [-
]mode
The mode argument is used to represent file mode bits. It will be identical in
format to the <symbolicmode> operand described in chmod, and will be
interpreted as follows. To start, a template will be assumed with all file mode
bits cleared. An op symbol of:
+ will set the appropriate mode bits in the template;
- will clear the appropriate bits;
= will set the appropriate mode bits, without regard to the contents of
process' file mode creation mask.
The op symbol of - cannot be the first character of mode; this avoids
ambiguity with the optional leading hyphen. Since the initial mode is all bits
off, there are not any symbolic modes that need to use - as the first
character.
If the hyphen is omitted, the primary will evaluate as true when the file
permission bits exactly match the value of the resulting template.
Otherwise, if mode is prefixed by a hyphen, the primary will evaluate as true
if at least all the bits in the resulting template are set in the file permission
bits.
-perm [-
]onum
True if the file permission flags exactly match the octal number onum see
chmod). If onum is prefixed by a minus sign (-), only the bits that are set in
onum are compared with the file permission flags, and the expression
evaluates true if they match.
-print Always true; causes the current path name to be printed.
-prune Always yields true. Do not examine any directories or files in the directory
structure below the pattern just matched. If -depth is specified, -prune will
have no effect.
-size n[c] True if the file is n blocks long (512 bytes per block). If n is followed by a c,
the size is in
bytes.
-type c True if the type of the file is c, where c is b, c, d, D, f, l, p, or s for block
special file, character special file, directory, door, plain file, symbolic link, fifo
(named pipe), or socket, respectively.
-user
uname
True if the file belongs to the user uname . If uname is numeric and does
not appear as a login name in the /etc/passwd file, it is taken as a user ID.
-xdev Same as the -mount primary.
When using find to determine files modified within a range of time, one must use the
?time argument before the -print argument; otherwise, find will give all files.
Examples
find -name 'mypage.htm'
In the above command the system would search for any file named mypage.htm in the
current directory and any subdirectory.
find / -name 'mypage.htm'
In the above example the system would search for any file named mypage.htm on the
root and all subdirectories from the root.
find -name 'file*'
In the above example the system would search for any file beginning with file in the
current directory and any subdirectory.
find -name '*' -size +1000k
In the above example the system would search for any file that is larger then 1000k.
find . -size +500000 -print
Next, similar to the above example, just formatted differently this command would find
anything above 500MB
jobs
Lists the jobs that you are running in the background and in the foreground. If the prompt
is returned with no information no jobs are present. Note: not all shells are capable of
running this command.
Syntax
jobs [-p | -l] [-n] [-p] [-x] [job id]
-p | -l Report the process group ID and working directory of the jobs.
-n Display only jobs that have stopped or exited since last notified.
-p Displays only the process IDs for the process group leaders of the selected
jobs.
-x Replace any job_id found in command or arguments with the corresponding
process group ID, and then execute command passing it arguments.
job id The job id.
Examples
jobs
Would display results similar to the below if jobs were running in the background.
[1] + Stopped (user) man jobs
As you can see in the above job example the id is 1 it has been stopped by the user and
the process in this case is man jobs (looking at the manual for jobs).
jobs -l
The above command would not just list the jobs running but also this group ID and the
working directory of the jobs. Below is an example of what this would display.
[3] 16882 Running ./chsearchproc (wd: ~/public_html/cgi-bin/chsearch)
ps
Reports the process status.
Syntax
ps [-a] [-A] [-c] [-d] [-e] [-f] [-j] [-l] [-L] [-P] [-y] [ -g grplist ] [ -n namelist ] [-o format ] [ -p
proclist ] [ -s sidlist ] [ -t term] [ -u uidlist ] [ -U uidlist ] [ -G gidlist ]
-a List information about all processes most frequently requested: all those
except process group leaders and processes not associated with a terminal.
-A List information for all processes. Identical to -e, below.
-c Print information in a format that reflects scheduler properties as described
in priocntl.
The -c option affects the output of the -f and -l options, as described below.
-d List information about all processes except session leaders.
-e List information about every process now running.
-f Generate a full listing.
-j Print session ID and process group ID.
-l Generate a long listing.
-L Print information about each light weight process (lwp) in each selected
process.
-P Print the number of the processor to which the process or lwp is bound, if
any, under an additional column header, PSR.
-y Under a long listing (-l), omit the obsolete F and ADDR columns and include
an RSS column to report the resident set size of the process. Under the -y
option, both RSS and SZ will be reported in units of kilobytes instead of
pages.
-g grplist List only process data whose group leader's ID number(s) appears in grplist.
(A group leader is a process whose process ID number is identical to its
process group ID number.)
-n
namelist
Specify the name of an alternative system namelist file in place of the
default. This option is accepted for compatibility, but is ignored.
-o format Print information according to the format specification given in format. This
is fully described in DISPLAY FORMATS. Multiple -o options can be
specified; the format specification will be interpreted as the space-character-
separated concatenation of all the format option-arguments.
-p proclist List only process data whose process ID numbers are given in proclist.
-s sidlist List information on all session leaders whose IDs appear in sidlist.
-t term List only process data associated with term. Terminal identifiers are
specified as a device file name, and an identifier. For example, term/a, or
pts/0.
-u uidlist List only process data whose effective user ID number or login name is
given in uidlist. In the listing, the numerical user ID will be printed unless you
give the -f option, which prints the login name.
-U uidlist List information for processes whose real user ID numbers or login names
are given in uidlist. The uidlist must be a single argument in the form of a
blank- or comma-separated list.
-G gidlist List information for processes whose real group ID numbers are given in
gidlist. The gidlist must be a single argument in the form of a blank- or
comma-separated list.
Examples
ps
Typing ps alone would list the current running processes. Below is an example of the
output that would be generated by the ps command.
PID TTY TIME CMD
6874 pts/9 0:00 ksh
6877 pts/9 0:01 csh
418 pts/9 0:00 csh
ps -ef
Display full information about each of the processes currently running.
UID PID PPID C STIME TTY TIME CMD
hope 29197 18961 0 Sep27 ? 00:00:06 sshd: hope@pts/87
hope 32097 29197 0 Sep27 pts/87 00:00:00 -csh
hope 7209 32097 0 12:17 pts/87 00:00:00 ps -ef
ps -l
Displays processes including those that are in a wait state, similar to the below example.
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 T 0 12308 29722 0
80 0 - 16136 finish pts/0 00:00:00 pico 0 R 0 12530 29722 0 80 0 - 15884 - pts/0
00:00:00 ps 4 S 0 29722 29581 0 80 0 - 16525 wait pts/0 00:00:00 bash
wc
Short for word count, wc displays a count of lines, words, and characters in a file.
Syntax
wc [-c | -m | -C ] [-l] [-w] [ file ... ]
-c Count bytes.
-m Count characters.
-C Same as -m.
-l Count lines.
-w Count words delimited by white space characters or new line characters.
Delimiting characters are Extended Unix Code (EUC) characters from any
code set defined by iswspace()
file Name of file to word count.
Examples
wc myfile.txt - Displays information about the file myfile.txt. Below is an example of the
output.
5 13 57 myfile.txt
5 = Lines
13 = Words
57 = Characters
===============================================================
settime and touch
Change file access and modification time.
Syntax
touch [-a] [-c] [-m] [-r ref_file | -t time ] file
settime [ -f ref_file ] file
-a Change the access time of file. Do not change the modification time unless -
m is also specified.
-c Do not create a specified file if it does not exist. Do not write any diagnostic
messages concerning this condition.
-m Change the modification time of file. Do not change the access time unless -
a is also specified.
-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:
[[CC]YY]MMDDhhmm [.SS]
MM - The month of the year [01-12].
DD - The day of the month [01-31].
hh - The hour of the day [00-23].
mm - The minute of the hour [00-59].
CC - The first two digits of the year.
YY - The second two digits of the year.
SS - The second of the minute [00-61].
-f ref_file Use the corresponding times of the file named by ref_file instead of the
current time.
file A path name of a file whose times are to be modified.
Examples
settime myfile.txt
Sets the file myfile.txt as the current time / date.
touch newfile.txt
Creates a file known as "newfile.txt", if the file does not already exist. If the file already
exists the accessed / modification time is updated for the file newfile.txt
tar
Create tape archives and add or extract files.
Syntax
tar c [ bBeEfFhiklnopPqvwX [ 0-7 ] ] [ block ] [ tarfile ] [ exclude-file ] {-I include-file | -C
directory | file | file }
tar r [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] {-I include-file | -C directory | file | file }
tar t [ BefFhiklnqvX [ 0-7 ] ] [ tarfile ] [ exclude-file ] {-I include-file | file } ...
tar u [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] [ tarfile ] file ...
tar x [ BefFhiklmnopqvwX [ 0-7 ] ] [ tarfile ] [ exclude-file ] [ file ... ]
c Create. Writing begins at the beginning of the tarfile, instead of at the end.
r Replace. The named file s are written at the end of the tarfile. A file created
with extended headers must be updated with extended headers (see E flag
under Function Modifiers). A file created without extended headers cannot
be modified with extended headers.
t Table of Contents. The names of the specified files are listed each time they
occur in the tar file. If no file argument is given, the names of all files in the
tarfile are listed. With the v
function modifier, additional information for the specified files is displayed.
u Update. The named file s are written at the end of the tarfile if they are not
already in the tar file, or if they have been modified since last written to that
tarfile. An update can be rather slow. A tarfile created on a 5.x system
cannot be updated on a 4.x system. A file created with extended headers
must be updated with extended headers (see E flag under Function
Modifiers). A file created without extended headers cannot be modified with
extended headers.
x Extract or restore. The named file s are extracted from the tarfile and written
to the directory specified in the tarfile, relative to the current directory. Use
the relative path names of files and directories to be extracted. If a named
file matches a directory whose contents has been writ ten to the tarfile, this
directory is recursively extracted. The owner, modification time, and mode
are restored (if possible); otherwise, to restore owner, you must be the
super-user. Character special and block-special devices (created by
mknod(1M)) can only be extracted by the super user. If no file argument is
given, the entire content of the tarfile is extracted. If the tar- file contains
several files with the same name, each file is written to the appropriate
directory, overwriting the previous one. Filename substitu tion wildcards
cannot be used for extracting files from the archive; rather, use a command
of the form:
tar xvf... /dev/rmt/0 `tar tf... /dev/rmt/0 | grep 'pattern' `
When extracting tapes created with the r or u functions, directory
modification times may not be set correctly. These same functions cannot
be used with many tape drives due to tape drive limitations such as the
absence of backspace or append capabilities.
When using the r, u, or x functions or the X function modifier, the named
files must match exactly the corresponding files in the tarfile. For example,
to extract ./thisfile, you must specify ./thisfile, and not thisfile. The t function
displays how each file was archived.
Function Modifiers
The characters below may be used in conjunction with the letter that selects the desired
function.
b Blocking Factor. Use when reading or writing to raw magnetic archives (see
f below). The block argument specifies the number of 512-byte tape blocks
to be included in each read or write operation performed on the tarfile. The
minimum is 1, the default is 20. The maximum value is a function of the
amount of memory available and the blocking requirements of the specific
tape device involved (see mtio(7I) for details.) The maximum cannot
exceed INT_MAX/512 (4194303).
When a tape archive is being read, its actual blocking factor will be
automatically detected, provided that it is less than or equal to the nominal
blocking factor (the value of the block argument, or the default value if the b
modifier is not specified). If the actual blocking factor is greater than the
nominal blocking factor, a read error will result. See Example 5 in Examples.
B Block. Force tar to perform multiple reads (if necessary) to read exactly
enough bytes to fill a block. This function modifier enables tar to work
across the Ethernet, since pipes and sockets return partial blocks even
when more data is coming. When reading from standard input, '-', this
function modifier is selected by default to ensure that tar can recover from
short reads.
e Error. Exit immediately with a positive exit status if any unexpected errors
occur. The SYSV3 environment variable overrides the default behavior.
(See ENVIRONMENT section below.)
E Write a tarfile with extended headers. (Used with c, r, or u options; ignored
with t or x options.) When a tarfile is written with extended headers, the
modification time is maintained with a granularity of microseconds rather
than seconds. In addition, filenames no longer than PATH_MAX characters
that could not be archived without E, and file sizes greater than 8GB, are
supported. The E flag is required whenever the larger files and/or files with
longer names, or whose UID/GID exceed 2097151, are to be archived, or if
time granularity of microseconds is desired.
f File. Use the tarfile argument as the name of the tarfile. If f is specified,
/etc/default/tar is
not searched. If f is omitted, tar will use the device indicated by the TAPE
environment variable, if set; otherwise, it will use the default values defined
in /etc/default/tar. If the name of the tarfile is '-', tar writes to the standard
output or reads from the standard input, whichever is appropriate. tar can be
used as the head or tail of a pipeline. tar can also be used to move
hierarchies with the command:
example% cd fromdir; tar cf - .| (cd todir; tar xfBp -)
F With one F argument, tar excludes all directories named SCCS and RCS
from the tarfile. With two arguments, FF, tar excludes all directories named
SCCS and RCS, all files with .o as their suffix, and all files named errs, core,
and a.out. The SYSV3 environment variable overrides the default behavior.
(See ENVIRONMENT section below.)
h Follow symbolic links as if they were normal files or directories. Normally, tar
does not follow symbolic links.
i Ignore directory checksum errors.
-j, -- bzip2 filter archive through bzip2, use to decompress .bz2 files. WARNING: some
previous versions of tar used option -I to filter through bzip2. When writing
scripts, use -- bzip2 instead of -j so that both older and newer tar versions
will work.
k size Requires tar to use the size argument as the size of an archive in kilobytes.
This is useful when the archive is intended for a fixed size device such as
floppy disks. Large files are then split across volumes if they do not fit in the
specified size.
l Link. Output error message if unable to resolve all links to the files being
archived. If l is not specified, no error messages are printed.
m Modify. The modification time of the file is the time of extraction. This
function modifier is
valid only with the x function.
n The file being read is a non-tape device. Reading of the archive is faster
since tar can randomly seek around the archive.
o Ownership. Assign to extracted files the user and group identifiers of the
user running the program, rather than those on tarfile. This is the default
behavior for users other than root. If the o function modifier is not set and
the user is root, the extracted files will take on the group and user identifiers
of the files on tarfile (see chown for more information). The o function
modifier is only valid with the x function.
p Restore the named files to their original modes, and ACLs if applicable,
ignoring the present umask. This is the default behavior if invoked as super-
user with the x function letter specified. If super-user, SETUID and sticky
information are also extracted, and files are restored with their original
owners and permissions, rather than owned by root. When this function
modifier is used with the c function, ACLs are created in the tarfile along
with other information. Errors will occur when a tarfile with ACLs is extracted
by
previous versions of tar .
P Suppress the addition of a trailing "/" on directory entries in the archive.
q Stop after extracting the first occurrence of the named file. tar will normally
continue reading the archive after finding an occurrence of a file.
v Verbose. Output the name of each file preceded by the function letter. With
the t function, v provides additional information about the tarfile entries. The
listing is similar to the format produced by the -l option of the ls command.
w What. Output the action to be taken and the name of the file, then await the
user's confirmation. If the response is affirmative, the action is performed;
otherwise, the action is not performed. This function modifier cannot be
used with the t function.
For any help on commands refer http://www.computerhope.com/unix.htm
ls -lart
Long list of all files and directories
l- list of files
a-all hidden file i.e starting with . and ..
r-reverse order while storing
t-sort with modification time
ls -d */
- List the directories in the current directory
cat > test_file1.txt
This is a test file
Ctrl+d;
-To create a file and write data into that file
Cat test_file1.txt
-To read the content of a file
Cat >> test_file1.txt
This is the line appended
Ctrl+d
-To append data into exiting file
Cd /gita/test1
-To change the directory
Cp file1.txt file2.txt
-To copy file1 content to file2 content
Mv file1.txt file2.txt
-move file1 content to file2 and file1 will not exit anywhere
Difference between move and copy
A move command is simply a copy command which deletes the original once it's
finished.
rm –rf file1.txt
To remove a directory/file forcefully
Clear
To clear the screen
Pwd
pwd command displays the name of the current working directory.
More file1.txt
Content of a file one screenful at a time.Hitting the space bar brings the next screenful of
text.Pressing “q” quits the more command and brings back to unix shell
Mkdir test
To create a directory
Ifconfig
To know the ipaddress of the system
Ping 192.168.1.59
To check connectivity to remote system
SED TUTORIAL:http://www.sedtutorial.com/
# the following uses the editor sed to find blank lines
# and delete them:
# in the regex ^ means beginning of line,
# and $ means end of line
sed '/^$/d' myfile.txt >newfile.txt
mv newfile.txt myfile.txt
To read particular single line from a file
Sed -n 4p text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
To read multiple line in range from a file
Sed -n '200,250p' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
To delete 10th line in a file
Sed '10 d' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
To delete range of lines in a file
Sed '100,300 d' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
To remove all of the lines containing "two" from the myfile.txt file:
$ sed '/two/ d' myfile.txt
one 1
three 1
one 1
three 1
$
Remove spaces in a file
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
sed -e "s/[ <tab>]*//g" text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- --
A common use for this is to delete a header. The following command will delete all lines
in a file, from the first line through to the first blank line:
sed '1,/^$/ d' {filename}
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Remove all blank line in a file
sed '/^$/ d' text.dat
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
To delete all lines except those that contain the phrase "two," the syntax becomes:
$ sed '/two/ !d' myfile.txt
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
echo
Echo's to the screen what you type after echo. Echo is useful for producing diagnostics
in command files, for sending known data into a pipe, and for displaying the contents of
environment variables.
Syntax
echo [-n] text
-n On BSD and some variants derived from BSD does not begin a new line
after the echoed text.
Text The text that you want to echo to the screen.
Examples
echo Hello world
The above example would return "Hello world" to the console
echo * | wc
The above example would list a count of all the files and directories in the current
directory..
===================================================================
====
compress
Compacts a file so that it is smaller. When compressing a file it will be replaced with a
file with the extension .Z, while keeping all the same ownership modes.
Syntax
compress [-c] [-f] [-v] filenames
-c Write to the standard output; no files are changed and no .Z files are
created. The behavior of zcat is identical to that of `uncompress -c'.
-f When compressing, force compression of file , even if it does not actually
reduce the size of the file, or if the corresponding file .Z file already exists. If
the -f option is not given, and the process is not running in the background,
prompt to verify whether an existing file .Z file should be overwritten. When
uncompressing, do not prompt for overwriting files. If the -f option is not
given, and the process is not running in the background, prompt to verify
whether an existing file should be overwritten. If the standard input is not a
terminal and -f is not given, write a diagnostic message to standard error
and exit with a status greater than 0.
-v Shows you how much the file shrank in size.
Filenames The name of the file(s) that you wish to compress.
Examples
compress -v bigfile.exe - Would compress bigfile.exe and rename that file to
bigfile.exe.Z.
===================================================================
==
cmp
Compares two files and tells you which line numbers are different.
Syntax
cmp [-c] [-i N] [-l] [-s] [-v] firstfile secondfile
-c Output differing bytes as characters.
-i N Ignore differences in the first N bytes of input.
-l Write the byte number (decimal) and the differing bytes (octal) for each
difference.
-s Write nothing for differing files; return exit statuses only.
-v Output version info.
Firstfile First file that you wish to compare.
Secondfile Second file that you wish to compare to.
Examples
cmp file1.txt file2.txt - Compares file1 to file2 and outputs results. Below is example of
how these results may look.
file.txt file2.txt differ: char 1011, line 112
comm
Select or reject lines common to two files.
Syntax
comm [-1] [-2] [-3 ] file1 file2
-1 Suppress the output column of lines unique to file1.
-2 Suppress the output column of lines unique to file2.
-3 Suppress the output column of lines duplicated in file1 and file2.
file1 Name of the first file to compare.
file2 Name of the second file to compare.
Examples
comm myfile1.txt myfile2.txt
The above example would compare the two files myfile1.txt and myfile2.txt.
===================================================================
====
chown
Command for system V that changes the owner of a file.
Syntax
chown [-R] newowner filenames
-R Change the permission on files that are in the subdirectories of the directory
that you are currently in.
newowner The alias/username of the new owner of the file.
Filenames The file that you are changing the rights to.
Examples
Give permissions as owner to user hope for the file file.txt.
chown chope file.txt
Give chown permissions to hope for all files in the work directory.
chown -R hope work
===================================================================
====
head -15 myfile.txt
- Would display the first fifteen lines of myfile.txt.
tail myfile.txt
Delivers the last part of the file.
Syntax
tail [+ number] [-l] [-b] [-c] [-r] [-f] [-c number | -n number] [file]
+number
-number
This option is only recognized if it is specified first. COUNT is a decimal
number optionally followed by a size letter (`b', `k', `m') as in `-c', or `l' to
mean count by lines, or other option letters (`cfqv').
-l Units of lines.
-b Units of blocks.
-c Units of bytes.
-r Reverse. Copies lines from the specified starting point in the file in reverse
order. The default for r is to print the entire file in reverse order.
-f Follow. If the input-file is not a pipe, the program will not terminate after the
line of the input-file has been copied, but will enter an endless loop, wherein
it sleeps for a second and then attempts to read and copy further records
from the input-file. Thus it may be used to monitor the growth of a file that is
being written by some other process.
-c number The number option-argument must be a decimal integer whose sign affects
the location in the file, measured in bytes, to begin the copying:
+ Copying starts relative to the beginning of the file.
- Copying starts relative to the end of the file.
none Copying starts relative to the end of the file.
The origin for counting is 1; that is, -c+1 represents the first byte of the file, -
c-1 the last.
-n number Equivalent to -c number, except the starting location in the file is measured
in lines instead of bytes. The origin for counting is 1; that is, -n+1 represents
the first line of the file, -n- 1 the last.
File Name of the file you wish to display
Examples
tail myfile.txt
The above example would list the last 10 (default) lines of the file myfile.txt.
tail myfile.txt -n 100
The above example would list the last 100 lines in the file myfile.txt.
===================================================================
====
Cut
Cut out selected fields of each line of a file.
Syntax
cut [-b] [-c] [-f] list [-n] [-d delim] [-s] [file]
-b list The list following -b specifies byte positions (for instance, -b1- 72 would pass
the first 72
bytes of each line). When -b and -n are used together, list is adjusted so
that no multi-byte character is split. If -b is used, the input line should
contain 1023 bytes or less.
-c list The list following -c specifies character positions (for instance, -c1- 72 would
pass the first 72 characters of each line).
-f list The list following -f is a list of fields assumed to be separated in the file by a
delimiter character (see -d ); for instance, -f1,7 copies the first and seventh
field only. Lines with no field delimiters will be passed through intact (useful
for table subheadings), unless -s is specified. If -f is used, the input line
should contain 1023 characters or less.
List A comma-separated or blank-character- separated list of integer field
numbers (in increasing order), with optional - to indicate ranges (for
instance, 1,4,7; 1-3,8; -5,10 (short for 1-5,10); or 3- (short for third through
last field)).
-n Do not split characters. When -b list and -n are used together, list is
adjusted so that no multi-byte character is split.
-d delim The character following -d is the field delimiter (-f option only). Default is tab.
Space or other characters with special meaning to the shell must be quoted.
delim can be a multi-byte character.
-s Suppresses lines with no delimiter characters in case of -f option. Unless
specified, lines with no delimiters will be passed through untouched.
File A path name of an input file. If no file operands are specified, or if a file
operand is -, the standard input will be used.
Examples
name=`who am i | cut -f1 -d' '` - set name to current login name.
egrep
Search a file for a pattern using full regular expressions.
Syntax
egrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list ] [-f file ] [ strings ] [ file]
-b Precede each line by the block number on which it was found. This can be
useful in locating block numbers by context (first block is 0).
-c Print only a count of the lines that contain the pattern.
-h Suppress printing of filenames when searching multiple files.
-i Ignore upper/lower case distinction during comparisons.
-l Print the names of files with matching lines once, separated by NEWLINEs.
Does not repeat the names of files when the pattern is found more than
once.
-n Precede each line by its line number in the file (first line is 1).
-s Work silently, that is, display nothing except error messages. This is useful
for checking the error status.
-v Print all lines except those that contain the pattern.
-x Consider only input lines that use all characters in the line to match an
entire fixed string or regular expression to be matching lines.
-e
pattern_list
Search for a pattern_list (full regular expression that begins with a -).
-f file Take the list of full regular expressions from file.
Strings Specify a pattern to be used during the search for input.
File A path name of a file to be searched for the patterns. If no file operands are
specified, the standard input will be used.
Examples
egrep "support|help|windows" myfile.txt - Would search for patterns of support help and
windows in the file myfile.txt.
===================================================================
====
Grep –in “kk” test1.txt
Gives the line number of the first match of “kk” in test1.txt without case sensitivity
Finds text within a file.
Syntax
grep [options] PATTERN [FILE...]
grep [options] [-e PATTERN | -f FILE] [FILE...]
-A NUM, -- after-
context=NUM
Print NUM lines of trailing context after matching lines. Places a
line containing -- between contiguous groups of matches.
-a, -- text Process a binary file as if it were text; this is equivalent to the --
binary-files=text option.
-B NUM, -- before-
context=NUM
Print NUM lines of leading context before matching lines. Places a
line containing -- between contiguous groups of matches.
-b, -- byte-offset Print the byte offset within the input file before each line of output.
-- binary-files=TYPE If the first few bytes of a file indicate that the file contains binary
data, assume that the file is of type TYPE. By default, TYPE is
binary, and grep normally outputs either a one-line message
saying that a binary file matches, or no message if there is no
match. If TYPE is without-match, grep assumes that a binary file
does not match; this is equivalent to the -I option. If TYPE is text,
grep processes a binary file as if it were text; this is equivalent to
the -a option. Warning: grep -- binary-files=text might output binary
garbage, which can have nasty side effects if the output is a
terminal and if the terminal driver interprets some of it as
commands.
-C NUM, --
context=NUM
Print NUM lines of output context. Places a line containing --
between contiguous groups of matches.
-c, -- count Suppress normal output; instead print a count of matching lines for
each input file. With the -v, -- invert-match option (see below),
count non-matching lines.
-- colour[=WHEN], --
color[=WHEN]
Surround the matching string with the marker find in
GREP_COLOR environment variable. WHEN may be `never',
`always', or `auto'
-D ACTION, --
devices=ACTION
If an input file is a device, FIFO or socket, use ACTION to process
it. By default, ACTION is read, which means that devices are read
just as if they were ordinary files. If ACTION is skip, devices are
silently skipped.
-d ACTION, --
directories=ACTION
If an input file is a directory, use ACTION to process it. By default,
ACTION is read, which means that directories are read just as if
they were ordinary files. If ACTION is skip, directories are silently
skipped. If ACTION is recurse, grep reads all files under each
directory, recursively; this is equivalent to the -r option.
-E, -- extended-
regexp
Interpret PATTERN as an extended regular expression (see
below).
-e PATTERN, -- Use PATTERN as the pattern; useful to protect patterns beginning
regexp=PATTERN with -.
-F, -- fixed-strings Interpret PATTERN as a list of fixed strings, separated by
newlines, any of which is to be matched.
-f FILE, -- file=FILE Obtain patterns from FILE, one per line. The empty file contains
zero patterns, and therefore matches nothing.
-G, -- basic-regexp Interpret PATTERN as a basic regular expression (see below).
This is the default.
-H, -- with-filename Print the filename for each match.
-h, -- no-filename Suppress the prefixing of filenames on output when multiple files
are searched.
-- help Output a brief help message.
-I Process a binary file as if it did not contain matching data; this is
equivalent to the -- binary-files=without match option.
-i, -- ignore-case Ignore case distinctions in both the PATTERN and the input files.
-L, -- files-without-
match
Suppress normal output; instead print the name of each input file
from which no output would normally have been printed. The
scanning will stop on the first match.
-l, -- files-with-
matches
Suppress normal output; instead print the name of each input file
from which output would normally have been printed. The
scanning will stop on the first match.
-- label=LABEL Displays input actually coming from standard input as input
coming from file LABEL. This is especially useful for tools like
zgrep, e.g. gzip -cd foo.gz |grep -- label=foo something
-- line-buffered Use line buffering, it can be a performance penalty.
-m NUM, -- max-
count=NUM
Stop reading a file after NUM matching lines. If the input is
standard input from a regular file, and NUM matching lines are
output, grep ensures that the standard input is positioned to just
after the last matching line before exiting, regardless of the
presence of trailing context lines. This enables a calling process to
resume a search. When grep stops after NUM matching lines, it
outputs any trailing context lines. When the -c or -- count option is
also used, grep does not output a count greater than NUM. When
the -v or -- invert-match option is also used, grep stops after
outputting NUM non-matching lines.
-- mmap ations, -- mmap yields better performance. However, -- mmap can
cause undefined behavior (including core dumps) if an input file
shrinks while grep is operating, or if an I/O error occurs.
-n, -- line-number Prefix each line of output with the line number within its input file.
-o, -- only-matching Show only the part of a matching line that matches PATTERN.
-P, -- perl-regexp Interpret PATTERN as a Perl regular expression.
-q, -- quiet, -- silent Quiet; do not write anything to standard output. Exit immediately
with zero status if any match is found, even if an error was
detected. Also see the -s or -- no-messages option.
-R, -r, -- recursive Read all files under each directory, recursively; this is equivalent to
the -d recurse option.
--
include=PATTERN
Recurse in directories only searching file matching PATTERN.
--
exclude=PATTERN
Recurse in directories skip file matching PATTERN.
-s, -- no-messages Suppress error messages about nonexistent or unreadable files.
Portability note: unlike GNU grep, traditional grep did not conform
to POSIX.2, because traditional grep lacked a -q option and its -s
option behaved like GNU grep's -q option. Shell scripts intended to
be portable to traditional grep should avoid both -q and -s and
should redirect output to /dev/null instead.
-U, -- binary Treat the file(s) as binary. By default, under MS-DOS and MS-
Windows, grep guesses the file type by looking at
the contents of the first 32KB read from the file. If grep decides the
file is a text file, it strips the CR characters from the original file
contents (to make regular expressions with ^ and $ work
correctly). Specifying -U overrules this guesswork, causing all files
to be read and passed to the matching mechanism verbatim; if the
file is a text file with CR/LF pairs at the end of each line, this will
cause some regular expressions to fail. This option has no effect
on platforms other than MS-DOS and MS-Windows.
-u, -- unix-byte-
offsets
Report Unix-style byte offsets. This switch causes grep to report
byte offsets as if the file were Unix-style text file, i.e. with CR
characters stripped off. This will produce results identical to
running grep on a Unix machine. This option has no effect unless -
b option is also used; it has no effect on platforms other than MS-
DOS and MS-Windows.
-V, -- version Print the version number of grep to standard error. This version
number should be included in all bug reports (see below).
-v, -- invert-match Invert the sense of matching, to select non-matching lines.
-w, -- word-regexp Select only those lines containing matches that form whole words.
The test is that the matching substring must either be at the
beginning of the line, or preceded by a non-word constituent
character. Similarly, it must be either at the end of the line or
followed by a non-word constituent character. Word-constituent
characters are letters, digits, and the underscore.
-x, -- line-regexp Select only those matches that exactly match the whole line.
-y Obsolete synonym for -i.
-Z, -- null Output a zero byte (the ASCII NUL character) instead of the
character that normally follows a file name. For example, grep -lZ
outputs a zero byte after each file name instead of the usual
newline. This option makes the output unambiguous, even in the
presence of file names containing unusual characters like
newlines. This option can be used with commands like find -print0,
perl -0, sort -z, and xargs -0 to process arbitrary file names, even
those that contain newline characters.
-z, -- null-data Treat the input as a set of lines, each terminated by a zero byte
(the ASCII NUL character) instead of a newline. Like the -Z or --
null option, this option can be used with commands like sort -z to
process arbitrary file names.
Patterns for searching.
. Matches single character.
* Wild character Example C* if found would pull up CC or CAT...
{} Matches any character contained within the bracket.
^ Represents the beginning of the line, so if you did ^T it would search for any
sentence starting with a T.
$ Represents the end of the line, so if you did $. then it would pull up any lines
that ended with .
\ Means to take the next character serious so you could search for C\ C.
Note: Be careful using the characters $, *, [, ^, |, (, ), and \ in the pattern list because
they are also meaningful to the shell. It is safest to enclose the entire pattern list in single
quotes '... '.
Examples
grep "unix" *.htm
search all .htm files in the current directory for any reference of unix and give results
similar to the below example text.
asoftwar.htm: href="win95.htm">Windows 95</a>, <a href="unix.htm">Unix</a>, <a
href="msdos.htm">MS-DOS</a>,
asoftwar.htm: <td><font face="Times New Roman"><a name="U"></a><a
href="unix.htm"><strong>Unix</strong></a></font></td>
learnhtm.htm: <a href="unix.htm">Unix help</a><br>
os.htm: <a href="unix.htm">Unix</a><br>
As seen above the grep command has found references of unix in some of the HTML
files in our home directory. The file name that contains unix is listed at the beginning of
the line followed by a colon and the text continuing unix.
chmod –R 644 files
Changes the permission of a file.
-R change files and directories recursively
Numeric Permissions:
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
Examples
The above numeric permissions can be added to set a certain permission, for example,
a common HTML file on a Unix server to be only viewed over the Internet would be:
chmod 644 file.htm
This gives the file read/write by the owner and only read by everyone else (-rw- r-- r-- ).
Files such as scripts that need to be executed need more permissions. Below is another
example of a common permission given to scripts.
chmod 755 file.cgi
This would be the following 400+040+004+200+100+010+001 = 755 where you are
giving all the rights except the capability for anyone to write to the file.cgi file(-rwxr- xr-x).
Finally, another common CHMOD permission is 666, as shown below, which is read and
write by everyone.
chmod 666 file.txt
Additional information
Below is an example of how a file may be listed when typing ( ls -l ) at the prompt as well
as information on how to interpret it.
-rw- rw-r- - 1 hope 123 Feb 03 15:36 file.txt
- Rw rw- r-- 1 hope 123 Feb 03 15:36 file.txt
File owner group everyone else links owner size mod date file name
Display or list all directories
Type the following command:
$ ls -l | egrep `^d'
Display or list only files
Type the following command:
$ ls -l | egrep -v `^d'
grep command used to searches input. It will filter out directories name by matching first
character d. To reverse effect (just to display files) you need to pass -v option. It invert
the sense of matching, to select non-matching lines.
crontab
List of files that you want to run on a regular schedule.
Syntax
crontab [-e] [-l] [-r] [filename]
-e edit a copy of the current user's crontab file, or creates an empty file to edit
if crontab does not exist. When editing is complete, the file is installed as the
user's crontab file. If a user- name is given, the specified user's crontab file
is edited, rather than the current user's crontab file; this may only be done
by a super-user. The environment variable EDITOR determines which editor
is invoked with the -e option. The default editor is ed. Note that all crontab
jobs should be submitted using crontab ; you should not add jobs by just
editing the crontab file because cron will not be aware of changes made this
way.
-l list the crontab file for the invoking user. Only a super-user can specify a
username following the -r or -l options to remove or list the crontab file of the
specified user.
-r remove a user's crontab from the crontab
Filename The filename that contains the commands to run.
Lines that can be in the crontab file.
minute (0-59),
hour (0-23),
day of the month (1-31),
month of the year (1-12),
day of the week (0-6 with 0=Sunday).
Examples
crontab -e = edits the crontab file to be used.
0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.
Below is a table that represents what each of the above fields are for.
min hour dayofmonth monthofyear dayofweek command
0 12 14 2 * mailx john%Happy Birthday!%Time
for lunch.
Options Explanation
* Is treated as a wild card. Meaning any possible value.
*/5 Is treated as ever 5 minutes, hours, days, or months. Replacing the 5 with
another numerical value will change this option.
2,4,6 Treated as an OR, so if placed in the hours, this could mean at 2, 4, or 6 o-
clock.
9-17 Treats for any value between 9 and 17. So if placed in day of month this would
be days 9 through 17. Or if put in hours it would be between 9 and 5.
If you wish to create a task to be performed once later during the day you may wish to
consider using the at command.
kill
Cancels a job.
Syntax
kill [-s] [-l] %pid
-s Specify the signal to send, using one of the symbolic names defined in the
<signal.h> description. Values of signal will be recognized in a case
independent fashion, without the SIG prefix. In addition, the symbolic name
0 will be recognized, representing the signal value zero. The corresponding
signal will be sent instead of SIGTERM.
-l Write all values of signal sup ported by the implementation, if no operand is
given. If an exit_status operand is given and it is a value of the ? shell
special parameter and wait corresponding to a process that was ter minated
by a signal, the signal corresponding to the signal that terminated the
process will be written. If an exit_status operand is given and it is the
unsigned decimal integer value of a signal number, the signal corresponding
to that signal will be written. Otherwise, the results are unspecified.
pid One of the following:
1. A decimal integer specifying a process or process group to be signaled.
The process or processes selected by positive, negative and zero values of
the pid operand will be as
described for the kill function. If process number 0 is specified, all processes
in the process group are signaled. If the first pid operand is negative, it
should be preceded by -- to keep it from being interpreted as an option.
2. A job control job ID that identifies a background process group to be
signaled. The job control job ID notation is applicable only for invocations of
kill in the current shell execution environment.
Note the job control job ID type of pid is available only on systems
supporting the job control option.
Examples
kill -s kill 100 -165
Kills job 1 of uid 165
When running the kill command you may receive the error "Operation not permitted", this
is often encountered when you're killing the wrong group id (often 1,2,3 or low number
jobs) that you don't have permission to kill. If you wish to see the group id of the
background task run jobs -l
find
Finds one or more files assuming that you know their approximate filenames.
Syntax
find path expressions
path A path name of a starting point in the directory hierarchy.
-atime n True if the file was accessed n days ago. The access time of directories in
path is changed by find itself.
-cpio
device
Always true; write the current file on device in cpio format (5120-byte
records).
-ctime n True if the file's status was changed n days ago.
-depth Always true; causes descent of the directory hierarchy to be done so that all
entries in a directory are acted on before the directory itself. This can be
useful when find is used with cpio to transfer files that are contain edin
directories without write permission.
-exec
command
True if the executed command returns a zero value as exit status. The end
of command must be punctuated by an escaped semicolon. A command
argument {} is replaced by the current path name.
-follow Always true; causes symbolic links to be followed. When following symbolic
links, find keeps track of the directories visited so that it can detect infinite
loops; for example, such a loop would occur if a symbolic link pointed to an
ancestor. This expression should not be used with the -type l expression.
-fstype
type
True if the filesystem to which the file belongs is of type type .
-group
gname
True if the file belongs to the group gname. If gname is numeric and does
not appear in the /etc/group file, it is taken as a group ID.
-inum n True if the file has inode number n.
-links True if the file has n links.
-local True if the file system type is not a remote file system type as defined in the
/etc/dfs/fstypes file. nfsis used as the default remote filesystem type if
the/etc/dfs/fstypes file is not present.
-ls Always true; prints current path name together
with its associated statistics. These include
(respectively):
inode number
size in kilobytes (1024 bytes)
protection mode
number of hard links
user
group
size in bytes
modification time.
If the file is a special file the size field will instead contain the major and
minor device numbers.
If the file is a symbolic link the pathname of the linked-to file is printed
preceded by `->'. The format is identical to that of ls -gilds ls Note:
Formatting is done internally, without executing the ls program.
-mount Always true; restricts the search to the file system containing the directory
specified. Does not list mount points to other file systems.
-mtime n True if the file's data was modified n days ago.
-name
pattern
True if pattern matches the current file name. Normal shell file name
generation characters (see sh) may be used. A backslash (\) is used as an
escape character within the pattern. The pattern should be escaped or
quoted when find is invoked from the shell.
-ncpio
device
Always true; write the current file on device in cpio -c format (5120 byte
records).
-newer file True if the current file has been modified more recently than the argument
file.
-nogroup True if the file belongs to a group not in the /etc/group file.
-nouser True if the file belongs to a user not in the /etc/passwd file.
-ok
command
Like -exec except that the generated command line is printed with a
question mark first, and is executed only if the user responds by typing y.
-perm [-
]mode
The mode argument is used to represent file mode bits. It will be identical in
format to the <symbolicmode> operand described in chmod, and will be
interpreted as follows. To start, a template will be assumed with all file mode
bits cleared. An op symbol of:
+ will set the appropriate mode bits in the template;
- will clear the appropriate bits;
= will set the appropriate mode bits, without regard to the contents of
process' file mode creation mask.
The op symbol of - cannot be the first character of mode; this avoids
ambiguity with the optional leading hyphen. Since the initial mode is all bits
off, there are not any symbolic modes that need to use - as the first
character.
If the hyphen is omitted, the primary will evaluate as true when the file
permission bits exactly match the value of the resulting template.
Otherwise, if mode is prefixed by a hyphen, the primary will evaluate as true
if at least all the bits in the resulting template are set in the file permission
bits.
-perm [-
]onum
True if the file permission flags exactly match the octal number onum see
chmod). If onum is prefixed by a minus sign (-), only the bits that are set in
onum are compared with the file permission flags, and the expression
evaluates true if they match.
-print Always true; causes the current path name to be printed.
-prune Always yields true. Do not examine any directories or files in the directory
structure below the pattern just matched. If -depth is specified, -prune will
have no effect.
-size n[c] True if the file is n blocks long (512 bytes per block). If n is followed by a c,
the size is in
bytes.
-type c True if the type of the file is c, where c is b, c, d, D, f, l, p, or s for block
special file, character special file, directory, door, plain file, symbolic link, fifo
(named pipe), or socket, respectively.
-user
uname
True if the file belongs to the user uname . If uname is numeric and does
not appear as a login name in the /etc/passwd file, it is taken as a user ID.
-xdev Same as the -mount primary.
When using find to determine files modified within a range of time, one must use the
?time argument before the -print argument; otherwise, find will give all files.
Examples
find -name 'mypage.htm'
In the above command the system would search for any file named mypage.htm in the
current directory and any subdirectory.
find / -name 'mypage.htm'
In the above example the system would search for any file named mypage.htm on the
root and all subdirectories from the root.
find -name 'file*'
In the above example the system would search for any file beginning with file in the
current directory and any subdirectory.
find -name '*' -size +1000k
In the above example the system would search for any file that is larger then 1000k.
find . -size +500000 -print
Next, similar to the above example, just formatted differently this command would find
anything above 500MB
jobs
Lists the jobs that you are running in the background and in the foreground. If the prompt
is returned with no information no jobs are present. Note: not all shells are capable of
running this command.
Syntax
jobs [-p | -l] [-n] [-p] [-x] [job id]
-p | -l Report the process group ID and working directory of the jobs.
-n Display only jobs that have stopped or exited since last notified.
-p Displays only the process IDs for the process group leaders of the selected
jobs.
-x Replace any job_id found in command or arguments with the corresponding
process group ID, and then execute command passing it arguments.
job id The job id.
Examples
jobs
Would display results similar to the below if jobs were running in the background.
[1] + Stopped (user) man jobs
As you can see in the above job example the id is 1 it has been stopped by the user and
the process in this case is man jobs (looking at the manual for jobs).
jobs -l
The above command would not just list the jobs running but also this group ID and the
working directory of the jobs. Below is an example of what this would display.
[3] 16882 Running ./chsearchproc (wd: ~/public_html/cgi-bin/chsearch)
ps
Reports the process status.
Syntax
ps [-a] [-A] [-c] [-d] [-e] [-f] [-j] [-l] [-L] [-P] [-y] [ -g grplist ] [ -n namelist ] [-o format ] [ -p
proclist ] [ -s sidlist ] [ -t term] [ -u uidlist ] [ -U uidlist ] [ -G gidlist ]
-a List information about all processes most frequently requested: all those
except process group leaders and processes not associated with a terminal.
-A List information for all processes. Identical to -e, below.
-c Print information in a format that reflects scheduler properties as described
in priocntl.
The -c option affects the output of the -f and -l options, as described below.
-d List information about all processes except session leaders.
-e List information about every process now running.
-f Generate a full listing.
-j Print session ID and process group ID.
-l Generate a long listing.
-L Print information about each light weight process (lwp) in each selected
process.
-P Print the number of the processor to which the process or lwp is bound, if
any, under an additional column header, PSR.
-y Under a long listing (-l), omit the obsolete F and ADDR columns and include
an RSS column to report the resident set size of the process. Under the -y
option, both RSS and SZ will be reported in units of kilobytes instead of
pages.
-g grplist List only process data whose group leader's ID number(s) appears in grplist.
(A group leader is a process whose process ID number is identical to its
process group ID number.)
-n
namelist
Specify the name of an alternative system namelist file in place of the
default. This option is accepted for compatibility, but is ignored.
-o format Print information according to the format specification given in format. This
is fully described in DISPLAY FORMATS. Multiple -o options can be
specified; the format specification will be interpreted as the space-character-
separated concatenation of all the format option-arguments.
-p proclist List only process data whose process ID numbers are given in proclist.
-s sidlist List information on all session leaders whose IDs appear in sidlist.
-t term List only process data associated with term. Terminal identifiers are
specified as a device file name, and an identifier. For example, term/a, or
pts/0.
-u uidlist List only process data whose effective user ID number or login name is
given in uidlist. In the listing, the numerical user ID will be printed unless you
give the -f option, which prints the login name.
-U uidlist List information for processes whose real user ID numbers or login names
are given in uidlist. The uidlist must be a single argument in the form of a
blank- or comma-separated list.
-G gidlist List information for processes whose real group ID numbers are given in
gidlist. The gidlist must be a single argument in the form of a blank- or
comma-separated list.
Examples
ps
Typing ps alone would list the current running processes. Below is an example of the
output that would be generated by the ps command.
PID TTY TIME CMD
6874 pts/9 0:00 ksh
6877 pts/9 0:01 csh
418 pts/9 0:00 csh
ps -ef
Display full information about each of the processes currently running.
UID PID PPID C STIME TTY TIME CMD
hope 29197 18961 0 Sep27 ? 00:00:06 sshd: hope@pts/87
hope 32097 29197 0 Sep27 pts/87 00:00:00 -csh
hope 7209 32097 0 12:17 pts/87 00:00:00 ps -ef
ps -l
Displays processes including those that are in a wait state, similar to the below example.
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD 0 T 0 12308 29722 0
80 0 - 16136 finish pts/0 00:00:00 pico 0 R 0 12530 29722 0 80 0 - 15884 - pts/0
00:00:00 ps 4 S 0 29722 29581 0 80 0 - 16525 wait pts/0 00:00:00 bash
wc
Short for word count, wc displays a count of lines, words, and characters in a file.
Syntax
wc [-c | -m | -C ] [-l] [-w] [ file ... ]
-c Count bytes.
-m Count characters.
-C Same as -m.
-l Count lines.
-w Count words delimited by white space characters or new line characters.
Delimiting characters are Extended Unix Code (EUC) characters from any
code set defined by iswspace()
file Name of file to word count.
Examples
wc myfile.txt - Displays information about the file myfile.txt. Below is an example of the
output.
5 13 57 myfile.txt
5 = Lines
13 = Words
57 = Characters
===============================================================
settime and touch
Change file access and modification time.
Syntax
touch [-a] [-c] [-m] [-r ref_file | -t time ] file
settime [ -f ref_file ] file
-a Change the access time of file. Do not change the modification time unless -
m is also specified.
-c Do not create a specified file if it does not exist. Do not write any diagnostic
messages concerning this condition.
-m Change the modification time of file. Do not change the access time unless -
a is also specified.
-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:
[[CC]YY]MMDDhhmm [.SS]
MM - The month of the year [01-12].
DD - The day of the month [01-31].
hh - The hour of the day [00-23].
mm - The minute of the hour [00-59].
CC - The first two digits of the year.
YY - The second two digits of the year.
SS - The second of the minute [00-61].
-f ref_file Use the corresponding times of the file named by ref_file instead of the
current time.
file A path name of a file whose times are to be modified.
Examples
settime myfile.txt
Sets the file myfile.txt as the current time / date.
touch newfile.txt
Creates a file known as "newfile.txt", if the file does not already exist. If the file already
exists the accessed / modification time is updated for the file newfile.txt
tar
Create tape archives and add or extract files.
Syntax
tar c [ bBeEfFhiklnopPqvwX [ 0-7 ] ] [ block ] [ tarfile ] [ exclude-file ] {-I include-file | -C
directory | file | file }
tar r [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] {-I include-file | -C directory | file | file }
tar t [ BefFhiklnqvX [ 0-7 ] ] [ tarfile ] [ exclude-file ] {-I include-file | file } ...
tar u [ bBeEfFhiklnqvw [ 0-7 ] ] [ block ] [ tarfile ] file ...
tar x [ BefFhiklmnopqvwX [ 0-7 ] ] [ tarfile ] [ exclude-file ] [ file ... ]
c Create. Writing begins at the beginning of the tarfile, instead of at the end.
r Replace. The named file s are written at the end of the tarfile. A file created
with extended headers must be updated with extended headers (see E flag
under Function Modifiers). A file created without extended headers cannot
be modified with extended headers.
t Table of Contents. The names of the specified files are listed each time they
occur in the tar file. If no file argument is given, the names of all files in the
tarfile are listed. With the v
function modifier, additional information for the specified files is displayed.
u Update. The named file s are written at the end of the tarfile if they are not
already in the tar file, or if they have been modified since last written to that
tarfile. An update can be rather slow. A tarfile created on a 5.x system
cannot be updated on a 4.x system. A file created with extended headers
must be updated with extended headers (see E flag under Function
Modifiers). A file created without extended headers cannot be modified with
extended headers.
x Extract or restore. The named file s are extracted from the tarfile and written
to the directory specified in the tarfile, relative to the current directory. Use
the relative path names of files and directories to be extracted. If a named
file matches a directory whose contents has been writ ten to the tarfile, this
directory is recursively extracted. The owner, modification time, and mode
are restored (if possible); otherwise, to restore owner, you must be the
super-user. Character special and block-special devices (created by
mknod(1M)) can only be extracted by the super user. If no file argument is
given, the entire content of the tarfile is extracted. If the tar- file contains
several files with the same name, each file is written to the appropriate
directory, overwriting the previous one. Filename substitu tion wildcards
cannot be used for extracting files from the archive; rather, use a command
of the form:
tar xvf... /dev/rmt/0 `tar tf... /dev/rmt/0 | grep 'pattern' `
When extracting tapes created with the r or u functions, directory
modification times may not be set correctly. These same functions cannot
be used with many tape drives due to tape drive limitations such as the
absence of backspace or append capabilities.
When using the r, u, or x functions or the X function modifier, the named
files must match exactly the corresponding files in the tarfile. For example,
to extract ./thisfile, you must specify ./thisfile, and not thisfile. The t function
displays how each file was archived.
Function Modifiers
The characters below may be used in conjunction with the letter that selects the desired
function.
b Blocking Factor. Use when reading or writing to raw magnetic archives (see
f below). The block argument specifies the number of 512-byte tape blocks
to be included in each read or write operation performed on the tarfile. The
minimum is 1, the default is 20. The maximum value is a function of the
amount of memory available and the blocking requirements of the specific
tape device involved (see mtio(7I) for details.) The maximum cannot
exceed INT_MAX/512 (4194303).
When a tape archive is being read, its actual blocking factor will be
automatically detected, provided that it is less than or equal to the nominal
blocking factor (the value of the block argument, or the default value if the b
modifier is not specified). If the actual blocking factor is greater than the
nominal blocking factor, a read error will result. See Example 5 in Examples.
B Block. Force tar to perform multiple reads (if necessary) to read exactly
enough bytes to fill a block. This function modifier enables tar to work
across the Ethernet, since pipes and sockets return partial blocks even
when more data is coming. When reading from standard input, '-', this
function modifier is selected by default to ensure that tar can recover from
short reads.
e Error. Exit immediately with a positive exit status if any unexpected errors
occur. The SYSV3 environment variable overrides the default behavior.
(See ENVIRONMENT section below.)
E Write a tarfile with extended headers. (Used with c, r, or u options; ignored
with t or x options.) When a tarfile is written with extended headers, the
modification time is maintained with a granularity of microseconds rather
than seconds. In addition, filenames no longer than PATH_MAX characters
that could not be archived without E, and file sizes greater than 8GB, are
supported. The E flag is required whenever the larger files and/or files with
longer names, or whose UID/GID exceed 2097151, are to be archived, or if
time granularity of microseconds is desired.
f File. Use the tarfile argument as the name of the tarfile. If f is specified,
/etc/default/tar is
not searched. If f is omitted, tar will use the device indicated by the TAPE
environment variable, if set; otherwise, it will use the default values defined
in /etc/default/tar. If the name of the tarfile is '-', tar writes to the standard
output or reads from the standard input, whichever is appropriate. tar can be
used as the head or tail of a pipeline. tar can also be used to move
hierarchies with the command:
example% cd fromdir; tar cf - .| (cd todir; tar xfBp -)
F With one F argument, tar excludes all directories named SCCS and RCS
from the tarfile. With two arguments, FF, tar excludes all directories named
SCCS and RCS, all files with .o as their suffix, and all files named errs, core,
and a.out. The SYSV3 environment variable overrides the default behavior.
(See ENVIRONMENT section below.)
h Follow symbolic links as if they were normal files or directories. Normally, tar
does not follow symbolic links.
i Ignore directory checksum errors.
-j, -- bzip2 filter archive through bzip2, use to decompress .bz2 files. WARNING: some
previous versions of tar used option -I to filter through bzip2. When writing
scripts, use -- bzip2 instead of -j so that both older and newer tar versions
will work.
k size Requires tar to use the size argument as the size of an archive in kilobytes.
This is useful when the archive is intended for a fixed size device such as
floppy disks. Large files are then split across volumes if they do not fit in the
specified size.
l Link. Output error message if unable to resolve all links to the files being
archived. If l is not specified, no error messages are printed.
m Modify. The modification time of the file is the time of extraction. This
function modifier is
valid only with the x function.
n The file being read is a non-tape device. Reading of the archive is faster
since tar can randomly seek around the archive.
o Ownership. Assign to extracted files the user and group identifiers of the
user running the program, rather than those on tarfile. This is the default
behavior for users other than root. If the o function modifier is not set and
the user is root, the extracted files will take on the group and user identifiers
of the files on tarfile (see chown for more information). The o function
modifier is only valid with the x function.
p Restore the named files to their original modes, and ACLs if applicable,
ignoring the present umask. This is the default behavior if invoked as super-
user with the x function letter specified. If super-user, SETUID and sticky
information are also extracted, and files are restored with their original
owners and permissions, rather than owned by root. When this function
modifier is used with the c function, ACLs are created in the tarfile along
with other information. Errors will occur when a tarfile with ACLs is extracted
by
previous versions of tar .
P Suppress the addition of a trailing "/" on directory entries in the archive.
q Stop after extracting the first occurrence of the named file. tar will normally
continue reading the archive after finding an occurrence of a file.
v Verbose. Output the name of each file preceded by the function letter. With
the t function, v provides additional information about the tarfile entries. The
listing is similar to the format produced by the -l option of the ls command.
w What. Output the action to be taken and the name of the file, then await the
user's confirmation. If the response is affirmative, the action is performed;
otherwise, the action is not performed. This function modifier cannot be
used with the t function.
salesforce online course
ReplyDeletehadoop online course
Data Science online course
linux online course
etl testing online course
web methods online course
business analyst training
oracle adf training
oracle rac training
msbi training