Twitter http://twitter.com/janosgyerik/
Blog http://janosgyerik.com/blog/
Website http://janosgyerik.com/

0 score

Extract audio only from video files using ffmpeg

 $ ffmpeg -i video.any -vn -acodec libvorbis audio.ogg

April 21, 2019, 10:55 p.m.Janos

0 score

Print the list of your Git commits this month

 $ git log --since='last month' --author="$(git config user.name)" --oneline

Feb. 25, 2019, 6:57 p.m.Janos

0 score

Store the output of find in an array

 $ mapfile -d $'\0' arr < <(find /path/to -print0)

Feb. 18, 2019, 7:48 p.m.Janos

0 score

Check if a text snippet is valid C code

 $ gcc -fsyntax-only -xc - <<< "text snippet"

Feb. 10, 2019, 8:12 a.m.Janos

1 score

Inspect the HTTP headers of a website

 $ curl -I amazon.com

Feb. 8, 2019, 10:56 p.m.Janos

0 score

While loop to pretty print system load (1, 5 & 15 minutes)

 $ while :; do date; awk '{printf "1 minute load: %.2f\n", $1; printf "5 minute load: %.2f\n", $2; printf "15 minute load: %.2f\n", $3}' /proc/loadavg; sleep 3; done

Sept. 5, 2018, 8:41 p.m.Janos

1 score

Scan entire Git repo for dangerous Amazon Web Service IDs

 $ git grep -Ew '[A-Z0-9]{20}'

Sept. 5, 2018, 8:30 p.m.Janos

1 score

Kill a process running on port 8080

 $ lsof -i :8080 | awk 'NR > 1 {print $2}' | xargs --no-run-if-empty kill

Sept. 1, 2017, 8:31 p.m.Janos

0 score

Get the HTTP status code of a URL

 $ curl -Lw '%{http_code}' -s -o /dev/null -I SOME_URL

June 19, 2017, 11:15 p.m.Janos

1 score

List the content of a GitHub repository without cloning it

 $ svn ls https://github.com/user/repo/trunk/some/path

May 21, 2017, 6:01 p.m.Janos

1 score

Download a file from a webserver with telnet

 $ (echo 'GET /'; echo; sleep 1; ) | telnet www.google.com 80

Dec. 22, 2014, 11:31 p.m.Janos

4 score

Change the encoding of all files in a directory and subdirectories

 $ find . -type f  -name '*.java' -exec sh -c 'iconv -f cp1252 -t utf-8 "$1" > converted && mv converted "$1"' -- {} \;

Nov. 20, 2014, 12:15 p.m.Janos

2 score

Generate a sequence of numbers

 $ for ((i=1; i<=10; ++i)); do echo $i; done

Nov. 4, 2014, 12:29 p.m.Janos

0 score

Shuffle lines

 $ ... | perl -MList::Util -e 'print List::Util::shuffle <>'

Oct. 25, 2014, 10:40 p.m.Janos

1 score

Print a flat list of dependencies of a Maven project

 $ mvn dependency:list | sed -ne s/..........// -e /patterntoexclude/d -e s/:compile//p -e s/:runtime//p | sort | uniq

Sept. 22, 2014, 9:02 p.m.Janos

2 score

Find recent logs that contain the string "Exception"

 $ find . -name '*.log' -mtime -2 -exec grep -Hc Exception {} \; | grep -v :0$

July 19, 2014, 7:53 a.m.Janos

3 score

Extract your external IP address using dig

 $ dig +short myip.opendns.com @resolver1.opendns.com

Feb. 25, 2014, 7:50 a.m.Janos

0 score

Check if a file exists and has a size greater than X

 $ [[ $(find /path/to/file -type f -size +51200c 2>/dev/null) ]] && echo true || echo false

Jan. 9, 2014, 12:34 p.m.Janos

0 score

Replace sequences of the same characters with a single character

 $ echo heeeeeeelllo | sed 's/\(.\)\1\+/\1/g'

Dec. 11, 2013, 7:58 p.m.Janos

1 score

Counting the number of commas in CSV format

 $ perl -ne 'print tr/,//, "\n"' < file.csv | sort -u

Dec. 1, 2013, 1:03 p.m.Janos

0 score

Count the lines of each file extension in a list of files

 $ git ls-files | xargs wc -l | awk -F ' +|\\.|/' '{ sumlines[$NF] += $2 } END { for (ext in sumlines) print ext, sumlines[ext] }'

Nov. 9, 2013, 11:49 a.m.Janos

0 score

Add all unknown files in a Subversion checkout

 $ svn add . --force

Sept. 24, 2013, 7:59 a.m.Janos

0 score

Find files that are not executable

 $ find /some/path -type f ! -perm -111 -ls

Sept. 18, 2013, 9:14 p.m.Janos

1 score

Find which log files contain or don't contain a specific error message

 $ for i in *.log; do grep OutOfMemo $i >/dev/null && echo $i oom || echo $i ok; done

Sept. 13, 2013, 3:43 p.m.Janos

1 score

Create a transparent image of given dimensions

 $ convert -size 100x100 xc:none transparency.png

July 31, 2013, 11:32 p.m.Janos

0 score

Create a heap dump of a Java process

 $ jmap -dump:format=b,file=/var/tmp/dump.hprof 1234

July 8, 2013, 8:18 a.m.Janos

1 score

Send a file by email as attachment

 $ uuencode /var/log/messages messages.txt | mailx -s "/var/log/messages on $HOST" me@example.com

May 26, 2013, 9:37 a.m.Janos

0 score

Print file owners and permissions of a directory tree

 $ find /path/to/dir1 -printf "%U %G %m %p\n" > /tmp/dir1.txt

March 19, 2013, 10:51 p.m.Janos

0 score

Get only the latest version of a file from across mutiple directories

 $ find . -name custlist\* | perl -ne '$path = $_; s?.*/??; $name = $_; $map{$name} = $path; ++$c; END { print $map{(sort(keys(%map)))[$c-1]} }'

Feb. 23, 2013, 4:23 p.m.Janos

2 score

Create a thumbnail from the first page of a PDF file

 $ convert -thumbnail x80 file.pdf[0] thumb.png

Feb. 6, 2013, 9:44 p.m.Janos

0 score

Recreate or update an existing zip file and remove files that do not exist anymore

 $ zip --filesync -r /path/to/out.zip /path/to/dir

Jan. 26, 2013, 8:48 p.m.Janos

1 score

Function to extract columns from an input stream

 $ col() { awk '{print $('$(echo $* | sed -e s/-/NF-/g -e 's/ /),$(/g')')}'; }

Dec. 7, 2012, 4:14 p.m.Janos

0 score

Make the output of the `time` builtin easier to parse

 $ TIMEFORMAT=%R

Dec. 4, 2012, 10:43 p.m.Janos

1 score

Remove offending key from known_hosts file with one swift move

 $ vi +18d +wq ~/.ssh/known_hosts

Oct. 30, 2012, 9:28 p.m.Janos

0 score

Remove EXIF data such as orientation from images

 $ mogrify -strip /path/to/image.jpg

Oct. 24, 2012, 12:08 a.m.Janos

0 score

Get the last modification date of a file in any format you want

 $ date -r /etc/motd +%Y%m%d_%H%M%S

Oct. 17, 2012, 4:42 p.m.Janos

0 score

Forget all remembered path locations

 $ hash -r

Oct. 14, 2012, 9:46 a.m.Janos

0 score

Rename files with numeric padding

 $ perl -e 'for (@ARGV) { $o = $_; s/\d+/sprintf("%04d", $&)/e; print qq{mv "$o" "$_"\n}}'

Oct. 6, 2012, 1:38 p.m.Janos

0 score

Copy or create files with specific permissions and ownership

 $ install -b -m 600 /dev/null NEWFILE

Sept. 25, 2012, 2:20 p.m.Janos

1 score

Redirect stdout to a file you don't have write permission on

 $ echo hello | sudo tee -a /path/to/file

Sept. 11, 2012, 9:24 a.m.Janos

1 score

`tail -f` a file until text is seen

 $ tail -f /path/to/file.log | sed '/^Finished: SUCCESS$/ q'

Aug. 22, 2012, 8:29 a.m.Janos

0 score

Run command multiple times with a for loop and a sequence expression

 $ for i in {1..10}; do date; sleep 1; done

Aug. 19, 2012, 9:27 a.m.Janos

0 score

Clear the swap space forcing everything back to main memory in Linux

 $ sudo swapoff -a; sudo swapon -a

Aug. 14, 2012, 11:21 a.m.Janos

0 score

Redirection operator to override the noclobber option

 $ some_command >| output.txt

Aug. 11, 2012, 9:21 a.m.Janos

0 score

How to set the ip address in Solaris 11

 $ ipadm create-addr -T static -a 192.168.1.10/24 eth0/staticaddr

Aug. 3, 2012, 11:44 a.m.Janos

1 score

Use vim to pretty-print code with syntax highlighting

 $ vim +'hardcopy > output.ps' +q style.css 

July 21, 2012, 12:13 a.m.Janos

0 score

Edit the Gimp launcher file to disable the splash screen

 $ sudo sed -i 's/^Exec=[^ ]*/& -s/' /usr/share/applications/gimp.desktop

June 30, 2012, 9:06 p.m.Janos

0 score

`less` is more convenient with the `-F` flag

 $ less -F FILE1

June 25, 2012, 6:47 p.m.Janos

0 score

Append to a file text, a blank line, and the last line of another file

 $ { echo some text; echo; tail -n1 /var/log/apache2/error.log; } >> /path/to/file

June 22, 2012, 5:29 p.m.Janos

-1 score

Run a local shell script on a remote server without copying it there

 $ ssh user@server bash < /path/to/local/script.sh

June 21, 2012, 12:06 a.m.Janos

0 score

Convert a list of terms in slug format to capitalized words

 $ sed -e 's/^./\U&/' -e 's/_./\U&/g' -e 's/_/ /g' /path/to/input

June 17, 2012, 7:54 a.m.Janos

0 score

Execute different commands with find depending on file type

 $ find /path/to/dir -type d -exec chmod 0755 '{}' \; -o -type f -exec chmod 0644 '{}' \;

June 17, 2012, 12:01 a.m.Janos

0 score

Convert m4a files to mp3 using faad and lame

 $ faad -o tmp.wav music.m4a && lame -b 192 tmp.wav music.mp3

June 14, 2012, 9:29 a.m.Janos

0 score

Write both stdout and stderr to the same file

 $ do_something.sh &> out.log

June 5, 2012, 11:34 a.m.Janos

0 score

Create or mount an encrypted directory using encfs

 $ encfs -i 5 $PWD/raw $PWD/content

May 22, 2012, 12:21 a.m.Janos

0 score

Run a never-ending process in the background in a way that you can check on its status anytime

 $ screen -d -m -S some_name ping my_router

May 17, 2012, 11:03 p.m.Janos

0 score

Make a hexdump or do the reverse with the xxd command

 $ xxd /path/to/binary/file

May 16, 2012, 10:22 a.m.Janos

0 score

Really lazy way to print the first instance of $foo that occurs after $bar

 $ ifconfig | grep ^en1 -A5 | grep inet | head -n 1

May 12, 2012, 12:30 p.m.Janos

0 score

Replace symlinks with the actual files they are pointing at

 $ find /path/to/dir -type l -exec sh -c 'cp --remove-destination "$(readlink "{}")" "{}"' \; 

April 24, 2012, 3:29 p.m.Janos

0 score

Expire a user's password immediately

 $ chage -d 0 USERNAME

April 23, 2012, 11:05 p.m.Janos

0 score

Sort du output in Human-readable format

 $ for i in G M K; do du -hsx * | grep "[0-9]$i\b" | sort -nr; done 2>/dev/null

April 14, 2012, 11:06 a.m.Janos

0 score

Convert a decimal number to octal, hexadecimal, binary, or anything

 $ echo 'obase=2;1234' | bc

April 11, 2012, 11:20 p.m.Janos

0 score

Convert from avi format to mp4 encoding

 $ ffmpeg -i file.avi file.mp4

April 11, 2012, 11:10 p.m.Janos

0 score

Format input into multiple columns, like a table, useful or pretty-printing

 $ mount | column -t

April 8, 2012, 4:08 p.m.Janos

0 score

Function to extract columns from an input stream

 $ col() { awk '{print $'$(echo $* | sed -e 's/ /,$/g')'}'; }

April 5, 2012, 11:36 p.m.Janos

0 score

Resize an image proportionally to some specified width or height

 $ mogrify -geometry x31 path/to/image.gif

April 3, 2012, 9:48 p.m.Janos

0 score

Do something in another directory without going there

 $ (cd /path/to/somewhere; tar c .) > somewhere.tar

April 2, 2012, 10:24 p.m.Janos

0 score

Find the target path a symlink is pointing to

 $ readlink a_symbolic_link_to_somewhere

March 31, 2012, 3:23 p.m.Janos

1 score

Remove carriage return '\r' character in many files, without looping and intermediary files

 $ vi +'bufdo set ff=unix' +'bufdo %s/^M$//' +q file1 file2 file3

March 30, 2012, 3:50 p.m.Janos

0 score
1 score

Sort and remove duplicate lines in a file in one step without intermediary files

 $ vi +'%!sort | uniq' +wq file.txt

March 22, 2012, 1:09 p.m.Janos

0 score

List or edit and re-execute commands from the history list

 $ fc -l

March 15, 2012, 12:10 p.m.Janos

0 score

Find the most recently modified files in a directory and all subdirectories

 $ find /path/to/dir -type f -mtime -7 -print0 | xargs -0 ls -lt | head

March 8, 2012, 5:10 p.m.Janos

0 score

List open files

 $ lsof -n

March 2, 2012, 10:01 a.m.Janos

0 score

Set a colorful bash prompt per dev test prod environments

 $ PS1='\[\e[1;31m\][\u@\h \W]\$\[\e[0m\] '

Feb. 25, 2012, 2:46 p.m.Janos

0 score

Print the lines of file2 that are missing in file1

 $ grep -vxFf file1 file2

Feb. 8, 2012, 2:42 p.m.Janos

1 score

Find all the unique 4-letter words in a text

 $ cat ipsum.txt | perl -ne 'print map("$_\n", m/\w+/g);' | tr A-Z a-z | sort | uniq | awk 'length($1) == 4 {print}'

Jan. 29, 2012, 10:28 p.m.Janos

0 score

Concatenate PDF files using GhostScript

 $ gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=output.pdf -dBATCH file1.pdf file2.pdf file3.pdf

Jan. 26, 2012, 8:51 a.m.Janos

0 score

Format text with long lines to text with fixed width

 $ fmt -s -w80 file.txt

Jan. 22, 2012, 10:08 a.m.Janos

0 score

Come back quickly to the current directory after doing some temporary work somewhere else

 $ pushd /some/where/else; work; cd /somewhere; work; cd /another/place; popd

Jan. 15, 2012, 11:12 p.m.Janos

0 score

Export a git project to a directory

 $ git archive master | tar x -C /path/to/dir/to/export

Jan. 12, 2012, 11:04 a.m.Janos

0 score

Delete all tables of a mysql database

 $ mysql --defaults-file=my.cnf -e 'show tables' | while read t; do mysql --defaults-file=my.cnt  -e 'drop table '$t; done

Jan. 8, 2012, 7:53 a.m.Janos

0 score

Calculate the total disk space used by a list of files or directories

 $ du -s file1 dir1 | awk '{sum += $1} END {print sum}'

Dec. 28, 2011, 8:42 p.m.Janos

1 score

Concatenate two or more movie files into one using mencoder

 $ mencoder cd1.avi cd2.avi -o movie.avi -ovc copy -oac copy

Dec. 24, 2011, 3:51 p.m.Janos

1 score

Calculate the average execution time (of short running scripts) with awk

 $ for i in {1..10}; do time some_script.sh; done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum += $1} END {print sum / NR}'

Dec. 21, 2011, 8:50 a.m.Janos

0 score

Check the performance of a script by re-running many times while measuring the running time

 $ for i in {1..10}; do time curl http://localhost:8000 >/dev/null; done 2>&1 | grep real

Dec. 17, 2011, 1:49 a.m.Janos

1 score

A convenient way to re-run the previous command with sudo

 $ sudo !!

Dec. 14, 2011, 11:26 p.m.Janos

0 score

Put an ssh session in the background

 $ ~^z

Dec. 9, 2011, 7:44 p.m.Janos

1 score

Rotate a movie file with mencoder

 $ mencoder video.avi -o rotated-right.avi -oac copy -ovc lavc -vf rotate=1

Dec. 2, 2011, 10:30 p.m.Janos

0 score

Recursively remove all empty sub-directories from a directory tree

 $ find . -type d | tac | xargs rmdir 2>/dev/null

Nov. 29, 2011, 8:01 p.m.Janos

0 score

Remove all the versioned-but-empty directories from a Subversion checkout

 $ find . -name .svn -type d | while read ss; do dir=$(dirname "$ss"); test $(ls -a "$dir" | wc -l) == 3 && echo "svn rm \"$dir\""; done

Nov. 27, 2011, 8:38 a.m.Janos

0 score

Create a sequence of integer numbers

 $ echo {4..-9}

Nov. 24, 2011, 10:07 p.m.Janos

0 score

Redirect the output of the time builtin command

 $ { time command; } > out.out 2> time+err.out

Nov. 20, 2011, 8:34 p.m.Janos

0 score

Copy a directory with a large number of files to another server

 $ tar cp -C /path/to/dir . | ssh server2 'tar x -C /path/to/target'

Nov. 17, 2011, 12:19 p.m.Janos

0 score

Redirect the output of multiple commands

 $ { cmd1 ; cmd2 ; cmd3 ; } > out.out 2> err.out

Nov. 14, 2011, 10:08 a.m.Janos

0 score

View a file with line numbers

 $ grep -n ^ /path/to/file | less

Nov. 9, 2011, 11:05 p.m.Janos

0 score

Print the n-th and m-th line of a file

 $ sed -ne '101 p' -e '106 p' /path/to/the/file

Nov. 6, 2011, 11:20 p.m.Janos

0 score

Repeat the previous command but with a string replacement

 $ ^geomtry^geometry

Nov. 4, 2011, 7:10 a.m.Janos

2 score

Rename all files in the current directory by capitalizing the first letter of every word in the filenames

 $ ls | perl -ne 'chomp; $f=$_; tr/A-Z/a-z/; s/(?<![.'"'"'])\b\w/\u$&/g; print qq{mv "$f" "$_"\n}'

Nov. 1, 2011, 12:51 p.m.Janos

0 score

Do not save command history of current bash session

 $ HISTFILE=

Oct. 29, 2011, 2:41 p.m.Janos

0 score

Use rsync instead of cp to get a progress indicator when copying large files

 $ rsync --progress largefile.gz somewhere/else/

Oct. 19, 2011, 12:48 a.m.Janos

0 score

Create and restore backups using cpio

 $ find . -xdev -print0 | cpio -oa0V | gzip > path_to_save.cpio.gz

Oct. 17, 2011, 11:06 p.m.Janos

0 score

Get the available space on a partition as a single numeric value

 $ df /path/to/dir | sed -ne 2p | awk '{print $4}'

Oct. 2, 2011, 5:41 p.m.Janos

0 score

Schedule a one-time task using "at" command and intuitive date specifications

 $ at now + 30 minutes

Sept. 25, 2011, 11:30 a.m.Janos

2 score

Remove spaces recursively from all subdirectories of a directory

 $ find /path/to/dir -type d | tac | while read LINE; do target=$(dirname "$LINE")/$(basename "$LINE" | tr -d ' '); echo mv "$LINE" "$target"; done

Sept. 20, 2011, 4:52 p.m.Janos

1 score

Replace a regexp pattern in many files at once

 $ vi +'bufdo %s/pattern/replacement/g | update' +q $(grep -rl pattern /path/to/dir)

Sept. 15, 2011, 11:50 p.m.Janos

0 score

Find video files cached by the flash plugin in browsers

 $ file /proc/*/fd/* 2>/dev/null | grep Flash | cut -f1 -d:

Aug. 27, 2011, 1:46 p.m.Janos

0 score

Force the preferred language when downloading a web page with wget

 $ wget -–header='Accept-Language: en-us' http://www.timeanddate.com/calendar/index.html?year=2008&country=26 -O calendar.html

Aug. 21, 2011, 1:40 p.m.Janos

0 score

Burn the contents of a directory to dvd without needing a gui application

 $ growisofs -dvd-compat -Z /dev/scd0 -R -J -pad /path/to/dir

Aug. 14, 2011, 9:35 p.m.Janos

0 score

Convert all flac files in the current directory to mp3 format using "lame"

 $ for i in *.flac; do flac -c -d "$i" | lame -m j -b 192 -s 44.1 - "${i%.flac}.mp3"; done

Aug. 9, 2011, 9:57 p.m.Janos

0 score

Halt the system in Linux without the halt command or gui

 $ echo o > /proc/sysrq-trigger

Aug. 9, 2011, 9:55 p.m.Janos

0 score
0 score

Create an encrypted tar file with openssl

 $ tar c paths_to_files_and_dirs | gzip -c | openssl des3 > encrypted.tar.gz

Aug. 9, 2011, 1:30 a.m.Janos

0 score

Make another user superuser in Ubuntu

 $ for i in $(grep :boss /etc/group | cut -f1 -d:); do adduser wife $i; done

Aug. 5, 2011, 8:57 p.m.Janos

0 score

Change the label of a USB drive in Linux without a gui

 $ sudo mlabel -i /dev/sdd1 ::NewLabel

Aug. 5, 2011, 8:57 p.m.Janos

0 score

Mirror from one Subversion repository to another Subversion repository

 $ bzr co https://repo1/proj1/trunk proj1 && cd proj1 && bzr push https://repo2/vendor/proj1/trunk

Aug. 5, 2011, 8:57 p.m.Janos

2 score

Rename all files in a directory to lowercase names

 $ paste <(ls) <(ls | tr A-Z a-z) | while read OLD NEW; do echo mv -v $OLD $NEW; done

Aug. 5, 2011, 8:57 p.m.Janos

0 score

Find Flash videos stored by browsers on a Mac

 $ find /private/ 2>/dev/null | grep /Flash

Aug. 5, 2011, 8:57 p.m.Janos