Skip to content

Bash

Published:

Note

This file contains miscellaneous useful bash commands without an overarching theme.

# Find all files over a certain size (c = bytes, k = kilobytes, M = megabytes, G = gigabytes)
find . -size +80c
# Combine multiple csv into a single csv file
awk '(NR == 1) || (FNR > 1)' *.csv > combined.csv
# Check how many non hidden files are in a directory
ls . -1 | wc -l
# Compess all files in a directory
tar -czvf results.tar.gz dir/*
# Find and compress all files smaller than 8k
find . -type f -size -8k -print0 | xargs -0 tar -czvf small_mps.tar.gz
# Filter files with a certain number of rows
wc -l job/*.out | sed -E -e '/^ +1 /d' -e '/ *total$/d' -e 's/^ +[0-9]+ +//' | xargs -d '\n' tar -czvf complete_smt2.tar.gz
# Find files that contain a certain pattern and sort them by the time they took to solve
grep -Rnw 'job' -e 'pattern to include' | sed -E -e 's/\.err:1:.*/.out/' | xargs -d '\n' head -q -n 2 | sed 'N;s/\n/ /' | sort -k4 -rn
# Share a folder using the Remote Desktop Protocol (RDP) client rdesktop
# A new disk named "share" will appear on the remote machine (This PC) with the contents of the shared folder
rdesktop -u username -p password -d domain -r disk:share=/path/to/share host
# Download recursively all necessary packages (.deb) for a specific program
# Useful for installing a program on a computer without an internet connection
export $PACKAGES="libgmp-dev"
apt-get download \
$(apt-cache depends --no-recommends --no-suggests --no-conflicts --no-breaks --no-replaces --no-enhances --recurse --no-pre-depends $PACKAGES | grep "^\w")
# Read a csv file skipping the header | sort by column 17 | only print the first column if column 20 is "delta-sat" | remove duplicates
tail -n +2 results.csv | sort -k17 -n -t, | awk -F,  'BEGIN {OFS=","} { if (tolower($20) == "delta-sat")  print $1 }' | awk '!visited[$0]++'