Linuxjedi

From CleanPosts

Jump to: navigation, search

Linux Jedi Mind Tricks

  • Make an image of a CD on your hard drive:

dd if=/dev/sr0 of=image.iso


  • Mount that image on your system to use it:

mount -o loop image.iso /mnt/temp


  • Make a new .iso image in /mnt/burn from the contents in /mnt/hold:

mkisofs -o /mnt/burn/image.iso /mnt/hold


  • Burn that image to another CD:

cdrecord dev=/dev/sr0 /mnt/burn/image.iso


  • Convert RPM package to DEB package:

alien file.rpm


  • Copy a file

cp INFILE OUTFILE


  • Add a CD-ROM to your list of repositories.

apt-cdrom -m add


  • List only non-blank lines in a file:

awk 'NF >0' file.txt


  • Create a custom command to list files:

alias l = 'ls -l --color=auto'


  • Add line numbers to a file:

cat -n file.txt


  • Find text in a file:

awk 'chevy' cars.txt


  • Backup Master Boot Record:

dd if=/dev/sda of=MBR.img bs=446 count=1


  • Make a file lowercase:

cat FILE1.TXT | tr '[A-Z]' '[a-z]' > FILE2.TXT


  • Change the owner of a directory and all its contents:

chown -R teresita DIRECTORY


  • Grab a copy of a website:

wget -w9 -r --random-wait -l3 -np -E URL


  • Display time since boot:

uptime


  • Get the sizes of all subdirectories under a directory

du -sh MYDIR


  • Display unique lines in a sorted file:

uniq <FILE1 >FILE2


  • Use CUPS printer management system:

localhost:631 (in a browser address bar)


  • MP3 to WAV conversion:

madplay --output=wave:OCEANLAB.WAV OCEANLAB.MP3


  • Convert to OGG:

oggenc *


  • Create a link:

ln -s /initrd/mnt/dev_ro2 HOME


  • Extract tarball:

tar -xvf /dev/hda/FILE


  • Make archive:

tar -c DIRECTORY | bzip2 > DIR.TAR.BZ2


  • Make a file executable for all users:

chmod u+x FILE


  • Turn a directory into a SquashFS file:

mksquashfs /tmp/merge PUP_412.SFS


  • Mount your SquashFS file:

mount -o loop -t squashfs PUP_412.SFS /mnt/pup


  • Upload a file to your webspace:

wput MYFILE ftp://username:password@web.host.com


  • Convert a MIDI file to a .WAV file:

timidity -Ow -oRUBY.WAV RUBY.MID


  • Replace spaces in a filename with hyphens:

find . -name "* *mp3" -exec rename 's/\ /-/g' {} \;


  • Print the current month in Julian dates:

cal -j


  • Make a new file of the individual words in another file:

tr ' ' '\012' <INFILE >OUTFILE

or

for WORD in `cat FILE`

do

echo $WORD

done


  • Strip carriage returns from a DOS file:

'tr -d '\015' <INFILE >OUTFILE


  • Downshift all file names:

for F in *

do

mv $F `echo $F | tr '[A-Z]' '[a-z]'

done


  • Rename in bulk:

OLD=xxx

NEW=yyy

for F in $OLD*

do

SUFFIX=`expr $F : '$OLD\(.*\)'`

mv $OLD$SUFFIX $NEW$SUFFIX

done


  • Install from tarball

tar -zxvf ARCHIVE.TAR.GZ

./configure


  • Format floppy disk:

fdformat' /dev/sde


  • List directories:

find . -type d -print


  • Convert avi to mpeg:

mencoder MOVIE.AVI -of mpeg -mpegopts format=mpeg1:tsaf:muxrate=2000 -o MOVIE.MPG -oac lavc -lavcopts acodec=mp2:abitrate=224 -ovc lavc -lavcopts vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2:aspect=4/3


  • Factorial function implemented by recursion.

define fact(n)

{

if (n <= 1) return (n);

return (n * fact(n-1));

}


  • Perform a ROT 13 conversion:
#!/bin/sh
echo "$1" | tr '[A-Za-z]' '[N-ZA-Mn-za-m]'

  • Download streaming videos and convert them to MP3s

sudo curl https://yt-dl.org/downloads/2014.05.05/youtube-dl -o /usr/local/bin/youtube-dl

sudo chmod a+x /usr/local/bin/youtube-dl

youtube-dl --title --extract-audio --audio-format mp3 [LINK]

ffmpeg -i yourvideo.mp4 -f mp3 -ab 192000 -vn yourvideo.mp3

Personal tools