commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.
Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):
Subscribe to the feed for:
You need to apt-get install python-sqlparse. This command simply formats a sql query and prints it out. It is very useful when you want to move a sql query from commandline to a shell script. Everything is done locally, so you don't need to worry about copying sql query to external websites.
hexdump could be used for conversion too!
echo defaults to include a newline character at the end of the string, which messes with the hash. If you suppress it with -n then it has the same effect as PHP's ?echo md5("string"), "\t-";? Even more, by using cut you get the exact same output, so it works as a drop-in replacement for the original command for this thread.
Useful to add a timestamp to every line printed to stdout.
You can use `-Ins` instead of `-Iseconds` if you want more precision.
Edit YYYY and MM at the beginning of the command with the year and month you want.
Note that `DD=$(printf "%02d" $d)` will pad single digit integers with a leading zero.
Substitute `echo $YYYY$MM$DD` at the end of the line with the command you want to launch, for instance
script.pl --yyyymmdd $YYYY$MM$DD
this command will add the following two lines into the ~/.bash_aliases:
alias exit='pwd > ~/.lastdir;exit'
[ -n "$(cat .lastdir 2>/dev/null)" ] && cd "$(cat .lastdir)"
or redirect it to the ~/.bashrc if you like
Donno, I find it usefull. You may also define an alias for 'cd ~' like - alias cdh='cd ~'
Pings all the hosts on 192.168.1.0/24 in parallel, so it is very fast. Alive host IP addresses are echoed to stdout as pings are responded to.
client$ while true; do read -n30 ui; echo $ui |openssl enc -aes-256-ctr -a -k PaSSw ; done | nc localhost 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-ctr -k PaSSw`; echo -e "Incoming: $decoded_so"; done
This will establish a simple encrypted chat with AES-256-CTR using netcat and openssl only.
More info here https://nixaid.com/encrypted-chat-with-netcat/
Use find's internal stat to get the file size then let the shell add up the numbers.
Repair each node in sequence. Make sure you change the IP replacements to match your environment
Pass the files path to finfo(), can be unix path, dos path, relative or absolute. The file is converted into an absolute nix path, then checked to see if it is in-fact a regular/existing file. Then converted into an absolute windows path and sent to "wmic". Then magic, you have windows file details right in the terminal. Uses: cygwin, cygpath, sed, and awk. Needs Windows WMI "wmic.exe" to be operational. The output is corrected for easy...
finfo "/cygdrive/c/Program Files/notepad.exe"
Generates a bash array and uses it to select a random image from ~/wallpapers.
Old drive with lots of music or unsorted drive? This command will play all mp3 files in a folder and after playing one song or pressing q, it will ask you if you want to delete the file.
This lists the number of ogg/mp3/wav/flac files in each subdirectory of the current directory. The output can be sorted by piping it into "sort -n".
Prepend text to a file. It doen't need temporary files, ed or sed.
Creates a temporary ram partition
to make a 3gb partition (Defaults to 1gb)
If you want to test output, run it like this:
for fn in *.epub; do echo mv \"$fn\" \"`echo "$fn" | sed -E 's/\.*\/*(.*)( - )(.*)(\.[^\.]+)$/\3\2\1\4/' | sed -E 's/(.*) ([^ ]+)( - )(.*)/\2, \1\3\4/' `\";done > rename.txt
Change the "run_command" to whatever command you want, and remove the "echo" to run it once you are happy.
This will display --> Hello World