From c0a51a2d0fca1486738803cfde6d2ab543f7348d Mon Sep 17 00:00:00 2001 From: ImmortalPC Date: Fri, 7 Mar 2014 14:52:50 +0100 Subject: [PATCH 1/2] [PS,GREP] Exclude grep from your grepped output of ps. --- cheatsheets/grep | 4 ++++ cheatsheets/ps | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cheatsheets/grep b/cheatsheets/grep index 3a01723..fced336 100644 --- a/cheatsheets/grep +++ b/cheatsheets/grep @@ -20,3 +20,7 @@ grep -E "[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" file #Find IP add # Find all files who contain {pattern} in the directory {directory}. # This will show: "file:line my research" grep -rnw 'directory' -e "pattern" + +# Exclude grep from your grepped output of ps. +# Add [] to the first letter. Ex: sshd -> [s]shd +ps aux | grep '[h]ttpd' diff --git a/cheatsheets/ps b/cheatsheets/ps index 3710a90..75d6155 100644 --- a/cheatsheets/ps +++ b/cheatsheets/ps @@ -9,3 +9,7 @@ ps -aufoouser # To list every process with a user-defined format: ps -eo pid,user,command + +# Exclude grep from your grepped output of ps. +# Add [] to the first letter. Ex: sshd -> [s]shd +ps aux | grep '[h]ttpd' From b2e5f6d2cf27472ab663b7587f79801b99e78849 Mon Sep 17 00:00:00 2001 From: ImmortalPC Date: Mon, 10 Mar 2014 21:47:19 +0100 Subject: [PATCH 2/2] [XARGS] Add xargs example --- cheatsheets/xargs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 cheatsheets/xargs diff --git a/cheatsheets/xargs b/cheatsheets/xargs new file mode 100644 index 0000000..44bf20a --- /dev/null +++ b/cheatsheets/xargs @@ -0,0 +1,12 @@ +# find all file name ending with .pdf and remove them +find -name *.pdf | xargs rm -rf + +# if file name contains spaces you should use this instead +find -name *.pdf | xargs -I{} rm -rf '{}' + +# Will show every .pdf like: +# &toto.pdf= +# &titi.pdf= +# -n1 => One file by one file. ( -n2 => 2 files by 2 files ) + +find -name *.pdf | xargs -I{} -n1 echo '&{}='