Random unix commands

Random unix commands

Random commands I’ve collected over the years.

vim

delete the character in column ten in all rows:

:%!colrm 10 10

Shell

Recursively chmod only directories

find . -type d -exec chmod 755 {};

Recursively chmod only files

find . -type f -exec chmod 644 {};

Recursively chmod only python files

find . -type f -name '*.py' -exec chmod 644 {};

Recursively set the execute bit on every directory

chmod -R a+X *

(+x limits execute bit to directories)

tar only files in current directory

ls -l | grep '^[^d]' | awk '{print $9}' | xargs tar cvf foo.tar

Open remote folder locally over SSH:

/usr/local/bin/sshfs user@host:/remote-dir-path "local-dir-name" -o volname="local-volume-name" -o noappledouble

Info

Information on kernel:

  • uname -a
  • uname -r for exact version

Information on OS:

  • lsb_release -a
  • lsb_release -r for exact version

All partition information

sudo fdisk -l

sudo netstat -tulpn

Audio

Get lengths of all audio files in folder

for file in *.wav;do ffprobe -v error -select\_streams a:0 -show_entries stream=duration -of default=noprint\_wrappers=1:nokey=1 "$file";done >> length.txt

Sum values in file

awk '{ sum += $1 } END { print sum }' length.txt

Segment every mp3 sample in the current dir into 3 second wav files:

find . -name '*.mp3' -type f -exec sh -c 'ffmpeg -i "${0%.*}.mp3" -f segment -segment_time 120 -c copy "wav${0%.*}_%03d.wav"' {};

Extract subtitles

for i in *.mkv; do ffmpeg -i "$i" "${i%.mkv}.srt"; done

Convert all ogg files in all subdirs

for d in ./*/ ; do (cd "$d" && for i in *.ogg; do ffmpeg -i "$i" -ar 16000 -ac 1 "${i%.ogg}.wav"; done); done