Skip to content

Instantly share code, notes, and snippets.

@jrjames83
Last active November 20, 2017 17:50
Show Gist options
  • Save jrjames83/5aa3882c23bb89b5c3b11c91ee5def1f to your computer and use it in GitHub Desktop.
Save jrjames83/5aa3882c23bb89b5c3b11c91ee5def1f to your computer and use it in GitHub Desktop.
Handy Bash / Command Line Commands

Count Files Matching A Certain Pattern

Option 1 - recursive

ls -1f | grep wav | wc -l

Option 2 - only current dir

find . -maxdepth 1 -name "*wav" | wc -l

Rename A File

mv worker.sh mp3_worker.sh

Count Lines in a File

wc -l results.txt 

Remove Duplicate Lines from A File

sort -u results.txt 

Copy Files from Remote Server to Local Machine (ec2)

scp -i "your_ec2_key.pem" -r [email protected]:/home/ec2-user/files ~/Desktop/your_dir/

Loop Over Files and Execute Command Writing Output to Text File (example uses aubio.org music software)

for f in *.mp3
do
	var=$(aubio tempo $f)
        echo $var ", $f"
        echo $var ", $f" >> results.txt
done

Create a Copy of A file

cp mp3_worker.sh wav_worker.sh

Combine Multiple Text Files

  • (note >> means append, > will overwrite existing in all_results.txt)
cat results.txt wav_results.txt >> all_results.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment