GNU/Linux Commands

Sources & External References…

- http://linux.stoyan.cz/
- http://mindspill.net/computing/linux-notes/
- http://cb.vu/unixtoolbox.xhtml
- http://www.addedbytes.com/cheat-sheets/
- http://www.cheat-sheets.org/
- http://bruxy.regnet.cz/web/programming/CZ/jednopapirove-reference/
- http://www.abclinuxu.cz/serialy/unixove-nastroje
- http://osa.fiit.stuba.sk/os/prehlad_prikazov/
- http://osa.fiit.stuba.sk/os/html/Obsah.html
- http://www.rayninfo.co.uk/vimtips.html
- http://grml.org/zsh/zsh-lovers.html
- http://successtheory.com/tips/zshtips.html

Package management

Desc.Debian/UbuntuArchLinuxGentooRedHatMandriva
update package databaseapt-get updatepacman -Syemerge syncurpmi.update -a
search in package databaseaptitude search keywordpacman -Ss keywordemerge -S keywordurpmq [package_name]
search in installed packages:aptitude search ~ikeywordpacman -Qs keywordyum list [keyword]
upgrade already installed packagesapt-get upgradepacman -Suemerge -uD worldyum updateurpmi –update –auto-select
full update/upgrade comboapt-get update; apt-get dist-upgradepacman -Syuurpmi –auto-select
install local package(s)dpkg -i package.debpacman -U package.pkg.tar.gz
download and install package(s)apt-get install package1 [package2,...]pacman -S package1 [package2,...]emerge -u packageyum install packageurpmi package
remove package(s)apt-get remove package1 [package2,...]pacman -R package1 [package2,...]emerge -C packageyum remove [package]urpme [package_name]
remove and purge package(s)apt-get purge package1 [package2,...]pacman -Rsn package1 [package2,...]
purge previously removed packages (delete user data,configuration,cache)aptitude purge ~c
remove orphan packagesapt-get autoremove $(deborphan –guess-all)pacman -Rsn $(pacman -Qtdq)urpmi_rpm –find-leaves
list files in packagedpkg –listfiles packagepacman -Ql package
lookup file ownerdpkg -S [file]pacman -Qo [file]yum whatprovides [file]urpmf [file]
get source packageapt-get source packagesudo abs; cp -r /var/abs/*/package .
build package from source packagedpkg-buildpackage -rfakeroot -samakepkg

Permissions

Octal digitText equivalentBinary valueMeaning
0---000All types of access are denied
1--x001Execute access is allowed only
2-w-010Write access is allowed only
3-wx011Write and execute access are allowed
4r--100Read access is allowed only
5r-x101Read and execute access are allowed
6rw-110Read and write access are allowed
7rwx111Everything is allowed
Access typeFileFolder
ReadIf the file contents can be readIf the directory listing can be obtained
WriteIf user or process can write to the file (change its contents)If user or process can change directory contents somehow: create new or delete existing files in the directory or rename files.
ExecuteIf the file can be executedIf user or process can access the directory, that is, go to it (make it to be the current working directory)
Octal digitBinary valueMeaning
0000setuid, setgid, sticky bits are cleared
1001sticky bit is set
2010setgid bit is set
3011setgid and sticky bits are set
4100setuid bit is set
5101setuid and sticky bits are set
6110setuid and setgid bits are set
7111setuid, setgid, sticky bits are set
SUIDIf set, then replaces "x" in the owner permissions to "s", if owner has execute permissions, or to "S" otherwise. Examples:
-rws------ both owner execute and SUID are set
-r-S------ SUID is set, but owner execute is not set
SGIDIf set, then replaces "x" in the group permissions to "s", if group has execute permissions, or to "S" otherwise. Examples:
-rwxrws--- both group execute and SGID are set
-rwxr-S--- SGID is set, but group execute is not set
StickyIf set, then replaces "x" in the others permissions to
"t", if others have execute permissions, or to "T" otherwise. Examples:
-rwxrwxrwt both others execute and sticky bit are set
-rwxrwxr-T sticky bit is set, but others execute is not set

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 .

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]*

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

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 640×480 (optional) with 32 second step between two of them.

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

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]

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

Leave a Reply