Category Archives: Advanced

Nuix 101: Replace an Encrypted Zip

This video will show you how to replace an encrypted zip file in your Nuix Case.

To see more Nuix how to videos visit their Youtube playlist here: https://www.youtube.com/playlist?list=PL63768553A2B1803F

Advertisements

#CommandLineFu: 8 Deadly Commands You Should Never Run on Linux

Being a command line junky, I thought I’d share this fun little article I found the other day from @chrisbhoffman – 8 Deadly Commands You Should Never Run on Linux.

rm -rf / – Deletes Everything!

:(){ :|: & };: – Fork Bomb

mkfs.ext4 /dev/sda1 – Formats a Hard Drive

command > /dev/sda – Writes Directly to a Hard Drive

dd if=/dev/random of=/dev/sda – Writes Junk Onto a Hard Drive

mv ~ /dev/null – Moves Your Home Directory to a Black Hole

wget http://example.com/something -O – | sh – Downloads and Runs a Script

Chris Hoffman is a technology writer and all-around computer geek. He’s as at home using the Linux terminal as he is digging into the Windows registry. Connect with him on Google+.

CommandLineFu: File/Byte Count of Folder List

 while read -r dir; do echo -n `du -hsb "$dir"` ; echo "|"`find "$dir" -type f | wc -l` ; done < UD_input.txt | tee UserData.log

 

Uses text file with one directory per line as input and prints:

BYTES [space] DIRECTORY NAME [pipe] FILE COUNT

1842531456 ./FD99_UserShare/z/Bond/|213

CommandLineFu: FileType Report w/ Dates

More find magic — this little beast takes a while to run on large directories but is worth it’s weight in gold.  Now I just need a way to convert Epoch time to YYYYMMDD format inline. (New project)

find ./foo/ -type f -printf '%f|%h|%s|%AY%Am%Ad|%TY%Tm%Td|' -exec stat --printf "%W|" '{}' \; -exec file -bp '{}' \; > bar.log

%f == file name without leading directories

%h == leading directories without file name

%s == size in bytes

%A = Last access time (Y,m,D = YYYYMMDD format)

%T == Modification time (Y,m,D = YYYYMMDD format)

(using printf keeps everything on the same line)

stat %W == file birth date in Epoch time

file -bp == checks file type, b==brief, p==preserve date

CommandLineFu: FOR LOOP – report file count in pwd/* && print disk usage

#!/bin/bash
for i in */ ;
    do
        echo -n "$i:" >> "/path/to/some/file/already/created.txt" ;
        find "$i" -type f | wc -l >> "/path/to/same/file/already/created.txt" ;
        du -hs "$i" ;
    done
exit 0

Quick and dirty…
Actually this is quite slow when dealing with directories containing thousands of little files.
But it gets the job done.  I’ll play around with it and see if forking helps.

CommandLineFu: Read list of filenames – test if they exist

while read -r file; do if [[ ! -e $file ]]; then echo "$file|error" ; fi ; done < input.txt

I’ll usually pipe the output to tee so I can watch what’s going on:

while read -r file; do if [[ ! -e $file ]]; then echo "$file|error" ; fi ; done < input.txt | tee error_report.txt

CommandLineFu: Split a Text file based on line numbers

Assumptions: I have a text file that contains 25+ Million lines, I want to split them into 100,000 line text files.

#!/bin/bash
x=1
y=100000
z=1
while [ $z -le 26 ]
do
    sed -n "$x,${y}p;${y}q;" tbl_001.txt > "t$z.txt"
    x=$(( $x + 100000 ))
    y=$(( $y + 100000 ))
    z=$(( $z + 1 ))
done

If you want to split by a different amount change the “y” variable, and the + whatever number to the number of lines you want.

The “z” variable is used as the filename, and the cutoff point.  If my original file only had one million lines I would change the “while” condition to 10 instead of 26.

I’m sure there’s a way to have the machine do the math for me.  But I don’t have the patience to hunt down how to do this right now.  I imagine it would have something to do with storing the line count (wc -l) in a variable, prompting the end user for the max line count (read $maxcount), and looping until the file is completely done.  (Not sure how to do this last part).  A project for another day.