SPOJE.NET

Technická dokumentace

Uživatelské nástroje

Nástroje pro tento web


Postranní lišta


Provozují SPOJE.NET.
Nejlepší internet v Praze.

howto:linux:useful_commands

Useful Commands

On this page i am gathering useful GNU/Linux commands that i came across during my work…

Sources & External References…

Commands

Tuhle stránku prosím nepřekládat do češtiny!

FIXME prepsat z http://blog.harvie.cz/useful-gnulinux-commands/

Audio

Convert WAV to MP3

lame --preset standard in.wav out.mp3

use "--preset help" for overview on different quality settings…

Batch Re-encode MP3s to Lower Bitrate

I had few audiobooks with stupidly big bitrate and without using VBR, so i made them smaller using this command (launch it in directory with your mp3s):

QUALITY=voice; mkdir "lame-$QUALITY"; ls -1 *.mp3 | while read i; do lame --preset "$QUALITY" "$i" "lame-$QUALITY/$i"; done;

Note that all ID3 tags will be lost (i preffer good filenames anyway), original files will be preserved… Maybe you need to recode music instead of spoken word, sou you can change QUALITY variable at begining of command. To get list of possible values, check output of lame --preset help.

Extract Audio from mp3 or Video File

export to wav

ffmpeg -i input.mp4 out.wav

export to 128kb/s mp3

ffmpeg -i input.mp4 -ab 128k out.mp3

Video

Join Multiple Video Files (Same Encodings)

So far, I have tried this command successfully with wmv and mpg files. To join several video files [part1], [part2], etc into a file called [whole], run the following command:

mencoder -oac copy -ovc copy -o [whole] [part1] [part2] ... [partn]

If the parts are listed in the correct order when you run ls -l [part]*, you don't have to list all parts when you call mencoder:

mencoder -oac copy -ovc copy -o [whole] [part]*

Capture (Record) MMS Stream

mencoder 'mms://host/path/video.wmv' -oac copy -ovc copy -o video.wmv

(HTTP streams can be captured using wget or curl - like regular downloading. press ^C (in another words ctrl+c) to stop recording).

Join Multiple Video Files (Different Encodings) To Single XVID

Similar as for same encodings (takes longer time) You should adjust bitrate in the xvidencopts…

mencoder -oac copy -ovc xvid -xvidencopts bitrate=800 -o [whole] [part]*

Convert Video to 3GP

This one's suitable for older Nokia cellphones (you can decrease sound quality using -ar 8000):

ffmpeg -i video.avi -f 3gp -vcodec h263 -b 100000 -s qcif -r 12 -acodec libfaac -ar 16000 -ab 16 -ac 1 outputfile.3gp

HardCode Subtitles Directly to Video

This can be usefull before converting videos to 3gp or mp4 for cellphones or pocket devices without subtitle support.

mencoder input.flv -subcp cp1250 -sub subtitles.srt -o output.flv -oac lavc -ovc lavc -lavcopts abitrate=128 vbitrate=1200

you can try "-oac copy" for speedup (didn't worked for me) or manipulate the bitrates. those options can be also usefull for manipulating appearance of subtitles: -subfont-text-scale -subpos -spualign -font -slang (see man mencoder for more…)

Repair Index in Video Files

Rebuild the idx without re-encoding

mencoder [file.avi] -forceidx -oac copy -ovc copy -o [fixedfile.avi]

You can also remove currupted idx by -noidx option (most players will generate index by self - mplayer with -idx option)

mencoder [file.avi] -noidx -oac copy -ovc copy -o [fixedfile.avi]

Convert Between Subtitle Formats or Change Subtitle Timing

echo q | mplayer /dev/zero -rawvideo pal:fps=1 -demuxer rawvideo -vc null -vo null -noframedrop -benchmark -sub input_subtitles.sub -dumpsrtsub

See man mplayer for filename of generated subtites (it's dumpsub.srt for srt format). Beside of -dumpsrtsub you can also use those formats: -dumpjacosub -dumpmicrodvdsub -dumpmpsub -dumpsami (check man mplayer for more). You can also change timing of subtitles by adding -subdelay [[-]seconds] option.

Extract thumbnails from video file

mplayer input.avi -ao null -vo jpeg -sstep 32 -frames 23 -vf scale=640:480

Makes 23 thumbnails scaled to 640x480 (optional) with 32 second step between two of them.

Stabilize shaky video using vid.stab

ffmpeg -i SHAKY_INPUT_VIDEO.mp4 -vf vidstabdetect=stepsize=6:shakiness=8:accuracy=9:result=transform_vectors.trf -f null -
ffmpeg -i SHAKY_INPUT_VIDEO.mp4 -vf vidstabtransform=input=transform_vectors.trf:zoom=1:smoothing=30,unsharp=5:5:0.8:3:3:0.4 -vcodec libx264 -preset slow -tune film -crf 18 -acodec copy SMOOTH_OUTPUT_VIDEO.mp4

Old way, not very effective:

ffmpeg -i input.mov -vf deshake output.mov

Correct video Hue, Saturation and Brightness

ffmpeg -i IN.mp4 -vf hue=h=0:s=2:b=0 OUT.mp4

Capture screencast using ffmpeg

ffmpeg -video_size 1280x800 -framerate 25 -f x11grab -i :0.0+0,0 output.mp4

with sound:

ffmpeg -video_size 1280x800 -framerate 25 -f x11grab -i :0.0+0,0 -f alsa -ac 2 -i default output.mp4

CUPS Printing

Install CUPS and you get the print server cupsd and the print commands lpstat, lpr and lpq, amongst others. I installed CUPS on two Gentoo boxes, following the Gentoo Printing Guide. On one of these machines I run the cupsd server.

To specify the print server on the client machine, edit /etc/cups/client.conf to contain:

ServerName the.print.server

lpstat can be used to get status information. For example, the following command shows the accepting state of printer queues. If no printers are specified then all printers are listed, in my case my HP LazerJet 1100.

localhost # lpstat -a
HPLJ1100 accepting requests since Jan 01 00:00

If you want to check a different server:

lpstat -h the.other.server -a

Print a file:

lpr [filename]

Specify printer, page size and grayscale (i.e. no colour):

lpr -P Epson_stylus_c66 -o PageSize=A4 -o ColorModel=Grayscale [filename]

Misc.

Encrypt File Using GPG

Encrypt. This will add an encrypted file called [filename].gpg.

gpg --cipher-algo AES -c [filename]

Decrypt. This will create the decrypted file called [filename].

gpg -o [filename] -d [filename].gpg

Send Email from Commandline

You can use the mail command. I believe it relies on sendmail by default.

echo -e "message body" | mail -s "message subject" email_address

Firefox + Flashplayer blocking ALSA

Note this is only for Flash Player 9 and lower with installed (lib)flashsupport. If you have problems with running Flash Player 10 on (latest) ALSA make sure that you've uninstalled (lib)flashsupport. IMHO you should still need (lib)flashsupport to run latest Flash on OSS, Arts, PulseAudio and others. You have to use proper flashsupport package compiled against this sound server.

FlashPlayer <= 9 You need to have alsa-oss installed, then you can try this configuration:

cat /etc/firefox/firefoxrc 
FIREFOX_DSP="aoss"

or you can also try:

FIREFOX_DSP=auto

And you can also try to run firefox like this (and/or update your shortcuts):

aoss firefox [args...]

Unix TimeStamp StopWatch

clear; while true; do echo -ne "$(date +%s)r"; sleep 1; done;

You can press enter to save actual time or ^C to stop…

Generating Random Passwords and/or Random Data

head -c 1024 /dev/urandom | md5sum | cut -d ' ' -f 1

if you want lot of random passwords you can use this command:

for i in $(seq 1 5); do head -c 1024 /dev/urandom | md5sum | cut -d ' ' -f 1; done;

(example for generating 5 passwords - you can adjust the second seq argument value)

If you want to get random string of specified lenght containing only specified characters, you can use this command:

cat /dev/urandom | tr -c -d '01' | head -c 100

example will generate 100 zeroes or ones, but you can also specify different characters or one of tr's character classes instead of '01':

  • [:lower:] for lowercase letters
  • [:alpha:] for all letters
  • [:alnum:] for all letters and numbers
  • [:graph:] for all printable characters

Figlet font overview

ls /usr/share/figlet/fonts/*.flf | cut -d . -f 1 | while read i; do echo "$i:"; figlet -f "$i" ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890; done | less
wget --spider -nd -o wget.log -e robots=off -r -p http://example.com
grep -B 2 '404' wget.log | egrep -o 'https?://.*' | sort -u
howto/linux/useful_commands.txt · Poslední úprava: 2017/01/03 21:49 autor: harvie