showriblog.files.wordpress.com  · web view2017. 12. 19. · the passwd command is used to change...

54
EXP: 5 Basic UNIX Commands Basic UNIX Commands - Table of Contents A. UNIX Commands for Manipulating Files cat, chgrp, chmod, chown, cp, cut, mkdir, more, mv, paste, rm, rmdir B. UNIX Shell Environment Control Commands alias, cd, clear, exit, export, passwd, read, unalias, unset C. Commands for UNIX Job/Process Control bg, fg, kill, jobs, ps D. Informational UNIX Commands date, diff, echo, env, file, find, finger, grep, head, history, hostname, ls, man, print, printinv, pwd, strings, tail, uname, wc, who E. UNIX Utilities awk, ftp, gzip, gunzip, ping, sed, talk, tar, vi, wall, write A. UNIX Commands for Manipulating Files a)cat 1. Display Contents of File In the below example, it will show contents of /etc/passwd file. 2. View Contents of Multiple Files in terminal In below example, it will display contents of test and test1 file in terminal. 3. Create a File with Cat Command NBKRIST III B.TECH IISEM -CSE FOSS LAB Page 1

Upload: others

Post on 12-Feb-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

EXP: 5 Basic UNIX Commands

Basic UNIX Commands - Table of Contents

A. UNIX Commands for Manipulating Files

cat, chgrp, chmod, chown, cp, cut, mkdir, more, mv, paste, rm, rmdir

B. UNIX Shell Environment Control Commands

alias, cd, clear, exit, export, passwd, read, unalias, unset

C. Commands for UNIX Job/Process Control

bg, fg, kill, jobs, ps

D. Informational UNIX Commands

date, diff, echo, env, file, find, finger, grep, head, history, hostname, ls, man, print, printinv, pwd, strings, tail, uname, wc, who

E. UNIX Utilities

awk, ftp, gzip, gunzip, ping, sed, talk, tar, vi, wall, write

A. UNIX Commands for Manipulating Files

a)cat

1. Display Contents of File

In the below example, it will show contents of /etc/passwd file.

2. View Contents of Multiple Files in terminal

In below example, it will display contents of test and test1 file in terminal.

3. Create a File with Cat Command

We will create a file called test2 file with below command.

Awaits input from user, type desired text and press CTRL+D (hold down Ctrl Key and type ‘d‘) to exit. The text will be written in test2 file. You can see content of file with following cat command.

4. Use Cat Command with More & Less Options

If file having large number of content that won’t fit in output terminal and screen scrolls up very fast, we can use parameters more and less with cat command as show above.

5. Display Line Numbers in File

With -n option you could see the line numbers of a file song.txt in the output terminal.

6. Display $ at the End of File

In the below, you can see with -e option that ‘$‘ is shows at the end of line and also in space showing ‘$‘ if there is any gap between paragraphs. This options is useful to squeeze multiple lines in a single line.

7. Display Tab separated Lines in File

In the below output, we could see TAB space is filled up with ‘^I‘ character.

8. Display Multiple Files at Once

In the below example we have three files test, test1 and test2 and able to view the contents of those file as shown above. We need to separate each file with ; (semi colon).

9. Use Standard Output with Redirection Operator

We can redirect standard output of a file into a new file else existing file with ‘>‘ (greater than) symbol. Careful, existing contents of test1 will be overwritten by contents of test file.

10. Appending Standard Output with Redirection Operator

Appends in existing file with ‘>>‘ (double greater than) symbol. Here, contents of test file will be appended at the end of test1 file.

11. Redirecting Standard Input with Redirection Operator

When you use the redirect with standard input ‘<‘ (less than symbol), it use file name test2 as a input for a command and output will be shown in a terminal.

12. Redirecting Multiple Files Contain in a Single File

This will create a file called test3 and all output will be redirected in a newly created file.

13. Sorting Contents of Multiple Files in a Single File

This will create a file test4 and output of cat command is piped to sort and result will be redirected in a newly created file.

b) chgrp

chgrp(CHange GRouP) 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

OPTIONS:

-RChange the permission on files that are in the subdirectories of the directory that you are currently in.

-cChange the permission for each file.

-fForce. Do not report errors.

EXAMPLE:

chgrp hiox test.txt

The group of 'test.txt' file is root, Change to newgroup hiox.

chgrp -R hiox test

The group of 'test' directory is root. With -R, the files and its subdirectories also changes to newgroup hiox.

chgrp -c hiox calc.txt

They above command is used to change the group for the specific file('calc.txt') only.

c) chmod

The syntax of chmod command is

chmod [options] mode filename

THe important options are:

-R : recursively change the permissions of a directory.

-v : Verbose

Chmod Examples in Linux / Unix:

1. Give read, write and execute permissions to everyone.

Read, write and execute: 4+2+1=7

$ chmod 777 sample.sh

Alternatively, you can use the symbolic representation to give the permissions.

chmod ugo+rwx sample.sh

2. Give read permission to user, write permission to group and execute permission to others.

$ chmod 421 sample.sh

3. Recursive permissions to directory

To give read and write permissions to all the users to a directory (including files and subdirectories) use the recursive option -R.

$chmod -R 666 /dir

Symbolic Representation of Permissions:

The following symbols are used to represent the users, groups and others:

u : User

g : Group

o : Others a : All (user, group and others)

The following symbols represent the permissions:

r : read

w : write

x : execute

The following symbols represent the permissions grant or revoke:

+ : Additional permissions. Selected permissions are added.

- : Revoke the permissions. Selected permissions are revoked.

= : Specific permissions. Only selected permissions are assigned.

Examples:

1. Remove write permission from group

$ chmod g-w sample.sh This will only removes the write permission for the group. 

2. Add new permission execute to others

$ chmod o+x sample.sh

3. Give only read permissions to the user

$ chmod u=w sample.sh

4) chown

The chown command changes the owner and owning group of files.

1. Change the owner of a file

# ls –l art tmpfile

-rw-r--r-- 1 himanshu family 0 2012-05-22 20:03 tmpfile

# chown root tmpfile

# ls -l tmpfile

-rw-r--r-- 1 root family 0 2012-05-22 20:03 tmpfile

2. Change the group of a file

Through the chown command, the group (that a file belongs to) can also be changed.

# ls -l tmpfile

-rw-r--r-- 1 himanshu family 0 2012-05-22 20:03 tmpfile

# chown :friends tmpfile

# ls -l tmpfile

-rw-r--r-- 1 himanshu friends 0 2012-05-22 20:03 tmpfile

3. Change both owner and the group

# ls -l tmpfile

-rw-r--r-- 1 root family 0 2012-05-22 20:03 tmpfile

# chown himanshu:friends tmpfile

# ls -l tmpfile

-rw-r--r-- 1 himanshu friends 0 2012-05-22 20:03 tmpfile

So we see that using the syntax ‘:’, the owner as well as group can be changed in one go.

5) cp

The cp command is used to make copies of files and directories.

Syntax: cp origfile newfile

1. Run cp without any options

2. Copy multiple files at the same time

3. Copy a directory

Copying a directory is a little bit tricky. You need to add -r or -R option to do it. -r or -R option means recursive. This option is a must whether the directory is empty or not. Here’s an example :

4. Explain what is being done

By default, when copying activity is success, we will see a command prompt again. If you want to know what happen during the copying file, we can use -v option.

5.Use interactive mode

Interactive mode will ask if the destination folder have already the file. To activate interactive mode, use -i option.

6.Force copying

Using -f option will force the copying activity. If the destination files cannot be opened, then -f will try again.

6) cut

Remove or "cut out" sections of each line of a file or files.

Unix Cut Command Example

We will see the usage of cut command by considering the below text file as an example

1. Write a unix/linux cut command to print characters by position?

The above cut command prints the fourth character in each line of the file. You can print more than one character at a time by specifying the character positions in a comma separated list as shown in the below example

2.Write a unix/linux cut command to print characters by range?

You can print a range of characters in a line by specifying the start and end position of the characters.

The above cut command prints the characters from fourth position to the seventh position in each line. To print the first six characters in a line, omit the start position and specify only the end position.

To print the characters from tenth position to the end, specify only the start position and omit the end position.

3.Write a unix/linux cut command to print the fields using the delimiter?

You can use the cut command just as awk command to extract the fields in a file using a delimiter. The -d option in cut command can be used to specify the delimiter and -f option is used to specify the field position.

This command prints the second field in each line by treating the space as delimiter. You can print more than one field by specifying the position of the fields in a comma delimited list.

7.mkdir

Short for "make directory", mkdir is used to create directories on a file system.

How to create one directory

This first example creates a new directory named tmp in your current directory:

How to create multiple directories at one time

"Permission denied" errors

As a final note, if you try to create a directory like this:

and you get an error message like this:

as the message implies, you don't have permission to create this directory. You can use the ls command to figure out what permission you have in this directory.

Create the mydir directory, and set its permissions such that all users may read, write, and execute the contents.

8) more

What Does The Linux More Command Do

The more command allows you to display output in the terminal one page at a time. This is especially useful when running a command which causes a lot of scrolling such as the ls command or the du command. Display the contents of file myfile.txt, beginning at line 3

List the contents of the current directory with ls, using more to display the list one screen at a time.

9) mv

The mv command is used to move or rename files.

1. Rename a File

While renaming a file using mv command, it keeps the inode number same even after moving it to a different name. If you move the file to a different filesystem, the inode number will be different.

2. Moving multiple files

If we want to move multiple files, we put them in one line separated by space.

3. Moving directory

4. Renaming directory

5. Using interactive mode

10) paste

paste command, is used to merge lines of files. It is very useful for merging a single file and also for merging set of files as well.

Let us consider a file with the sample contents as below:

paste command with a single file:

1. paste command without any options is as good as the cat command when operated on a single file.

2. Join all lines in a file:

3. Join all lines using the comma delimiter:

-d option is used to specify the delimiter. Using this -d and -s combination, all the lines in the file get merged into a single line.

4. Merge a file by pasting the data into 2 columns:

The '-' reads a line from the standard input. Two '-' reads 2 lines and pastes them side by side.

5.Merge a file by pasting the data into 2 columns using a colon separator:

6. Merge a file by pasting the file contents into 3 columns:

paste command with multiple files:

Let us consider a file, file2, with the following contents:

7. paste contents of 2 files side by side.

8. paste contents of 2 files side by side with a comma separator:

9.Read lines in both the files alternatively:

11) rm

The rm command removes (deletes) files or directories.

1 Remove or delete a file.

Let’s delete a file with name “linuxstufff.log”

Delete multiple files at once.

Example:2 Delete the files interactively.

‘-i‘ option in rm command will prompt before deleting a file, example is shown below.

Example:3 Delete a empty directory

use ‘-d‘ option in rm command to delete a empty directory.

we can also use ‘rmdir‘ command to delete empty folder or directory.

Example:4 Deleting a directory recursively using ‘-r’ option

‘-r‘ option in rm command will delete all the files and sub-directories recursively of the parent directory.

Example:5 Deleting files forcefully using ‘-f’ option

Example:6 Delete large number files using rm command.

12) rmdir

You can delete empty directory using rmdir command, or directory with content using rm command. Deletion can be done interactively, recursively, forcefully, or through alias.

1. How to Delete Empty Directories in Unix?

rmdir command will delete the empty directories. i.e directory without any sub-directories or files.

To ensure that you are deleting an empty directory you should use rmdir command. If there is any files / directories in that directory it will display the following error.

2. How to Delete Nested Empty Directories in Linux?

Use option -p, to delete nested directories as shown below.

3. Delete Directory Which has Content (i.e Directory with Files and Sub-directories)

4. Delete Interactively: Avoid using -f in rm at the early stages.

Deleting a file interactively.

B. UNIX Shell Environment Control Commands

1) alias

alias instructs the shell to replace one string with another when executing commands.

Now you can just type search instead of grep at your Linux command line:

How to set an shell alias

Building on the previous example an alias can be directly set in the shell as follows.

Now when the rm command is run it will use the alias and the -i option.

2) cd

The cd command, which stands for "change directory", changes the shell's current working directory.

1. Change from current directory to /usr/local.

2. Change from current directory to /usr/local/lib using absolute path.

3. Change from current working directory to /usr/local/lib using relative path.

4. (a) Move one directory back from where you are now.

4. (b) Change Current directory to parent directory.

5. Move to users home directory from anywhere.

3) clear

This command clears the terminal screen.

SYNTAX :

clear

OPTIONS:

There are no options for clearscreen command.

EXAMPLE:

clear

clear command clearscreen like cls command.

You can also have alias for this command.

alias c='clear'

c is the alias name for clear command.

4) exit

Issuing the exit command at the shell prompt will cause the shell to exit.

How to get the exit code of a command

The command was successful. The file exists and there are no errors in reading the file or writing it to the terminal. The exit code is therefore 0.

In the following example the file does not exist.

The exit code is 1 as the operation was not successful.

How to use exit codes in scripts

5) export

Syntax

export VAR

You can assign value before exporting using the following syntax:

export VAR=value

To see all a list of all exported variables and functions, enter:

export -p

6) passwd

The passwd command is used to change the password of a user account. A normal user can run passwd to change their own password, and a system administrator (the superuser) can use passwd to change another user's password, or define how that account's password can be used or changed.

Example:1 Change Password of System Users

When you logged in as non-root user like ‘linuxtechi’ in my case and run passwd command then it will reset password of logged in user.

Example:2 Display Password Status Information.

To display password status information of a user , use -S option in passwd command.

In the above output first field shows the user name and second field shows Password status ( PS = Password Set , LK = Password locked , NP = No Password ), third field shows when the password was changed and last & fourth field shows minimum age, maximum age, warning period, and inactivity period for the password

Example:3 Display Password Status info for all the accounts

Example:4 Removing Password of a User using -d option

Example:5 Set Password Expiry Immediately

Example:6 Lock the password of System User

Example:7 Unlock User’s Password using -u option

Example:8 Setting inactive days using -i option

Example:9 Set Minimum Days to Change Password using -n option.

Example:10 Set Warning days before password expire using -w option

7) read

The read command is useful in scripts when reading or asking an input from user.

read command syntax

read VARIABLE

Example1: Read a value from user input.

read VAR1

To display this value we have to use echo command.

echo $VAR1

Example2: Reading multiple values at a time.

8)unalias

Remove each name from the list of defined aliases.

$ unalias p

9) unset

Use unset command to delete the variables during program execution. It can remove both functions and shell variables.

vech=Bus

echo $vech

unset vech

echo $vech

C. Commands for UNIX Job/Process Control

1)bg(background) 2. fg(foreground) 3.jobs 4. kill

bg is a job control command that resumes suspended jobs while keeping them running in the background.

1. View all the background jobs using jobs command

You can list out the background jobs with the command jobs. Sample output of jobs command is

2. Taking a job from the background to the foreground using fg command

You can bring a background job to the foreground using fg command. When executed without arguments, it will take the most recent background job to the foreground.

If you have multiple background ground jobs, and would want to bring a certain job to the foreground, execute jobs command which will show the job id and command. In the following example, fg %1 will bring the job#1 (i.e download-file.sh) to the foreground.

3. Kill a specific background job using kill %

If you want to kill a specific background job use, kill %job-number. For example, to kill the job 2 use

5) ps

PS gives a snapshots of the current process

1. Run ps without any options

By default, it will show us 4 columns of information.

PID is a Process ID of the running command (CMD)

TTY is a place where the running command runs

TIME tell about how much time is used by CPU while running the command

CMD is a command that run as current process

2. Show all current processes

To do this, we can use -a options. As we can guess, -a is stand for “all”. While x will show all process even the current process is not associated with any TTY (terminal)

This result might be long result. To make it more easier to read, combine it with less command.

3. Filter processes by its user

For some situation we may want to filter processes by user. To do this, we can use -u option. Let say we want to see what processes which run by user pungki. So the command will be like below

4. Filter processes by CPU or memory usage

Sort the CPU

5. Show processes in hierarchy

D. Informational UNIX Commands

date, diff, echo, env, file, find, finger, grep, head, history, hostname, ls, man, print, printinv, pwd, strings, tail, uname, wc, who

1) date

The date command is used to print out, or change the value of, the system's time and date information.

1. Display Date from a String Value using –date Option

2. Read Date Patterns from a file using –file option

3. Get Relative Date Using –date option

4. Display Past Date

5. Set Date and Time using –set option

6. Display Universal Time using -u option

2. diff

diff analyzes two files and prints the lines that are different. Essentially, it outputs a set of instructions for how to change one file in order to make it identical to the second file.

How diff Works

Let's say we have two files, file1.txt and file2.txt.

If file1.txt contains the following four lines of text:

I need to buy apples.

I need to run the laundry.

I need to wash the dog.

I need to get the car detailed.

...and file2.txt contains these four lines:

I need to buy apples.

I need to do the laundry.

I need to wash the car.

I need to get the dog detailed.

...then we can use diff to automatically display for us which lines differ between the two files with this command:

Example 2:

Let's look at another example. Let's say our two files look like this:

file1.txt:

I need to go to the store.

I need to buy some apples.

When I get home, I'll wash the dog.

file2.txt:

I need to go to the store.

I need to buy some apples.

Oh yeah, I also need to buy grated cheese.

When I get home, I'll wash the dog.

Output:

2a3

> Oh yeah, I also need to buy grated cheese.

Here, the output is telling us "After line 2 in the first file, a line needs to be added: line 3 from the second file." It then shows us what that line is.

$diff –c file1.txt file2.txt

3) echo

echo displays a line of text.

1. Input a line of text and display on standard output

Outputs the following text:

2. Declare a variable and echo its value. For example, Declare a variable of x and assign its value=10.

echo its value:

3. Using option ‘\b‘ – backspace with backslash interpretor ‘-e‘ which removes all the spaces in between.

4. Using option ‘\n‘ – New line with backspace interpretor ‘-e‘ treats new line from where it is used.

5. Using option ‘\t‘ – horizontal tab with backspace interpretor ‘-e‘ to have horizontal tab spaces.

6. How about using option new Line ‘\n‘ and horizontal tab ‘\t‘ simultaneously.

7. Using option ‘\v‘ – vertical tab with backspace interpretor ‘-e‘ to have vertical tab spaces.

4) env

env is a shell command for Linux, Unix, and Unix-like operating systems. It can be used to print a list of the current environment variables, or to run another program in a custom environment without modifying the current one.

Executing env with no options displays the current environment variables and their values.

5) file

The file command is used to determine a file's type.

How to determine the file type of a file

To determine the file type of a file pass the name of a file to the file command.The file name along with the file type will be printed to standard

6) find

Find command used to search and locate list of files and directories based on conditions you specify for files that match the arguments

1. Find Files Using Name in Current Directory

2. Find Files Under Home Directory

3. Find all PHP Files in Directory

4. Find Executable Files

7) finger

finger looks up and displays information about system users.

1. View detail about a particular user

2. View login details and Idle status about an user

3. To get information about all users logged in to host alcat, enter

8)grep

To search a pattern of word in a file, grep file is used.

Syntax: $grep < word name> < file name>

Example

Let's say want to quickly locate the phrase "our products" in HTML files on your machine. Let's start by searching a single file. Here, our PATTERN is "our products" and our FILE is product-listing.html.

A single line was found containing our pattern, and grep outputs the entire matching line to the terminal.

1. Viewing grep output in color

If we use the --color option, our successful matches will be highlighted for us:

2. Viewing line numbers of successful matches

3. Performing case-insensitive grep searches

4. Searching multiple files using a wildcard

9) head

Head is used to display the first parts of a file, it outputs the first 10 lines by default. You can use the -n num flag to specify the number of lines to be displayed:

To see the top 10 lines of a file - $head

To see the top 5 lines of a file - $head -5 [or]

Command: $ head -n 5 /var/log/auth.log

10) tail

tail outputs the last parts (10 lines by default) of a file. Use the -n num switch to specify the number of lines to be displayed.

The command below will output the last 5 lines of the specified file:

To see last 10 lines of a file - $tail < file name>

To see last 20 lines of a file - $tail -20

11) history

We use history command frequently in our daily routine jobs to check history of command or to get info about command executed by user.

1. List Last/All Executed Commands in Linux

2. Delete or Clear History of Commands

3.Search Commands in History Using Grep Command

4.Recall Last Executed Command

Recall a previously used specific command. Combination of Bang and 8 (!8) command will recall number 8 command which you have executed.

5.Recall Lastly Executed Specific Command

6.Print ‘n’ Lines

7. Repeat Most Recent Command

The most recent command can be executed simply by entering ‘!!’.

8. Repeat Specific Command

12) hostname

The hostname command shows or sets the system hostname.

1. Print the hostname of the system

2. Ip address of the computer

3. Print the domain name

4. Short hostname

13) ls

1. List Files using ls with no option

2 List Files With option –l

3. View Hidden Files

4. List Files with Human Readable Format with option –lh

5. List Files and Directories with ‘/’ Character at the end

6. List Files in Reverse Order

7. Sort Files by File Size

8. Display Inode number of File or Directory

9. Shows version of ls command

14) man

On Linux and other Unix-like operating systems, man is the interface used to view the system's reference manuals.

man ls

Display the manual page for the item (program) ls.

15) print

1. Viewing the Print Queue with lpq

$ lpq

2. Canceling a Print Job Using lprm

$ lprm –

16) printenv

printenv prints all or part of the environment.

1. Display the location of the current user's home directory.

2. Display the values of all environment variables.

17) pwd

pwd‘ stands for ‘Print Working Directory‘

1. Print your current working directory.

2. Print all the locations containing executable named pwd.

18) strings

the following would display all strings in the files named file1 and file2 that consist of at least two characters:

strings -n 2 file1 file2

19) uname

Print information about the current system.

1. Displays system information

2. Kernel name

To reveal the kernel name, you can use -s parameter.

3. Kernel release

4. Kernel version

20) wc

The wc (word count) command in Unix/Linux operating systems is used to find out number of newline count, word count, byte and characters count in a files specified by the file arguments. The syntax of wc command as shown below.

The following are the options and usage provided by the command.

So, let’s see how we can use the ‘wc‘ command with their few available arguments and examples in this article. We have used the ‘tecmint.txt‘ file for testing the commands. Let’s find out the output of the file using cat command as shown below.

1. A Basic Example of WC Command

The ‘wc‘command without passing any parameter will display a basic result of ”tecmint.txt‘ file. The three numbers shown below are 12 (number of lines), 16 (number of words) and 112 (number of bytes) of the file.

2. Count Number of Lines

To count number of newlines in a file use the option ‘-l‘, which prints the number of lines from a given file.

3. Display Number of Words

Using ‘-w‘ argument with ‘wc‘ command prints the number of words in a file.

4. Count Number of Bytes and Characters

When using options ‘-c‘ and ‘-m‘ with ‘wc‘ command will print the total number of bytes and characters respectively in a file.

5. Display Length of Longest Line

The ‘wc‘command allow an argument ‘-L‘, it can be used to print out the length of longest (number of characters) line in a file.

21) who

Displays who is logged on to the system.

1. Get the information on currently logged in users

2. Get the time of last system boot

3. Get information on system login processes

4. Get the hostname and user associated with stdin

5. Get the current run level

6. Get the list of user logged in

7. Get number of users logged-in and their user names

8. Get all the information

E. UNIX Utilities

1) awk

Awk is a programming language which allows easy manipulation of structured data and the generation of formatted reports. Awk stands for the names of its authors “Aho, Weinberger, and Kernighan”

1. Default behavior of Awk

By default Awk prints every line from the file.

2.Print only specific field.

2) ftp

ftp is the user interface to the ARPANET standard File Transfer Protocol. It can be used to transfer files to and from a remote network.

1. Connect to a FTP site

or

2. Download a file using ftp

3. Uploading a file to FTP server

4. Downloading multiple files with mget command

5. Close a FTP connection

3) gzip

The "gzip" command is a common way of compressing files within Linux and therefore it is worth knowing how to compress files using this tool.

1. Compress a single file

gzip filename

2. Compress multiple files at once

gzip file1.txt file2.txt file3.txt

3. Compress a single file and keep the original

You can instead keep the original file and create a compressed copy.

gzip -c file.txt > file.txt.gz

4) gunzip

gzip, gunzip, and zcat are used to compress or expand files.

1.Unzip the gzip file

gunzip all.gz

5) ping

ping is a simple way to send network data to, and receive network data from, another computer on a network. It is frequently used to test, at the most basic level, whether another system is reachable over a network, and if so, how much time it takes for that data to be exchanged.

1. Ping the host to see if its alive

ping google.com

2. Increase or Decrease the Time Interval Between Packets

Increase Ping Time Interval

Example: Wait for 5 seconds before sending the next packet.

$ ping -i 5 google.com

Decrease Ping Time Interval

Example: Wait 0.1 seconds before sending the next packet.

# ping -i 0.1 google.com

3. Send N packets and stop

$ ping -c 4 google.com

4. Give beep when the peer is reachable

$ ping -a IP

6) sed(Stream EDitor)

sed is a powerful stream editor for filtering and transforming text.

It is used to cut the information horizontally.

To see the first line in file sun,

$sed -n 1p sun

To see 3 to 5 lines

$sed -n '3,5p' sun

1. Replacing or substituting string

2. Replacing the nth occurrence of a pattern in a line.

3. Duplicating the replaced line with /p flag

4. Running multiple sed commands.

5. Replacing string on a specific line number

6. Deleting lines.

You can delete the lines a file by specifying the line number

7)talk

Chat with other logged-in users.

Syntax:

talk person [ttyname]

talk hope

8) tar

The Linux “tar” stands for tape archive, which is used by large number of Linux/Unix system administrators to deal with tape drives backup.

1. Create tar Archive File

c – Creates a new .tar archive file.

v – Verbosely show the .tar file progress.

f – File name type of the archive file.

2. Create tar.gz Archive File

3. Uncompress tar.gz Archive File

9) vi

Originally developed by William Joy in the late 1970s, vi (pronounced "vee-eye") is a visual text editor.

vi filename

1. Opens an existing file in the read-only mode.

vi -R filename

10) all

wall writes a message to other users.

sudo wall message.txt

Using the sudo command to run wall as the superuser, sends the contents of message.txt to all users.

Wall test

11) write

write sends a message to another user.

write hope tty7

NBKRIST III B.TECH IISEM -CSE FOSS LABPage 46