Skip to content

Instantly share code, notes, and snippets.

@AaronPhalen
Last active September 27, 2015 14:35
Show Gist options
  • Save AaronPhalen/60d2fa06824fff8b0af0 to your computer and use it in GitHub Desktop.
Save AaronPhalen/60d2fa06824fff8b0af0 to your computer and use it in GitHub Desktop.
Author: Aaron Phalen | Twitter: @aaron_phalen | email: [email protected]
Basic Linux Shell Commands (Ubuntu 12.04)
==========================================
1. grep command
---------------
The grep commands allows for search functionality when working with
output strings, files, or directories.
Examples:
1. grep "word" file --> Search for all match permutations of word within file.
2. grep -w "word" file --> Search for exact match of word within file.
3. grep -r "word" directory --> Search directory recursively for any match of word within file.
4. grep -i "word" file --> Search case insensitive for all match of word in file.
5. grep -c "word" file --> Count the number of time the search word was found in file.
6. grep -n "word" file --> Return line number before output data for found search in file.
7. egrep "word1|word2" file --> Search for multiple (word1, word2) in file.
Note: It is often useful to use the grep commands when combined with the UNIX
pipe commands (|) to chain toghether commands.
Examples:
(i) cat file | grep -w word --> search for exact word in display contents of a file.
(ii) ps -ax | grep -i mysql --> search for mysql case insensitive in display process list.
2. ps command:
--------------
The ps commands shows processes running on the linux system. Process may be daemon or not.
Examples:
1. ps --> display processes runinng in shell
2. ps -e --> display processes running as daemon
3. ps -f --> display proccesses with full options
4. ps -l --> list more information on processes
5. ps -ef --> display all processes and daemon on all ttys
6. ps -a --> display all processes that run on terminal
7. ps -x --> display all processes that do not run on terminal'
8. ps aux --> display everything
ps -f
UID PID PPID C STIME TTY TIME CMD
user id process id parent process id cpu usage process start time terminal command time command
ps -e
PID TTY STAT TIME COMMANDS
process id terminal process time commands
Note: When running the process command for showing daemons, these are not necessarily daemons
started by the user. Many daemons are started automatically: nginx, mysql, apache, etc..
3. cut commands
The cut command is used to select text from display output
Example:
1. cat <filename> --> display file contents
2. cut -c2 <filename> --> cut 2nd character of each line of file (index starts at 1)
3. cut -c1-3 <filename> --> cut characters 1-3 from file
4. cut -c3- <filename> --> cut characters 3 to end of line in file
5. cut -c-8 <filename> --> cut characters 1-8 from each line in file
6. cut -c- <filename> --> cut each line for file
7. cut -d":" -f1 /etc/psswd --> cut first group from each line in password config delimited by :
8. grep "bin/bash" /etc/psswd | cut -d":" -f1,6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment