Skip to content

Instantly share code, notes, and snippets.

@sepehr
sepehr / rm_biggies.sh
Last active November 10, 2015 22:38
Shell: Find & remove files bigger than X
# k: Kilobyte, M: Megabyte, G: Gigabyte
# +: Bigger than, -: Lower than
find . -maxdepth 1 -type f -size +500k -exec rm -f {} \;
# Or better:
find . -maxdepth 1 -type f -size +50M -delete
# Let's have a look first:
find . -maxdepth 1 -type f -size +2G -exec ls -lhS {} \; | awk {print $5 "\t" $9}
@sepehr
sepehr / duplicate_lines_count.sh
Last active November 10, 2015 22:45
Shell: Analyze huge files for repeating text portions
# Sorts the file by duplicate line count
sort /path/to/filename | uniq -c | sort -nr > ./_aggregated.tmp
# Just read the head as it's probably a huge file
head -n 1000 ./_aggregated.tmp | less
@sepehr
sepehr / mongodb_subdoc_query.js
Last active November 18, 2015 15:35
MongoDB: Remove an array from an embedded document
//
// Find documents with sub-document query:
//
db.collection_name.find({
relays: {
$elemMatch: {
timestamp: {$gte: 1447628400},
status: "RELAY_STATUS_ERROR_SUBMIT",
app_id: ObjectId("537cb1b5fc20a0eb47000000")
}
@sepehr
sepehr / desc
Last active September 7, 2017 11:59
Shell: Man a single option
#!/bin/bash
# Print information about a single option or command
# http://svn.mikelward.com/svn/scripts/desc
# Example Usage:
# opt bash continue
# opt rsync -v
scriptname=desc
@sepehr
sepehr / tsv2csv.py
Last active February 4, 2016 16:48
Python: Bulk convert .tsv to .csv
#!/usr/bin/python
import glob
import csv
import sys
import os
# Check args
if len(sys.argv) < 2:
sys.exit('Usage: tsv2csv.py /path/to/dir')
@sepehr
sepehr / nmap_dragon.txt
Last active November 10, 2015 22:48
Misc: ASCII art in NMAP source
( ) /\ _ (
\ | ( \ ( \.( ) _____
\ \ \ ` ` ) \ ( ___ / _ \
(_` \+ . x ( .\ \/ \____-----------/ (o) \_
- .- \+ ; ( O \____
(__ +- .( -'.- <. \_____________ ` \ /
(_____ ._._: <_ - <- _- _ VVVVVVV VV V\ \/
. /./.+- . .- / +-- - . (--_AAAAAAA__A_/ |
(__ ' /x / x _/ ( \______________//_ \_______
, x / ( ' . / . / \___' \ /
@sepehr
sepehr / accesslog2csv.pl
Created September 22, 2014 08:04
Perl: Convert Apache access log to CSV
#!/usr/bin/perl
#
# @file
# Converter tool, from Apache Common Log file to CSV.
#
# All code is released under the GNU General Public License.
# See COPYRIGHT.txt and LICENSE.txt.
#
@sepehr
sepehr / find_n_exec.sh
Last active November 10, 2015 22:49
Shell: Recursively delete particular files/dirs
find . -type f -name "__MACOSX" -exec rm -rf {} \;
@sepehr
sepehr / cron_times.sh
Last active November 10, 2015 22:50
Shell: /etc/cron.daily tasks run time
# When does cron.daily, cron.hourly, etc. run on a system?
grep run-parts /etc/crontab
@sepehr
sepehr / dos2unix.sh
Last active November 10, 2015 22:51
Shell: Recursively convert line endings to LF
find . -type f ! -regex ".*\/\.svn\/.*" -exec dos2unix {} \;