November 18

Linux: Using grep

Word count
grep -o ‘word’ filename | wc -l

One liner to find a running process and kill it
kill $(ps aux |grep -i ‘[/]usr/bin/puppet’ | awk ‘{print $2}’)

Find duplicate words in a file
grep -wo ‘[[:alnum:][:punct:]]+’ filename.txt | sort | uniq -cd

  • You may need to vary the “bracket expressions”, to fit the characters you are tryin go match.
    The above worked well when looking to find more than one server that is using the FQDN.

Search filesystem for a word:
find / -xdev -type f -print0 | xargs -0 grep -H “wordtosearchfor”

Category: Linux | Comments Off on Linux: Using grep
November 18

Linux: Basic User administration

Basic User administation

Delete a user:
userdel username
Be sure to delete the home folder if it is no longer in use

Add a user:
useradd username

Add user to specific gid and uid:
groupadd -g 2501 username ; useradd username -u 501 -g 2501 -m -s /bin/bash

Add a group:
groupadd groupname

Add a user to a group:
usermod -a -G groupname username

Change the default group for a user
usermod -g groupname username

If adding to administrator/wheel:
Use: visudo

Remove the # in front of “# %wheel ALL=(ALL) ALL”
Allows people in group wheel to run all commands

Add user to the wheel group:
usermod -aG wheel username

Change or add a users full name. Also called the finger name:
chfn -f “Joe Blow” jblow
usermod -c “Snow John” username

Category: Linux | Comments Off on Linux: Basic User administration