# commandlinefu.com - questions/comments: danstools00@gmail.com # Create a highly compressed encrypted 7zip file from a directory 7z a -t7z -mhe=on -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on some_directory.7z some_directory/ # Disk usage skipping mount points (even top-level ones) for a in /*; do mountpoint -q -- "$a" || du -shx "$a"; done | sort -h # Sort disk usage from directories du --max-depth=1 -h . | sort -h # Recursive dwdiff using find -exec find DIR -exec sh -c "if [ -f \"{}\" ]; then echo {} >> dwdiff.txt; dwdiff --no-common {} /OLD_FILES/{} >> dwdiff.txt; echo \"--EOF--\" >> dwdiff.txt; fi" \; # Share a file quickly using a python web server cd $mydir && python3 -m http.server 8888 # Check a directory of PNG files for errors ls *.png |parallel --nice 19 --bar --will-cite "pngcheck -q {}" # checks size of directory & delete it if its to small for i in *; do test -d "$i" && ( rclone size "$i" --json -L 2> /dev/null | jq --arg path "$i" 'if .bytes < 57462360 then ( { p: $path , b: .bytes}) else "none" end' | grep -v none | jq -r '.p' | parallel -j3 rclone purge "{}" -v -P ); done # Save a copy of all debian packages in the form in which they are installed and configured on your system for a in $(sudo dpkg --get-selections|cut -f1); do dpkg-repack $a|awk '{if (system("sleep .5 && exit 2") != 2) exit; print}';done # rename / move Uppercase filenames to lowercase filenames current directory FileList=$(ls); for FName in $FileList; do LowerFName=$(echo "$FName" | tr '[:upper:]' '[:lower:]'); echo $FName" rename/move to $LowerFName"; mv $FName $LowerFName; done # Individually 7zip all files in current directory for i in *.*; do 7z a "$i".7z "$i"; done # Moving large number of files find /source/directory -mindepth 1 -maxdepth 1 -name '*' -print0 | xargs -0 mv -t /target/directory; # tree command limit depth for recusive directory list tree -L 2 -u -g -p -d # Find non-ASCII and UTF-8 files in the current directory find . -type f -regex '.*\.\(cpp\|h\)' -exec file {} \; | grep "UTF-8\|extended-ASCII" # Replace lines in files with only spaces/tabs with simple empty line (within current directory - recursive) find . -type f -regex '.*\.\(cpp\|h\)' -exec sed -i 's/^[[:blank:]]\+$//g' {} \; # find hard linked files (duplicate inodes) recursively find . -type f -printf '%10i %p\n' | sort | uniq -w 11 -d -D | less # List all accessed configuration files while executing a program in linux terminal (improved version) strace 2>&1 |egrep -o "\".*\.conf\"" # create an uncompressed tar file of each child directory of the current working directory find . -maxdepth 1 -mindepth 1 -type d -exec tar cvf {}.tar {} \; # Fix time-stamped filenames of JPEG images according to the EXIF date the photo was taken (IFS=': '; for i in *.(#i)jpg; do set $(exiv2 -K 'Exif.Image.DateTime' -Pv $i 2> /dev/null); mv -v $i "$1-$2-$3${i#[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]}"; done) # Powershell one-line script to remove the bracketed date from filenames Get-ChildItem -Recurse | Where-Object { $_.Name -match " ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)" } | Rename-Item -NewName { $_.Name -replace " ?\(\d\d\d\d_\d\d_\d\d \d\d_\d\d_\d\d UTC\)", ""} # List only empty directories and delete safely (=ask for each) find . -type d -empty -exec rm -i -R {} \; # Find non-standard files in mysql data directory find . -type f -not -name "*.frm" -not -name "*.MYI" -not -name "*.MYD" -not -name "*.TRG" -not -name "*.TRN" -not -name "db.opt" # Rename all files in a directory to the md5 hash for i in *; do sum=$(md5sum $i); mv -- "$i" "${sum%% *}"; done # Graphical tree of sub-directories with files find . -print | sed -e 's;[^/]*/;|-- ;g;s;-- |; |;g' # Pull multiple repositories in child folders (a.k.a. I'm back from leave script) [Windows] gci -Directory | foreach {Push-Location $_.Name; git fetch --all; git checkout master; git pull; Pop-Location} # Initialise git in working directory with latest Visual Studio .gitignore [Windows] git init; (Invoke-WebRequest https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore -UseBasicParsing).Content | Out-File -FilePath .gitignore -Encoding utf8; git add -A