Execute Linux commands and describe the output
1.
TOUCH:
It is also used to
create a new empty file.
Syntax: $
touch filename
Synopsis:
-a Change
the access time only
-c if
the file does not exist, do not create it and do not report this condition
-m change
the modification time only
-r use
the access and modification times of file
-t use the time specified to update the access and modification times
Example:
$ touch filename
-Here an empty file named ‘filename’
will be created.
2.
CAT:
The cat
command can be used to join multiple files together and print the result on
screen.
Syntax:$
cat filename [-n] [-b] [-u] [-s] [-v]
Synopsis:
-n Precede each line output with its line number.
-b Number the
lines, as -n, but omit the line numbers from blank lines
-u Theoutput is
not buffered. (The default is buffered output)
-e A $
character will be printed at the end of each line (prior to the new-line).
-t Tabs will be
printed as ^I's and formfeeds to be printed as ^L's
Example:
$cat
a1,a2> a3
- Reads the files ‘a1’ and ‘a2’ and combines them into file
‘a3’.
3. LS:
The ls command lists all files in the directory that match the name. If name is left blank, it will list all of the files in the directory.
Syntax:$ ls [option] [name]
Synopsis:
-a Display all files.
-c Display files by timestamp.
-d Display only directories.
-f Interprets each name as a directory.
-l Displays the long format listing.
-p Displays directories with /.
-r Displays files in reverse order.
-R Displays subdirectories as well.
-t Displays the newest files first.
Example:
$ls
-List out the files and sub-directory of current directory.
$ls –l
-It will display the list of files and directory in detail.
4. MKDIR:
This command is used to make a new directory/directories.
Syntax:$mkdir [option] [names]
Synopsis:
-m Setsthe permission mode (as in chmod)
-p no error if existing, make parent directories as needed
Example:
$mkdir myfile
-It will make a directory names ‘myfile’.
5. RMDIR:
It removes the directory/directories if they are empty.
Syntax:$rmdir [option] [directory]
Synopsis:
-p Removes directory and its ancestors.
Example:
Rmdir som
- It will remove the directory named ‘som’.
6. CD:
It is used to change the current directory.
Syntax:cd [directory name]
Example:
Cd myfile
-It is used to move to the next directory which is ‘myfile’
-It is used to move to the previous directory.
7. CLEAR:
It clears all the contents of the screen.
Syntax:$clear
8. CP:
This command is used to copy source to destination, or multiple sources to directory.
Syntax:$cp [option] source destination
Synopsis:
-a archive
-b make backup before removal
-d preserve links
-i prompt before overwrite
-l link files instead of copying
-p append source path to directory
-u copy only when the SOURCE file is newerthan the destination file or when the destination file is missing.
Example:
$cp file1\dir1
-It will copy the file named file1 into directory dir1.
9. CAL:
Cal displays a simple calendar. If arguments are not specified, the current month is displayed.
Syntax: Cal [option]
Synopsis:
-l Display single month output. (This is the default.)
-3 Display previous/current/next month output.
-s Display Sunday as the first day of the week
-m Display Monday as the first day of the week
-j Display Julian dates (days one-based, numbered from January 1).
-y Display a calendar for the current year.
Example:
$cal –y
-It will display the calendar of the current year.
10. HISTORY:
It displays the history of all commands executed.
Syntax:
$history [option] [offset]… [option]
Synopsis:
-c clear the history list by deleting all of the entries.
-d delete the history entry at offset OFFSET.
-a append history lines from this session to the history file.
-n read all history lines not already read from the history file.
-p perform history expansion on each ARG and display the result without
storing it in the history.
Example:
history
-It displays all the commands executed.
history|more
-It will display the history page-wise.
11. CHMOD:
It is used to change the permission of a file or directory.
Syntax:
$chmod [option] [octal mode] [file]
Synopsis:
-c like verbose but report only when a change is made.
Example:
chmod 400 file1
-It will give read permission to only the user.
12. UMASK:
It is used to change the default file permission.
Syntax:$umask[mode] [file]
Example:
Umask 177
-It will give read and write permission to the user.
13. HEAD:
Display the starting contents (line wise) of a file.
Syntax:$head [option][filename]
Synopsis:
-c print the first N bytes of each file; with the leading '-'.
Example:
head -4 myfile
-It will display the first four lines of the file ‘myfile’.
14. TAIL:
Display the last lines of the files.
Syntax:$tail [option][file]
Synopsis:
-c output the last N bytes
-n output the last N lines, instead of the last 10
-q never output headers giving file names.
Example:
tail -4 file1
-It will display the last four lines of file file1.
15. DATE:
Display the current time in the given format, or set the system date.
Synopsis:
-d display time described by string.
-f like --date once for each line of date file.
-r display the last modification time of file.
Example:
Date
-It will return the current date and time of the system.
16. EXPR:
It is used to perform arithmetic expression.
Syntax:
$expr EXPRESSION
EXPRESSION may be:
arg1 | arg2 arg1 if it is neither null nor 0, otherwise arg2
arg1 & arg2 arg1 if neither argument is null or 0, otherwise 0
arg1 = arg2 arg1 is equal to arg2
arg1 >= arg2 arg1 is greater than or equal to arg2
arg1 > arg2 arg1 is greater than arg2
arg1 + arg2 arithmetic sum of arg1 and arg2
arg1 - arg2 arithmetic difference of arg1 and arg2
arg1 \* arg2 arithmetic product of arg1 and arg2
arg1 / arg2 arithmetic quotient of arg1 divided by arg2
arg1 % arg2 arithmetic remainder of arg1 divided by arg2
Example:
expr 4 +4
-It will perform addition and display the result as 8.
1 17. WHO
It
will print the name of all logged in users.
Syntax:
$who[option][file|arg1arg2 ]
Synopsis:
-b time of last system boot
-d print dead processes
-H print line of column headings
-l print system login processes
-p print active processes spawned by init
-t print last system clock change
-u list users logged in.
Example:
who
-It will display the list of currently logged in user.
who am i
-It will display the name of the user from which the user is logged in.
1 18. UNAME:
It
is used to print the system information.
Synopsis:$uname [option]
Syntax:
-a print all information, in the following order
-s print the kernel name
-n print the network node hostname
-r print the kernel version
-m print the machine hardware name
-p print the processor type or "unknown"
-o print the operating system.
Example:
Uname
-It will display the system name.
19. FINGER:
It is also used to display all the logged in user but in formatted way.
Syntax:
$finger[-lmsp][user][user@host]
Example:
finger
-Display the logged in user in formatted way.
20. CMP:
The cmp command compares two files of any type and writes the results to the standard output.
Syntax:
cmp [file 1] [file 2]
The following options are available:
-l Print the byte number (decimal) and the differing byte.
-s Print nothing for differing files; return exit status only.
Example:
cmp file1 file2
-If the content of both the file is same then no output is displayed. If the content is different then the line and character from where the content differs, is displayed.
21. COMM:
Compares
two sorted files line by line.
Syntax:comm [option] file1file2
Example:
comm file1 file2
-Here the output will be shown in column format. The first column will show the content from file1that is not present in file2. The second column will show the content from file2 that is not present in file1. The third column will show the common content of both files.
22. SORT:
It is used to sort the text files.
Syntax:
sort [option][file]
Synopsis:
-b ignore leading blanks
-f fold lower case to upper case characters
-M compare (unknown) < 'JAN' < ... < 'DEC'
-n compare according to string numerical value
Example:
ls –l | sort
-It will display the list in a sorted way.
23. SPELL:
This command will give us the details of all the spelling which are wrong in the file.
Syntax:
$ spell [file1]
Synopsis:
-b Uses British spellings.
-i Cause deroff to ignore .so and .nx commands. If deroff is not present on the system, then this option is ignored.
-l Follow the chains of all included files.
-v Print all words not literally in the spelling list, as well as plausible derivations from the words in the spelling list.
Example:
$ spell book
-Here it will display all words with wrong spelling in file named ‘book’ line wise.
24. WC:
This command will count the number of lines ,words and characters in the specified file.
Synopsis:
-c Print only the byte counts.
-w Print only the word counts.
-l Print only the newline counts.
-L Print
only the length of the longest line per file, and if there is more than one
file it prints the maximum (not the sum) of those lengths.
Syntax;
$spell [file1] [file2]
Example;
$ wc –lc file1 file2
-Here the file1 constitutes 20 lines
and 571 characters and similarly for
file
25. LOCATE:
It is used to search specific file.
Syntax:
locate [option]pattern
Synopsis:
Filename The name of the file or files that you wish to look at or per for tasks on.
-c Instead of writing file names on standard output, write the number of matching entries only.
-e Print only entries that refer to files existing at the time locate is run.
-iIgnore case distinctions when matching patterns.
Example:
locatemyfile
-It will locate the file named myfile from the whole database.
2 26. ENV:
It
is used to display, set, or remove environment variables.
Syntax:
env [option][name=value]
Synopsis:
-I start with an empty
environment
-u Remove variable from the environment
-help Display this help and exit
-version Output version information and exit
-i implies if no COMMAND, print the
resultingenvironment.
Example:
Env
-Executing
env with no options displays the current environment variables and their
values.
2 27. TYPE:
It is used to find current content of the file.
Syntax:
type [option] filename
Synopsis:
-l List the names of all
readline functions.
-p Display readline function names and bindings in such a way that
they can be
re-read.
-P List current readline function names and bindings.
-V List current readline variable names and values.
-x Cause shell-command to be executed whenever
keyseq is entered.
Example:
Type myfile1
-It will display the content of myfile1.
2 28.
MORE:
It displays the output page-wise.
Synopsis:
-num this option specifies an
integer which is the screen size (in lines).
-p do not scroll. Instead, clear the whole screen and then
display the text.
-s Squeeze multiple blank
lines into one.
Example:
History | more
-It will display the result page wise.
2 29. PS:
It is used
to find number of processes running.
Syntax:
ps [options]
Synopsis:
-A Select all processes. Identical to -e.
-N Select all processes except those that fulfill the specified conditions.
Negates the selection) Identical to -deselect.
-T Select all processes associated with this terminal.
Identical to the t option without any argument.
-F Extra full format. See the -f option, which -F implies.
-O format is like -o, but preloaded with some default columns.
-M Add a column of security data. Identical to Z.
-X Register format.
-Z Add a column of security data. Identical to -M.
-c Show different scheduler information for the -l option.
Example
Ps
-It will display the current running processes.
ps –l
-Displays
processes including those that are in a wait state.
3 30. READ:
It is used
to store a value in a variable.
Syntax:
sread [option][name]
Synposis:
-a
Option lets read get
array variableOption Meaning
-e Readline
is used to obtain the line.
-n
NCHARS read returns
after reading NCHARS characters rather than waiting for a complete line of
input.
-p
Display PROMPT,
without a trailing newline, before attempting to read any input. The prompt is
displayed only if input is coming from a terminal.
-r If
this option is given, backslash does not act as an escape character. The
backslash is considered to be part of the line. In particular, a backslash-newline
pair may not be used as a line continuation.
Example:
Read z
-It will
read the letter z from the file.
3 31. TTY:
It is
used to print the terminal no. of the system or the logical port to which the
user is connected.
Syntax:
tty [option]...
Synopsis:
-s prints nothing, only return an exit status.
-help display
this help and exit.
-version output version information and
exit.
Example:
Tty
-It will show from which terminal
the user is logged in.
32. PASSWD:
It is used to modify a user password.
Syntax:
passwd[options]
Synopsis:
-k The option-k, is used to indicate that the update should onlybe for expiredauthentication
tokens (passwords); the user wishes to keep their non-expired tokens
as before.
-l This option is used to lock the specified
account and it available to root only. The locking is performed by rendering
the encrypted password into an invalid string (by prefixing the encrypted
string with an!).
-stdin This option is used to indicate that passwd should read the newpassword
from standard input, which can be a pipe.
-S This will output a short information about the
status of the password for a given account. Available to root user only.
Example:Passwd
-It
will ask the user to enter the login-id and then for the new password.
3 33. RM:
Deletes a file without confirmation.
-f Remove all files (whether
write-protected or not) in a directory without prompting the user.
-i Interactive.
With this option, rm prompts for confirmation before removing any files.
-R Same
as -r option.
-r Recursively
remove directories and subdirectories in the argument list. The directory will
be emptied of files and removed.
Example:
rm
myfile.txt
-Remove
the file myfile.txt without prompting the user.
rm
-r directory
-Remove
a directory, even if files exist in that directory.
3 34. JOBS:
Lists
the status of all running jobs.
Syntax:jobs
[-option] [JOBSPEC]
Synposis:
Filename The name of the file or files that you
wish to look at or perform tasks on
-l lists process
IDs in addition to the normal information.
-n list only
processes that have changed status since the last notification.
-p lists process
IDs only.
-r restrict output
to running jobs.
-s restrict output
to stopped jobs.
Example:
Jobs
-Displays all running jobs.
jobs –l
-When supplied the -l option, jobs displays process IDs in addition
to job number.
3 35. KILL:
It is
used to stop a process from running.
Syntax:
kill[processid]
Synposis:
-n where n is larger than 0. The
process with pidn will be signaled.
-0 All processes in the current process
group are signaled.
-1 All processes with PID larger than 1
will be signaled.
-p Specify
that kill should only print the
process id of the named processes, and not send any signals.
Example:
kill 4000
-It will kill process having id 4000.
3 36. FIND:
Search a folder hierarchy for
filename(s) that meet a desired criteria: Name, Size, Type
Syntax:
find [-H] [-L] [-P] [path...]
[expression]
Synposis:
-maxdepth
levels Descend at most levels (a
non-negative integer) levels of directories below the command line arguments.
-mindepth
levels Do not apply any tests or
actions at levels less than levels (a non-negative integer).
Example:
$
find -name "*.mp3"
-It will find the mp3 files from the
database regardless the name of the file.
3 37. ECHO:
It is
used to display message on the screen.
Syntax:
echo [option][string]
Synposis:
-n do not output the trailing newline
-e enable interpretation of backslash escapes
-E disable interpretation of backslash escapes
(default)
Example:
echo Hello
-It
will display sting Hello.
echo
$a
-It
will display value of variable a.
3 38. PWD:
It is
used to display present working directory.
Syntax:
pwd
[option]
Synopsis:
-L use PWD from environment, even if it contains sym
links
-P avoid all sym links.
Example:
pwd
-It
will display the present working directory.
3 39. SET:
This command is use to assign values to
the positional parameters.
Syntax:
$ set [sentence]
Synopsis:
-a Mark
variables which are modified or created for export.
-e Exit
immediately if a command exits with a nonzero exit status.
-f Disable
file name generation.
-n Read
commands but do not execute them.
-s Sort
the positional parameters lexicographically.
-t Exit
after reading and executing one command.
-u Treat
unset variables as an error when substituting.
-v Print
shell input lines as they are read.
-x Print
commands and their arguments as they are executed.
Example:
Set env
PATH "directory path”
-Sets
the environment path to search for files in the directory.
4 40. AWK:
Find and Replace text, database
sort/validate/index.
Syntax:
awk<options> 'Program'
Input-File1 Input-File2
Synposis:
-f fs use
fs for the input field separator
-f
program-file read the awk
program source from the file program-file, instead of from the first command line
argument.
-v
var=val assign the
variable var the value valbefore program execution begins.
Example:
$ ls
-l | awk '{print $5}’
-From
an ls - l listing, return the fifth item ($5) from each line of the output.
41. ALIAS:
It is used to specify the alias name, i.e. we can give a particular name to the commands and further use that name directly instead of that command.
Syntax:
alias [name=['command']]
Synopsis:
-a Removes all alias definitions from the environment of the current shell session-t Sets and lists tracked aliases.
-x Sets or prints exported aliases. An exported alias is defined for scripts invoked by name.
Example:
alias a=’ls –l’
-a will execute same command as ls –l
42. INFO:
To see the information online.
Syntax:
info [option][menu-item]
Synposis:
-k look up STRING in all indices of all manuals.
-d add DIR to INFOPATH.
-f specify Info file to visit.
-h display this help and exit.
-n specify nodes in first visited Info file.
-o output selected nodes to filename.
Example:
infoemacs.
43. MAN:
This command will invoke the manual which we want help for.
Syntax:$ man [ directory ]
SYNOPSIS
-a By default, man will exit after displaying the first manual page it finds.
-c Reformat the source man page, even when an up-to-date cat page exists.
-F Format only - do not display.
-h Print a help message and exit.
-k Equivalent to apropos.
Example:
$ man cd
-Here manual for help of command ‘cd’
will be open.
44. GREP:
It
is used to find the whole line of a particular pattern in the file.
Syntax:
grep [options] PATTERN
[FILE...]
grep [options] [-ePATTERN | -fFILE] [FILE...]
Synposis:
-A
NUM Print NUM lines of trailing context after
matching lines.
Example:
Grep
he file1
-It
will display the whole line of the file file1 containing ‘he’.
45. CUT:
It
is used to divide a file into several parts and view it.
Syntax:
cut [OPTION].. [FILE]...o
Synposis:
-b select
only these bytes
-c select only these characters
-d use DELIM instead of TAB for field
delimiter
-n with -b: don't split multibyte characters
-s do not print lines not containing delimiters.
Example:
Cat
file1 | cut –c 2
-It
will cut the character no.2 from every line of file file1 and display it.
4 46. LN:
It is
used to store the hardlink or shortcut of a file into another,or into a
directory.
Syntax:
ln [OPTION]... [-T] TARGETLINK_NAME
Synposis:
-b like --backupbut
does not accept an argument
-d, -F allow the superuser to attempt to
hard link directories.
-f remove
existing destination files
-n treat destination that is a symlink to a
directory as if it were a normal file
-I prompt whether to remove destinations
-s make symbolic links instead of hard links
-S override
the usual backup suffix
-t specify the DIRECTORY in which to create the
links
-T treat LINK_NAME as a normal file.
Example:
lnfile1
dir1
-Here hard
link or shortcut of file1 is copied into dir1.Now whatever update is done in
dir1 file will be reflected in the original file too.
47. DIFF:
It is used to display the differences between the two files.
Syntax:
diff [options] from-file to-file.
Synposis:
-a Treat all files as text.
-b Ignore changes in the amount of white space.
-B Ignore changes whose lines are all blank.
-C NUM Output NUM (default 3) lines of copied context.
-d Try hard to find a smaller set of changes.
-E Ignore changes due to tab expansion.
Example:
Diff file1 file2
-It will show exactly from where the file differs.
No comments:
Post a Comment