0% found this document useful (0 votes)
48 views3 pages

Linux Advanced Commands

The document discusses various commands in Linux for searching strings in files, displaying processes, and networking tasks. It covers the grep command for searching strings in files, including options for ignoring case, searching multiple files, and using regular expressions. It also covers commands for listing and viewing processes like top, htop, ps, pstree, and kill. Finally, it discusses network commands like ping, ifconfig, traceroute, route, netstat, and nslookup for checking connectivity, IP addresses, routing tables, ports, and DNS lookups.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
0% found this document useful (0 votes)
48 views3 pages

Linux Advanced Commands

The document discusses various commands in Linux for searching strings in files, displaying processes, and networking tasks. It covers the grep command for searching strings in files, including options for ignoring case, searching multiple files, and using regular expressions. It also covers commands for listing and viewing processes like top, htop, ps, pstree, and kill. Finally, it discusses network commands like ping, ifconfig, traceroute, route, netstat, and nslookup for checking connectivity, IP addresses, routing tables, ports, and DNS lookups.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 3

Search for a string “linux” in a file using grep command in unix

This is the basic usage of grep command. It searches for the given string in the
specified file.

#grep “linux” index.html

Insensitive case search with grep -i

The below grep command searches for the words like “LINUX”, “Linux”, “linux” case
insensitively.

#grep -i “linux” index.html

Searching for a string in multiple files.

This command will search for "linux" string in multiple files at a time. It
searches in all files with file1.txt, file2.txt and along with different extensions
too like file1.html, file2.php and so on.

#grep “linux” file*.*

Specifying the search string as a regular expression pattern.

It is a very powerful feature and can use as a regular expression with much
effectively.
In the below example, it searches for all the pattern that starts with “fast” and
ends with “host” with anything in-between. i.e
To search “fast[anything in-between]host” in index.html file.

#grep “fast.*host” index.html

Displaying the line numbers.

You can use this grep command to display the line number which contains the matched
string in a file using the -n option

#grep -n “word*” file.txt

6. Highlighting the search using grep

If we use the –color option, our successful matches will be highlighted for us.

#grep –color “linux” index.html

7. Print the line excluding the pattern using -v option

List all the lines of the file /etc/passwd that does not contain specific word
“string”.

#grep -v linux /etc/passwd

Linux process commands


------------------------------

1. to display hidden files


[root@localhost admin]# ls -a
2.tree
Show files and directories in a tree starting from root
[root@localhost admin]# tree

3. top
top command gives you information on the processes that currently exist.
[root@localhost admin]# top
4. htop
It is similar to top, but allows you to scroll vertically and
horizontally, so you can see all the processes running on the
system, along with their full command lines, as well as view-
ing them as a process tree, selecting multiple processes and
acting on them all at once.
(Note: it works only in few distributions of linux)
[root@localhost admin]# htop

5.ps
Use the ps command to list running processes (top and htop list all processes
whether active or inactive).
[root@localhost admin]# ps

6.pstree
A step up from the simple ps command, pstree is used to display a tree diagram
of processes
that also shows relationships that exist between them.
[root@localhost admin]# pstree
7.kill
As its name suggests, kill can be used to terminate a process with
extreme prejudice.
[root@localhost admin]# kill -9 <processid>

=============================================================

#NetStat

netstat command allows you a simple way to review each of your network connections
and open sockets. netstat with head output is very helpful while performing web
server troubleshooting.

[root@localhost home]# netstat

Display statistics of all ports


[root@localhost home]# netstat -s

------------------------------
nslookup

A network utility program used to obtain information about Internet servers. As its
name suggests, the utility finds name server information for domains by querying
DNS.
[root@localhost home]# nslookup www.google.com

==================================================
Network commands
1.PING
PING(Packet Internet Groper) command sends packet requests to the address you
specify to test the connectivity between 2 nodes
ping IP/hostname
[root@localhost admin]# ping www.google.com

2.ifconfig
Ifconfig utility is used to configure network interface parameters.
Mostly we use this command to check the IP address assigned to the system

[root@localhost admin]#ifconfig -a
3.traceroute
traceroute print the route packets take to network host. Destination host or
IP is mandatory parameter to use this utility
[root@localhost admin]# traceroute www.google.com

4.route
route command is the tool used to display routeing table

[root@localhost admin]# route


5. ssh
Connect to host as user
[root@localhost admin]# ssh myuser4@localhost

You might also like