Commands by keyboardsage (5)

  • The 30 means start extracting frames from 30 seconds into the video. The 3 means extract the next 3 seconds from that point. The fps can be adjusted based on your preferences. The 320 is the width of the gif, the height will be calculated automatically. input.mp4 is the video file, which can be any video file ffmpeg supports. The output.gif is the gif created.


    0
    ffmpeg -ss 30 -t 3 -i input.mp4 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" -loop 0 output.gif
    keyboardsage · 2024-03-19 00:34:23 47
  • This begins recursively looking at dot files starting from "./path_to_dir". Then it prints out the names of those files. If you are satisfied with the list of files discovered then you can delete them like so `find ./path_to_dir -type f -name '.*' -exec rm '{}' \;` which executes the removal program against each of those names previously printed. This is useful when you want to remove thumbnail files on Mac OSX/Windows or simply want to reset an app's configuration on Linux.


    -1
    find ./path_to_dir -type f -name '.*'
    keyboardsage · 2024-03-16 23:47:01 74
  • Create a 7zip archive named "some_directory.7z" and adds to it the directory "some_directory". The `-mhe=on` is for header encryption, basically it mangles the file names so no one knows whats inside the 7z. If -mhe=on wasn't included, then a person without the password would still be able to view the file names inside the 7z. Having this option ensures confidentiality. To ensure the result is small use lzma2, level 9 compression. Lzma2 fast bytes range from 5 to 272, the higher the number the more aggressive it is at finding repetitive bytes that can be added to the dictionary. Here the fast bytes are set to 64 bytes and the dictionary is 32 MB. Depending on your purposes (the directory size and desired file size), you can be more aggressive with these values. Lastly, `-ms=on` just says concatenate all the individual files and treat them as a singular file when compressing. This leads to a higher compression ratio generally.


    0
    7z a -t7z -mhe=on -m0=lzma2 -mx=9 -mfb=64 -md=32m -ms=on some_directory.7z some_directory/
    keyboardsage · 2024-03-16 23:36:38 16
  • Extracts the binary from the .text section and escapes it. This puts it in a form ready to use in a program. Show Sample Output


    0
    objdump -d -j .text ExeHere | grep -e '^ ' | tr '[[:space:]]' '\n' | egrep '^[[:alnum:]]{2}$' | xargs | sed 's/ /\\x/g' | sed -e 's/^/\\x/g'
    keyboardsage · 2016-09-11 07:15:00 16
  • When you want to know the duration of all your mp3 files in the current working directory this command will tell you based on exif data. Since it relies on exif data it can be used against other files like movies, ogg vorbis etc. also. Useful when you want to know how long it will take to listen to an album or series of lectures. Show Sample Output


    0
    exiftool * | grep '^Duration' | sed 's/^.*[[:space:]]\([0-9]*:[0-9]*:[0-9]*\).*$/\1/g' | awk -F':' '{ H+=$1;M+=$2;S+=$3 } END { printf "%d:%d:%d\n", int(H+int(M/60)),int(M+S/60)%60,S%60 }'
    keyboardsage · 2015-06-17 06:20:47 9

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

Blackhole any level zones via dnsmasq
Explanation It creates dnsmasq-com-blackhole.conf file with one line to route all domains of com zones to 0.0.0.0 You might use "address=/home.lab/127.0.0.1" to point allpossiblesubdomains.home.lab to your localhost or some other IP in a cloud.

shuffle lines via perl
Same, without modules... Probably smarter option: just use the shuf command or even sort -R.

Function to check whether a regular file ends with a newline
tail -c 1 "$1" returns the last byte in the file. Command substitution deletes any trailing newlines, so if the file ended in a newline $(tail -c 1 "$1") is now empty, and the -z test succeeds. However, $a will also be empty for an empty file, so we add -s "$1" to check that the file has a size greater than zero. Finally, -f "$1" checks that the file is a regular file -- not a directory or a socket, etc.

Delete all but the latest 5 files, ignoring directories

scping files with streamlines compression (tar gzip)
it compresses the files and folders to stdout, secure copies it to the server's stdin and runs tar there to extract the input and output to whatever destination using -C. if you emit "-C /destination", it will extract it to the home folder of the user, much like `scp file user@server:`. the "v" in the tar command can be removed for no verbosity.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

pipe output to notify-send
Route output to notify-send to show nice messages on the desktop, e.g. title and interpreter of the current radio stream

Change host name
With sed you can replace strings on the fly.

The scene in the Shining (Stanley Kubrick)
Let's take a rest. How about watch a horror? The Shining http://en.wikipedia.org/wiki/The_Shining_(film)

Get the number of days in a given month and year


Stay in the loop…

Follow the Tweets.

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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

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: