0% found this document useful (0 votes)
125 views40 pages

Operating System - Unix Commands:-Displays A Calendar Syntax: - Cal (Options) (Month) (Year) Description

The document summarizes 14 common Unix commands - cal, clear, man, pwd, cd, ls, exit, echo, who, whoami, mkdir, rmdir, bc, and uname. It provides the syntax, description, and examples of how to use each command.

Uploaded by

Priyank Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
125 views40 pages

Operating System - Unix Commands:-Displays A Calendar Syntax: - Cal (Options) (Month) (Year) Description

The document summarizes 14 common Unix commands - cal, clear, man, pwd, cd, ls, exit, echo, who, whoami, mkdir, rmdir, bc, and uname. It provides the syntax, description, and examples of how to use each command.

Uploaded by

Priyank Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 40

3140702 – Operating System | Unix Commands

1) cal :- Displays a calendar


Syntax: - cal [options] [ month ] [year]
Description: -
Ø cal displays a simple calendar. If arguments are not specified, the current
month is displayed.
Ø In addition to cal, the ncal command ("new cal") is installed on some Linux
systems. It provides the same functions of cal, but it can display the calendar
vertically (with weeks in columns), and offers some additional options.
Option Use
-1 Display single (current) month output. (This is the default.)
-3 Display prev/current/next month output
-s Display Sunday as the first day of the week (This is the
default.)
-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
-w Print the number of the week under each week column
Example: -

2) clear :- It clears the terminal screen.


Syntax: - clear
Description: -
Ø clear command clears your screen if this is possible, including its scroll
back buffer.
Ø It ignores any command-line parameters that may be present.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 1


3140702 – Operating System | Unix Commands

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: -

4) pwd :- Displays path from root to current directory


Syntax :- pwd [options]

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 2


3140702 – Operating System | Unix Commands

Example:

5) cd :- It is used to change the directory.


Syntax: - cd [directory]
Description: -
Ø Used to go back one directory on the majority of all UNIX shells. It is
important that the space be between the cd and directory name or ..
Option Use
cd .. Change Current directory to parent directory
cd Lab_1 Change from current working directory to lab_1
Example: -

6) ls :- Lists the contents of a directory


Syntax: - ls [options] [file|dir]
Description: -
Optio Use
n
-a Shows you all files, even files that are hidden (these files begin with a
dot.)
-d If an argument is a directory it only lists its name not its contents

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 3


3140702 – Operating System | Unix Commands

-l Shows you huge amounts of information (permissions, owners, size,


and when last modified.)
-p Displays a slash ( / ) in front of all directories
-r Reverses the order of how the files are displayed
-t Sort by time & date
-S Sort by file size
-R Includes the contents of subdirectories
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.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 4


3140702 – Operating System | Unix Commands

Ø 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.

exit :- It is used to terminate a program, shell or log you out of a network


7)
normally.
Syntax: - exit

8) echo :- It prints the given input string to standard output.


Syntax: - echo string
Description: -
Option Use
-n Do not output a trailing newline
-e Enable interpretation of backslash escape sequences
Example: -

9) who :- who command can list the names of users currently logged in, their
terminal, the time

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 5


3140702 – Operating System | Unix Commands

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: -

1) whoami:- Print effective userid


Syntax: - whoami
Description: - Print the user name associated with the current effective user id.
Example: -

11) mkdir :- This command is used to create a new directory


Syntax: - mkdir [options] directory

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 6


3140702 – Operating System | Unix Commands

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: -

12) rmdir :- It is used to delete/remove a directory and its subdirectories.


Syntax: - rmdir [options...] Directory
Description: -
Ø It removes only empty directory.
Option Use
-p Remove directory and its ancestors
Example: -

13) bc :- bc command is used for command line calculator. It is similar to basic


calculator. By using which we can do basic mathematical calculations.
Syntax: - bc [options]

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 7


3140702 – Operating System | Unix Commands

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: -

14) uname :- It is used to print system information.


Syntax: - uname [options]
Description: -
Ø Print certain system information.
Option Use
-s print the kernel name
-n print the network node hostname
-r print the kernel release
-v print the kernel version
-m print the machine hardware name
-o print the operating system

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 8


3140702 – Operating System | Unix Commands

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: -

16) stty :- Change and print terminal line settings.


Syntax: - sty
Description: -
Ø stty sets certain terminal I/O modes for the device that is the current
standard input.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 9


3140702 – Operating System | Unix Commands

Ø Without arguments, it writes the settings of certain modes to standard


output.
Example: -

17) cat :- It is used to create, display and concatenate file contents.


Syntax: - cat [options] [FILE]...
Description: -
Option Use
-b Omits line numbers for blank space in the output
-E Displays a $ (dollar sign) at the end of each line
-n Line numbers for all the output lines
-s If the output has multiple empty lines it replaces it with one empty line
-T Displays the tab characters as ^I in the output

Ø Basically, three uses of the cat command.


1) Create new files.
2) Display the contents of an existing file.
3) Concatenate the content of multiple files and display.
Example: -

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 10


3140702 – Operating System | Unix Commands

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:-

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 11


3140702 – Operating System | Unix Commands

19) rm :- It is used to remove/delete the file from the directory.


Syntax: - rm [options...] [file|directory]
Description: -
Ø Files can be deleted with rm. It can delete more than one file with a single
invocation. For deleting a single file we have to use rm command with
filename to be deleted.
Ø Deleted file can’t be recovered. rm can’t delete the directories. If we want to
remove all the files from the particular directory we can use the * symbol.

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: -

20) mv :- It is used to move/rename file from one directory to another.


Syntax: - mv [options] oldname newname
Description: -
Ø mv command which is short for move.
Ø mv command is different from cp command as it completely removes the file
from the source and moves to the directory specified, where cp command
just copies the content from one file to another.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 12


3140702 – Operating System | Unix Commands

Ø mv has two functions: it renames a file and it moves a group of files to a


different directory.
Ø mv doesn’t create a copy of the file , it merely renames it. No additional
space is consumed on disk during renaming. For example if we rename a file
os to os1 and then if we try to read file os we will get error message as it is
renamed to os1 there is no existence of file named os.
Option Use
-i Prompts before overwriting another file
-f Force move by overwriting destination file without prompt
-n Never overwrite any existing file
-u Update – move when source is newer than destination
-v Print informative messages
Example:-

21) nl :- nl numbers the lines in a file.


Syntax: - nl [OPTION] [FILE]
Description: -
Option Use
-i line number increment at each line
-s add STRING after (possible) line number
-w use NUMBER columns for line numbers
Example: -

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 13


3140702 – Operating System | Unix Commands

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 14


3140702 – Operating System | Unix Commands

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 15


3140702 – Operating System | Unix Commands

Example: -

24) more:- Displays text one screen at a time.


Syntax: - more [options] filename
Description: -
Ø More command displays its output a page at a time.
Ø For example we are having a big file with thousands of records and we want
to read that file then we should use more command.

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 16


3140702 – Operating System | Unix Commands

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 17


3140702 – Operating System | Unix Commands

Example:-

26) comm :- compare two sorted files line by line


Syntax: - comm [option]... FILE1 FILE2
Description: -
Ø Compare sorted files FILE1 and FILE2 line by line.
Ø Requires two sorted files and lists differing entries in different columns.
produces three text columns as output:

1 Lines only in file1.


2 Lines only in file2.
3 Lines in both files.

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 18


3140702 – Operating System | Unix Commands

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 19


3140702 – Operating System | Unix Commands

Example:-

• d – a line was deleted


• c – a line was changed
• a – a line was added

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

5 read and execute


6 read and write
set all
7
permissions
Example :

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 21


3140702 – Operating System | Unix Commands

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]

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 22


3140702 – Operating System | Unix Commands

Description: -
Option Use
-i Force long output format
-m Match arguments only on user name (not first or last name)
Example: -

33) sleep :- Delay for a specified amount of time


Syntax :- sleep NUMBER[SUFFIX]
Description: -
Ø The sleep command pauses for an amount of time defined by NUMBER.
Ø SUFFIX may be "s" for seconds (the default), "m" for minutes, "h" for hours,
or "d" for days.
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.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 23


3140702 – Operating System | Unix Commands

Example: -

35) kill :- kill command is used to kill the background process.


Syntax: - kill [options] pid
Description: -
Ø The command kill sends the specified signal to the specified process or
process group.
Ø If no signal is specified, the TERM signal is sent. The TERM signal will kill
processes which do not catch this signal.
Ø For other processes, it may be necessary to use the KILL (9) signal, since
this signal cannot be caught.

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

Syntax: - ln [options] existingfile(or directory)name newfile(or directory)name


Description: -
What Is A Link?
Ø A link is an entry in your file system which connects a filename to the actual
bytes of data on the disk. More than one filename can "link" to the same
data. Here's an example. Let's create a file named file1.txt:
$ echo "This is a file." > file1.txt
Ø This command echoes the string "This is a file". Normally this would simply
echo to our terminal, but the > operator redirects the string's text to a file,
in this case file1.txt
Ø When this file was created, the operating system wrote the bytes to a
location on the disk and also linked that data to a filename, file1.txt so that
we can refer to the file in commands and arguments.
Ø If you rename the file, the contents of the file are not altered; only the
information that points to it.
Ø The filename and the file's data are two separate entities.

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”

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 25


3140702 – Operating System | Unix Commands

Ø 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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 26


3140702 – Operating System | Unix Commands

Ø we can cat either one of these to see the contents:


$ cat file1.txt
This is a file.
$ cat file2.txt
This is a file.
Ø But, if we remove file1.txt:
$ rm file1.txt
Ø we can no longer access the data it contained with our symlink:
$ cat file2.txt
cat: file2.txt: No such file or directory
Option Use
-s Makes it so that it creates a symbolic link
-f If the destination file or files already exist, overwrite
them
-i Prompt the user before overwriting destination files

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 27


3140702 – Operating System | Unix Commands

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 : -

39) sort :- It is used to sort the lines in a text file.


Syntax: - sort [options] filename

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 28


3140702 – Operating System | Unix Commands

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’

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 29


3140702 – Operating System | Unix Commands

-newer filename Search for files that were modified/created after


‘filename’
-user filename Search for files owned by user name or ID ‘name’
-size +N/-N Search for files of ‘N’ blocks; ‘N’ followed by ‘c’ can be
used to measure size in characters
-empty Search for empty files and directories
-perm octal Search for the file if permission is ‘octal’
Example:-

41) uniq :- Report or filter out repeated lines in a file.


Syntax: - uniq [option] filename
Description : -
Ø It can remove duplicates, show a count of occurrences, show only repeated
lines, ignore certain characters and compare on specific fields.

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 30


3140702 – Operating System | Unix Commands

-u Prints only unique lines


Example:-

42) tr :- Translate characters.


Syntax: - tr [options] set1 [set2]
Description: -
Ø It supports a range of transformations including uppercase to lowercase,
squeezing repeating characters, deleting specific characters and basic find
and replace.
Ø It can be used with UNIX pipes to support more complex translation.
Ø tr stands for translate.
Ø POSIX Character set supported by tr command :
• [:digit:] Only the digits 0 to 9.
• [:alnum:] Any alphanumeric character.
• [:alpha:] Any alpha character A to Z or a to z.
• [:blank:] Space and TAB characters only.
• [:xdigit:] Hexadecimal notation 0-9, A-F, a-f.
• [:upper:] Any alpha character A to Z.
• [:lower:] Any alpha character a to z.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 31


3140702 – Operating System | Unix Commands

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 32


3140702 – Operating System | Unix Commands

Example: -

44) write :- Send a message to another user.


Syntax: - write person [ttyname]
Description: -
Ø The write utility allows you to communicate with other users, by copying
lines from your terminal to theirs.
Ø When you run the write command, the user you are writing to gets a message
of the format:
Message from yourname@yourhost on yourtty at hh:mm ...
Ø Any further lines you enter will be copied to the specified user's terminal. If
the other user wants to reply, they must run write as well.
Ø When you are done, type an end-of-file or interrupt character. The other
user will see the message ‘EOF’ indicating that the conversation is over.
person If you wish to talk to someone on your own machine, then person is just
the person's login name. If you wish to talk to a user on another host,
then person is of the form 'user@host'.
ttyname If you wish to talk to a user who is logged in more than once, the ttyname
argument may be used to indicate the appropriate terminal name, where
ttyname is of the form 'ttyXX' or 'pts/X'

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 33


3140702 – Operating System | Unix Commands

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

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 34


3140702 – Operating System | Unix Commands

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.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 35


3140702 – Operating System | Unix Commands

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: -

49) | (Pipeline command) :- The Pipe is a command in Linux that lets


you use two or more commands such that output of one command serves as input
to the next.
Syntax: - command_1 | command_2 | command_3 | .... | command_N…
Description: -
Ø In short, the output of each process directly as input to the next one like a
pipeline.
Ø The symbol '|' denotes a pipe.
Ø Pipes help you mash-up two or more commands at the same time and run them
consecutively.
Example:-

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 36


3140702 – Operating System | Unix Commands

Basic system administration commands of unix

1) date : - Prints or sets the date and time.


Syntax :- date[options] [+format] [date]
Description: -
Ø Display the current date with current time, time zone.
Ø The command can also be used with suitable format specifies as arguments.
Each format is preceded by a + symbol, followed by the % operator, and a
single character describing the format.
Format
Option Use
%a Abbreviated weekday(Tue)
%A Full weekday(Tuesday)
%b Abbreviated month name(Jan)
%B Full month name(January)
%c Country-specific date and time format
%D Date in the format %m/%d/%y
%j Julian day of year (001-366)
%p String to indicate a.m. or p.m.
%T Time in the format %H:%M:%S
%t Tab space
%V Week number in year (01-52); start week on Monday
Example:-

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 37


3140702 – Operating System | Unix Commands

2) wall :- send a message to everybody's terminal.


Syntax :- wall [ message ]

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 38


3140702 – Operating System | Unix Commands

Ø Wall sends a message to everybody logged in with their mesg(1) permission


set to yes. The message can be given as an argument to wall, or it can be
sent to wall's standard input. When using the standard input from a
terminal, the message should be terminated with the EOF key (usually
Control-D).
Ø The length of the message is limited to 20 lines.
Ø wall sends a message to everybody logged in with their mesg permission set
to yes.
Example : -

3) passwd :- It is used to change your password.


Syntax: - passwd
Description: -
Ø Passwd changes the password or shell associated with the user given by
name or the current user if name is omitted.

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 39


3140702 – Operating System | Unix Commands

Ø 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 : -

Prof. Maulik Trivedi, CE Department | 3140702 – Operating System (2019-20) 40

You might also like