Operating System - Unix Commands:-Displays A Calendar Syntax: - Cal (Options) (Month) (Year) Description
Operating System - Unix Commands:-Displays A Calendar Syntax: - Cal (Options) (Month) (Year) Description
Example:-
3) man :- man command which is short for manual, provides in depth information
about the requested command (or) allows users to search for commands related to
a particular keyword.
Syntax: - man command name [options]
Example: -
Example:
Field Explanation:
Ø If first character is – then it is normal file
Ø If it is d then it is directory
Ø Field 1 – File Permissions: Next 9 character specifies the files permission.
Each 3 characters refers to the read, write, execute permissions for user,
group and world in this example, rwxr-xr-x indicates read-write-execute
permission for user, read-execute permission for group, and read-execute
permission for others.
Ø Field 2 – Number of links: Second field specifies the number of links for
that file. In this example, 1 indicates only one link to this file.
Ø Field 3 – Owner: Third field specifies owner of the file. In this example,
this file is owned by username “dietstaff”.
Ø Field 4 – Group: Fourth field specifies the group of the file. In this
example, this file belongs to “dietstaff” group.
Ø Field 5 – Size: Fifth field specifies the size of file. In this example, ’4096′
indicates the file size.
Ø Field 6 – Last modified date & time: Sixth field specifies the date and
time of the last modification of the file. In this example, ‘Jul 7 08:57′ specifies
the last modification time of the file.
Ø Field 7 – File or directory name: The last field is the name of the file
or directory. In this example, the file name is c1. c.
9) who :- who command can list the names of users currently logged in, their
terminal, the time
they have been logged in, and the name of the host from which they have logged
in.
Syntax: - who [options] [file]
Description: -
Option Use
-b Prints time of last system boot
-H Print column headings above the output
-a Display all details of current logged in user
Prints only the usernames and the user count/total no of users logged
-q
in
Example: -
Description: -
Option Use
-m Set permission mode
-p No error if existing, make parent directories as
needed
-v Print a message for each created directory
Example: -
Description: -
Ø bc is a language that supports arbitrary precision numbers with interactive
execution of statements.
Ø bc starts by processing code from all the files listed on the command line in
the order listed. After all files have been processed, bc reads from the
standard input. All code is executed as it is read.
Option Use
-q To avoid bc welcome message
-l To include math library functionalities
Example: -
Example:-
15) tty :- Print the file name of the terminal connected to standard input.
Syntax: - tty
Description: -
Ø tty writes the name of the terminal that is connected to standard input onto
standard output.
Ø Command is very simple and needs no arguments.
Example: -
18) cp :- cp command copy files from one location to another. If the destination is an
existing file, then the file is overwritten; if the destination is an existing directory,
the file is copied into the directory (the directory is not overwritten).
Syntax: - cp [option] source destination/directory
Description: -
Ø It will copy the content of source file to destination file.
Ø If the destination file doesn’t exist, it will be created.
Ø If it exists then it will be overwritten without any warning.
Ø If there is only one file to be copied then destination can be the ordinary file
or the directory file.
Option Use
-i interactive - ask before overwrite
-f force copy by removing the destination file if needed
-v print informative messages
-l link files instead of copy
-s follow symbolic links
-n no file overwrite
-u update - copy when source is newer than destination
-R copy directories recursively
Example:-
Option Use
-d Delete an empty directory
-r Remove directories and their contents recursively
-f Ignore non-existent files, and never prompt before removing
-i Prompt before every removal
Example: -
22) cut :- cut command is used to cut out selected fields of each line of a file. The cut
command uses delimiters to determine where to split fields.
Syntax :- cut [options] filename
Description: -
Option Use
-c The list following -c specifies character positions
-d The character following -d is the field delimiter
-f Select only these fields on each line
-b Select only the bytes from each line as specified in LIST
Example: -
23) paste:- paste command is used to paste the content from one file to another
file. It is also used to set column format for each line.
Syntax: - paste [option] file
Description: -
Ø Paste prints lines consisting of sequentially corresponding lines of each
specified file. In the output the original lines are separated by TABs. The
output line is terminated with a newline.
Option Use
-d Specify of a list of delimiters
-s Paste one file at a time instead of in parallel
Example: -
Option Use
-c Clear screen before displaying
-n Specify how many lines are printed in the screen for a given file
+n Starts up the file from the given number
-s Doesn’t display extra blank lines
Example: -
25) cmp :- It compares two files and tells you which line numbers are different.
Syntax: - cmp [options...] file1 file2
Description: -
Ø If a difference is found, it reports the byte and line number where the first
difference is found.
Ø If no differences are found, by default, cmp returns no output.
Option Use
-b Print differing bytes
-i Skip a particular number of initial bytes from both the files
-n Compare at most LIMIT bytes
-l Print byte position and byte value for all differing bytes
Example:-
Option Use
-1 suppress lines unique to FILE1
-2 suppress lines unique to FILE2
-3 suppress lines that appear in both files
--check-order check that the input is correctly sorted, even if all input
lines are pairable
--no check-order do not check that the input is correctly sorted
Example: -
Ø In the above output we can see that first column contains two lines unique
to the first file and second column contains three lines unique to the second
file and the third column contains two lines common to both the files.
Comm. Can produce the single column output using 3 options -1,-2 or -3.
To drop a particular column, simply use its column number as a prefix.
27) diff :- It is used to find differences between two files.
Syntax: - diff [options...] fileone filetwo
Description: -
Ø Diff is the third command that can be used to display file differences. Unlike
its fellow members, cmp and comm, it tells us which lines in one file have is
to be changed to make the two files identical.
Option Use
-b Ignore any changes which only change the amount
of whitespace (such as spaces or tabs)
-B Ignore blank lines when calculating differences
-i Ignore changes in case. consider upper- and lower-case letters
equivalent
Example:-
28) chmod :- chmod command allows you to alter / Change access rights to files
and directories.
Syntax: - chmod [options] [MODE] FileName
Description: -
Ø chmod command is used to set the permissions of one or more files for all
three categories of users (user,group and others ). It can be run only by the
user and super user. Command can be used in two ways. Let’s first take a
look at the abbreviations used by chmod command.
Category Operation Permission
u User + Assigns permission r Read permission
g Group - Removes permission w Write permission
o Others = Assigns absolute x Execute permission
File
#
Permission
0 none
1 execute only
2 write only
write and
3
execute
4 read only
Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 20
3140702 – Operating System | Unix Commands
29) chown :- Command for system V that changes the owner of a file.
Syntax: - chown [options] newowner filename/directoryname
Example: -
30) chgrp :- chgrp command is used to change the group of the file or directory.
This is an admin command. Root user only can change the group of the file or
directory.
Syntax: - chgrp [options] newgroup filename/directoryname
Example: -
file :- file command tells you if the object you are looking at is a file or a
31)
directory.
Syntax: - file [options] directoryname/filename
Description: -
Ø File command is used to determine the type of file, especially of an
ordinary file. We can use it with one or more filenames as arguments. For
example we can use file command to check the type of the os1 file that we
have created.
Option Use
To view the mime type of a file rather than the human readable
-i
format
Example: -
32) finger :- finger command displays the user's login name, real name, terminal
name and write status (as a ''*'' after the terminal name if write permission is
denied), idle time, login time, office location and office phone number.
Syntax: - finger [username]
Description: -
Option Use
-i Force long output format
-m Match arguments only on user name (not first or last name)
Example: -
ps :- It is used to report the process status. ps is the short name for Process
34)
Status.
Syntax: - ps [options]
Description: -
Option Use
Display every active process on a Linux system in generic (Unix/Linux)
-e
format.
-x View all processes owned by you
-u Filter processes by its user
-F to provide more information on processes.
Example: -
Option Use
-s send the specified signal to the process
-l list all the available signals.
-9 Force to kill a process.
Example: -
36) ln :- ln command is used to create link to a file (or) directory. It helps to provide
soft link for desired files.
Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 24
3140702 – Operating System | Unix Commands
File1.txt
“This is a file””
Ø What the link command does is allow us to manually create a link to file
data that already exists.
Ø So, let's use link to create our own link to the file data we just created. In
essence, we'll create another file name for the data that already exists.
$ link file1.txt file2.txt
Ø The important thing to realize is that we did not make a copy of this data.
Both filenames point to the same bytes of data on the disk. Here's an
illustration to help you visualize it:
File1.txt File2.txt
“This is a file”
Ø If we change the contents of the data pointed to by either one of these files,
the other file's contents are changed as well. Let's append a line to one of
them using the >>operator:
$ echo "Hello Linux" >> file1.txt
Ø Now let's look at the contents of file1.txt:
$ cat file1.txt
This is a file
Hello Linux
Ø Now let's look at the second file, the one we created with the link command.
$ cat file2.txt
This is a file
Hello Linux
Ø ln, by default, creates a hard link just like link does. So this ln command:
$ ln file1.txt file2.txt
Ø It is the same as the following link command. Because, both commands
create a hard link named file2.txt which links to the data offile1.txt.
$ link file1.txt file2.txt
Ø However, we can also use ln to create symbolic links with the -s option. So
the command:
$ ln -s file1.txt file2.txt
Ø It will create a symbolic link to file1.txt named file2.txt. In contrast to our
hard link example, here's an illustration to help you visualize our symbolic
link:
File1.txt File2.txt
“This is a file”
Ø You should also be aware that, unlike hard links, removing the file (or
directory) that a symlink(symbolic linkl) points to will break the link. So if
we create file1.txt:
$ echo "This is a file." > file1.txt
Ø Now, create a symbolic link to it:
$ ln -s file1.txt file2.txt
37) head :- head command is used to display the first ten lines of a file, and also
specifies how many lines to display.
Syntax: - head [options] filename
Description: -
Ø Head command displays the top of the file. When used without an option,
it displays the first ten lines of the file.
Option Use
-n To specify how many lines you want to display
-n The number option-argument must be a decimal integer whose
number sign affects the location in the file, measured in lines
-c The number option-argument must be a decimal integer whose
number sign affects the location in the file, measured in bytes
Example: -
38) tail :- tail command is used to display the last or bottom part of the file. By
default it displays last 10 lines of a file.
Syntax :- tail [options] filename
Description: -
Option Use
The number option-argument must be a decimal integer
-c number
whose sign affects the location in the file, measured in bytes
-n The number option-argument must be a decimal integer
number whose sign affects the location in the file, measured in lines
Example : -
Description: -
Ø By default, the sort command sorts file assuming the contents are ASCII.
Using options in sort command, it can also be used to sort numerically.
Option Use
-b Ignores spaces at beginning of the line
-c Check whether input is sorted; do not sort
-r Sorts in reverse order
-u If line is duplicated only display once
-n Compare according to string numerical value
-nr To sort a file with numeric data in reverse
order
-k Sorting a table on the basis of any column
Example:-
40) find :- Finds one or more files assuming that you know their approximate path.
Syntax :- find [options] path
Description: -
Ø Find is one of the powerful utility of Unix (or Linux) used for searching the
files in a directory hierarchy
Option Use
-name filename Search for files that are specified by ‘filename’
Option Use
-c Precede each output line with a count of the number of times the line
occurred in the input
-d Suppress the writing of lines that are not repeated in the input
-D Print all duplicate lines
-f Avoid comparing first N fields
-i Ignore case when comparing
-s Avoid comparing first N characters
Option Use
-c Use the complement of SET1
-d Delete characters in SET1, do not translate
-s Replace each input sequence of a repeated character that is listed in
SET1 with a single occurrence of that character
Example:-
43) history :- history command is used to list out the recently executed commands
in the number line order.
Syntax: - history [options]
Description: -
Ø The history command performs one of several operations related to recently-
executed commands recorded in a history list.
Optio Use
n
-c Clear the history list by deleting all of the entries
Example: -
Example: -
grep :- It selects and prints the lines from a file which matches a given string or
45)
pattern.
Syntax: - grep [options] pattern [file]
Description: -
Ø This command searches the specified input fully for a match with the
supplied pattern and displays it.
Ø While forming the patterns to be searched we can use shell match characters,
or regular expressions.
Ø grep stands for globally search for regular expression and print out.
Option Use
-i Ignore case distinctions
-v Invert the sense of matching, to select non-matching lines.
-w Select only those lines containing matches that form whole
words
-x Select only matches that exactly match the whole line.
-c Print a count of matching lines for each input file.
-n Display the matched lines and their line numbers
-o Print only the matched parts of a matching line
Example: -
46) pwd :-Displaying your current directory name (Print working directory).
Syntax: -pwd [options]
Description: -
Ø At the time of logging in user is placed in the specific directory of the file
system. You can move around from one directory to another, but any point
of time, you are located in only one directory. This directory is known as
your current directory. pwd command tells your current directory.
Example:-
47) wc :- Word Count (wc) command counts and displays the number of lines, words,
character and number of bytes enclosed in a file.
Syntax: - wc [options] [filename]
Description: -
Ø This command counts lines, words and characters depending on the options
used. It takes one or more filenames as its arguments and displays four-
columnar output. For example let’s read our os1 file. And we use wc
command with that filename.
Option Use
-l Print the newline counts
-w Print the word counts
-c Print the byte counts
-L Print the length of the longest line
Example: -
Ø First user has to insert current password. Then new password will be asked
followed by confirm new password field.
Ø passwd command can also be used to change the home directory where the
path stands for the home directory.
Example : -