Skip to content

Instantly share code, notes, and snippets.

@p3t3r67x0
Last active June 17, 2018 06:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save p3t3r67x0/ac613888e60095d1a0ecdd95d06faac5 to your computer and use it in GitHub Desktop.
Save p3t3r67x0/ac613888e60095d1a0ecdd95d06faac5 to your computer and use it in GitHub Desktop.
Some useful vim and bash commands that I only use occasionally

vim

Remove ^M

:%s/\r//g

Remove unwanted whitespaces

:%s/\s\+$//

Aligning text (using Tabular.vim)

:%sTab /,\zs

Replace tabs with spaces

:retab

bash

Determine target architecture of binary file

for i in $(ls); do objdump -x $i | grep 'Architektur:' | cut -d ' ' -f 2 | cut -d ',' -f 1; done

Unzip all files in this folder

for i in $(ls); do data=$(file --mime-type $i | cut -d ' ' -f 2); if [[ $data == 'application/zip' ]] then; unzip $i; fi; done

Retrieve all false positive hash values from Virustotal API report

for i in $( grep -n ' 0/' <file> | cut -f 1 | sed 's/://' ); do head -n $( echo $i + 2 | bc) <file> | tail -n 1 | awk '{ print $5 }'; done >> ../false_positives.txt

Find all files in sub directories from current location and move them there

find . -mindepth 2 -type f -print -exec mv {} . \;

Recursively change permissions of files

sudo find <path> -type f -print0 | xargs -0 sudo chmod 644 -
sudo find <path> -type d -print0 | xargs -0 sudo chmod 755 - 

Find specific files in same directory and remove them

find . -size 0 -print0 | xargs -0 rm
find . -size +30M -print0 | xargs -0 rm

Iterate over a list of filenames and remove them

for i in $(cat ../false_positives.txt); do if [[ -e $i ]]; then rm -v $i; fi; done

Delete all directories in current location

rm -R -v -- */

Kill apache2 process

kill -9 $(ps -e | grep apache2 | awk '{print $1}')

Count history commands and return them

history | cut -c8- | sort | uniq -c | sort -rn | head

Exclude files from search by file type

grep -rn <search> --exclude=\*.{log,swp} <folder>

To determine the path that your system has assigned to the new hard drive

sudo lshw -C disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment