🐧
Linux
  • Introduction
  • 🖇️general
    • essentials
    • other commands
    • Superuser-do (sudo)
    • SUID, SGID, sticky bit
    • /dev/null
    • environment variables
    • special variables
    • shebang
  • spool
  • 🔧bash
    • overview
    • redirection
    • loop
    • .bashrc
  • text processing
    • grep
    • sed
    • awk
  • xxd/hexdump
  • text editors
    • nano
    • vi/vim
  • 📂filesystem & directories
    • Filesystem Hierachy Standard (FHS)
      • /etc
        • hosts, hosts.allow, hosts.deny
        • /cron.d
        • /httpd
        • /samba.d
        • hostname
        • crontab
        • shadow
        • passwd
        • profile
        • services
      • /dev
      • /proc
        • version
      • /mnt
      • /opt
      • /sbin
      • /lib
      • /usr
      • /tmp
      • /var
      • /bin
      • /run
    • chroot
  • find
  • locate
  • ⌚processes & jobs
    • cronjob
    • daemon
  • ⛓️system
    • systemctl
    • hostname
    • systemd
  • 🗃️media
    • ffmpeg
    • pdftk
  • 🔒Security
    • ufw
  • firejail
  • apparmor
  • 📦Package management
    • dpkg
    • apt/apt-get
  • Storage
    • lsblk
    • mount/umount
  • df/du
  • user management
    • chsh
  • Networking
    • Introduction
    • routing table/interface management
    • /etc/hosts, /etc/hosts.allow, /etc/hosts.deny
Powered by GitBook
On this page
  • Looking for text from an output
  • Search for word within a file
  • Look for files in the current directory with a certain word
  1. text processing

grep

Looking for text from an output

$ echo -e 'hello friend, my name \n is jarrett!'
hello friend, my name 
 is jarrett!

$ echo -e 'hello friend, my name \n is jarrett!' | grep 'name'
hello friend, my name 

Search for word within a file

$ grep [word_search] [file_name]

# eg. Both lines below are equivalent, but using grep only without cat is more efficient
$ grep 'test' file.txt 
$ cat file.txt | grep 'test'

Look for files in the current directory with a certain word

$ grep -irl [word_search]

# Exclude directory, and suppress errors
$ grep -irl --exclude-dir=[dir_to_exclude] [word_search] 2>/dev/null

Flags

a) -i: Case-insensitive search

b) -r: Perform a recursive search on the directory

c) -l: Suppress normal output - only print the name of each file for which the output would have been printed from

Previous.bashrcNextsed

Last updated 5 months ago