Well most of us used to use grep in a pipe with other commands like netstat, ss, ps, etc., but grep is a very powerful tool and for instance could help you to locate text in the files of a directory.
Use:
$ grep -iR "text-to-find" *
The parameter -i is for no case sensitive search and -R is for recursive search.
As a result you can find a list of your files that contains the text and the line containing it.
See and example:
$ cd $TOMCAT_HOME
$ grep -iR "org.apache.tomcat" *
...
conf/catalina.properties:org.apache.naming.resources.,org.apache.tomcat.
conf/catalina.properties:org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
...
The grep command syntax is the following:
grep [OPTIONS] PATTERN [FILE...]
Where the options are:
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,
viernes, 14 de junio de 2019
Getting system info
Sometime you probably need to know some details for your systems as the linux distribution and version, type of CPU, etc.
These are some commands that could help you.
$ hostnamectl
Static hostname: YOURHOSTNAME
Icon name: computer-vm
Chassis: vm
Machine ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Boot ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Virtualization: vmware
Operating System: Ubuntu 16.04.5 LTS
Kernel: Linux 4.4.0-130-generic
Architecture: x86-64
If you need OS information, you have it on /etc/os-release.
$ cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="7.5"
...
You can find more info on this link https://www.cyberciti.biz/faq/how-to-check-os-version-in-linux-command-line/.
These are some commands that could help you.
$ hostnamectl
Static hostname: YOURHOSTNAME
Icon name: computer-vm
Chassis: vm
Machine ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Boot ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Virtualization: vmware
Operating System: Ubuntu 16.04.5 LTS
Kernel: Linux 4.4.0-130-generic
Architecture: x86-64
$ uname -a
Linux YOURHOSTNAME 4.4.0-130-generic #156-Ubuntu SMP Thu Jun 14 08:53:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
If you need hardware detailed info try with lshw:
$ lshw -short
H/W path Device Class Description
===========================================
system Computer
/0 bus Motherboard
/0/0 memory 7974MiB System memory
/0/1 processor Intel(R) Xeon(R) CPU E5-2670 v3 @ 2.30GHz
...
$ cat /etc/os-release
NAME="Oracle Linux Server"
VERSION="7.5"
...
You can find more info on this link https://www.cyberciti.biz/faq/how-to-check-os-version-in-linux-command-line/.
Enjoy!
lunes, 3 de junio de 2019
Identify a process who is listening in a port
Sometimes you need to identify a process than is associated
to a TCP port.
You can use ss instead netstat command to identify them.
For instance, if you want to identify what is the process
who is listen on TCP port 80, use the following command:
# ss -ltnp | grep -w ':80'
LISTEN 0 128 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=24503,fd=13),("nginx",pid=24502,fd=13),("nginx",pid=24499,fd=13))
Where:
- l – tells netstat to only show listening sockets.
- t – tells it to display tcp connections.
- n – instructs it show numerical addresses.
- p – enables showing of the process ID and the process name.
Then, with the process number (i.e. 24499) you can get the process
detail with:
# ls -l /proc/24499/exe
lrwxrwxrwx. 1 root root 0 Jun 3 08:37 /proc/24499/exe -> /opt/opscode/embedded/sbin/nginx
lrwxrwxrwx. 1 root root 0 Jun 3 08:37 /proc/24499/exe -> /opt/opscode/embedded/sbin/nginx
Suscribirse a:
Comentarios (Atom)
How to save a remote server SSL certificate locally as a file?
I found this answer following answer on StackExcahnge and it works perfect. Enjoy! "A quick method to get the certificate pulled and...
-
I found this answer following answer on StackExcahnge and it works perfect. Enjoy! "A quick method to get the certificate pulled and...
-
Well most of us used to use grep in a pipe with other commands like netstat, ss, ps, etc., but grep is a very powerful tool and for instance...