ANS Documentation

Improve This Doc
  • Cloud
  • Domains and DNS management
  • Backup and High Availability
  • eCommerce Stacks
  • Security
  • Email
  • Monitoring and usage management
  • Networking
  • Operating systems
    • Linux
      • Basics
      • Apache
      • Control Panels
      • FTP
      • Magento
      • Miscellaneous
      • MySQL
      • NGINX
      • PHP
      • PHP-FPM
      • Setting up Websites
      • NFS
      • VPN
      • Percona
      • SSH
      • SSL
      • Git
      • Redis
      • Elasticsearch
      • MongoDB
      • Ncdu
    • VMware ESXi
    • Windows
  • Webcelerator
  • MyUKFast
  • Home >
  • Operating systems >
  • Linux >
  • Miscellaneous >
  • The awk command

The awk command¶

The awk command can be used to search through text files by columns. This can be very useful while investigating access logs on the server. A basic use of the awk command would be to print the first column of each line in the file. If this was to be done on an access log, this would show the IP the request has been sent from which can potentially help investigate attacks on a server or aid general traffic investigation. An example of this command is below.

awk '{print $1}' /var/log/nginx/access.log

This can be used in conjunction with other commands and more complex commands can be created. The below command will search through the NGINX access logs for today’s date and print the IP, the type of request, the page requested and the referrer. This will then sort through the results and order them by amount of unique requests. This will then print the top 20 unique requests from unique IP addresses on the server today and display how many were sent.

grep "`date +%d/%b/%Y`" /var/log/nginx/access.log | awk '{print $1, $6, $7, $11}' | sort | uniq -c | sort -gr | head -n 20

Next Article > Run a virus scan

  • Useful Links
  • SMB
  • Enterprise
  • Channel
  • Public Sector
  • ANS Data Centres
  • About ANS
  • Careers
  • Blog
  • Get in touch
  •  
  • Sales 0800 458 4545
  • Support 0800 230 0032
  • Get in touch

© ANS Group Limited | Terms and Conditions | Corporate Guidance | Sitemap
ANS Group Limited, registered in England and Wales, company registration number 03176761, registered office 1 Archway, Birley Fields, Manchester M15 5QJ