Commands tagged encoding (12)

  • This is just a proof of concept: A FILE WHICH CAN AUTOMOUNT ITSELF through a SIMPLY ENCODED script. It takes advantage of the OFFSET option of mount, and uses it as a password (see that 9191? just change it to something similar, around 9k). It works fine, mounts, gets modified, updated, and can be moved by just copying it. USAGE: SEE SAMPLE OUTPUT The file is composed of three parts: a) The legible script (about 242 bytes) b) A random text fill to reach the OFFSET size (equals PASSWORD minus 242) c) The actual filesystem Logically, (a)+(b) = PASSWORD, that means OFFSET, and mount uses that option. PLEASE NOTE: THIS IS NOT AN ENCRYPTED FILESYSTEM. To improve it, it can be mounted with a better encryption script and used with encfs or cryptfs. The idea was just to test the concept... with one line :) It applies the original idea of http://www.commandlinefu.com/commands/view/7382/command-for-john-cons for encrypting the file. The embedded bash script can be grown, of course, and the offset recalculation goes fine. I have my own version with bash --init-file to startup a bashrc with a well-defined environment, aliases, variables. Show Sample Output


    6
    dd if=/dev/zero of=T bs=1024 count=10240;mkfs.ext3 -q T;E=$(echo 'read O;mount -o loop,offset=$O F /mnt;'|base64|tr -d '\n');echo "E=\$(echo $E|base64 -d);eval \$E;exit;">F;cat <(dd if=/dev/zero bs=$(echo 9191-$(stat -c%s F)|bc) count=1) <(cat T;rm T)>>F
    rodolfoap · 2013-01-31 01:38:30 13

  • 4
    iconv -f utf8 -t utf16 /path/to/file
    imsaar · 2009-12-01 21:02:58 3
  • Useful if non-ascii characters in filenames have been improperly encoded. Replace "PROBLEM" with the incorrect characters (e.g. 'é'), and "FIX" with the correct ones (e.g. '?').


    3
    for i in *;do mv "$i" "$(echo $i | sed s/PROBLEM/FIX/g)";done
    AlecSchueler · 2009-06-28 01:50:25 18
  • Get gzip compressed web page using wget. Caution: The command will fail in case website doesn't return gzip encoded content, though most of thw websites have gzip support now a days.


    3
    wget -q -O- --header\="Accept-Encoding: gzip" <url> | gunzip > out.html
    ashish_0x90 · 2010-11-27 22:14:42 6

  • 3
    find . -iname *.java -type f -exec bash -c "iconv -f WINDOWS-1252 -t UTF-8 {} > {}.tmp " \; -exec mv {}.tmp {} \;
    miguelbaldi · 2012-01-12 20:00:26 5
  • This command gives you the charset of a text file, which would be handy if you have no idea of the encoding. Show Sample Output


    2
    file -i <textfile>
    juvenn · 2009-09-08 01:33:19 4
  • http://www.mplayerhq.hu/DOCS/HTML/en/menc-feat-mpeg.html MEncoder can create MPEG (MPEG-PS) format output files. Usually, when you are using MPEG-1 or MPEG-2 video, it is because you are encoding for a constrained format such as SVCD, VCD, or DVD. To change MEncoder's output file format, use the -of mpeg option. Creating an MPEG-1 file suitable to be played on systems with minimal multimedia support, such as default Windows installs: mencoder input.avi -of mpeg -mpegopts format=mpeg1:tsaf:muxrate=2000 \ -o output.mpg -oac lavc -lavcopts acodec=mp2:abitrate=224 -ovc lavc \ -lavcopts vcodec=mpeg1video:vbitrate=1152:keyint=15:mbd=2:aspect=4/3


    1
    mencoder input.avi -of mpeg -ovc lavc -lavcopts vcodec=mpeg1video \ -oac copy other_options -o output.mpg
    slishan · 2010-01-18 13:12:03 3
  • Really helpfull when play with files having spaces an other bad name. Easy to store and access names and path in just a field while saving it in a file. This format (URL) is directly supported by nautilus and firefox (and other browsers) Show Sample Output


    1
    convert_path2uri () { echo -n 'file://'; echo -n "$1" | perl -pe 's/([^a-zA-Z0-9_\/.])/sprintf("%%%.2x", ord($1))/eg' ;} #convert2uri '/tmp/a b' ### convert file path to URI
    totti · 2013-07-01 08:54:45 7
  • Like the original command, but the -f allows this one to succeed even if the website returns uncompressed data. From gzip(1) on the -f flag: If the input data is not in a format recognized by gzip, and if the --stdout is also given, copy the input data without change to the standard output: let zcat behave as cat.


    1
    wget -q -O- --header="Accept-Encoding: gzip" <url> | gzip -cdf > out.html
    tempusername · 2014-11-29 20:42:21 8

  • 0
    uchardet <filename>
    fltman · 2014-11-28 07:47:13 7
  • I still don't know why mutt (or offlineimap or whatever in between), is borking the encoding of my files, but this fixes it. Show Sample Output


    0
    fix_saved_files() { for i in "$@" ; do mv $i $(php -r '$or = "'$i'"; mb_internal_encoding("UTF-8"); echo mb_decode_mimeheader($or) . "\n";') ; done; }
    guillaume · 2014-12-27 20:37:16 8
  • Also works with files: cat file Hello world base64 file SGVsbG8gd29ybGQK To decrypt use the -d option: echo SGVsbG8gd29ybGQK | base64 -d Hello world Show Sample Output


    -3
    echo "Hello world" | base64
    P17 · 2009-04-27 15:00:08 16

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

Kills a process that is locking a file.
Useful when you're trying to unmount a volume and other sticky situations where a rogue process is annoying the hell out of you.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

Automagically update grub.conf labels after installing a new kernel
I like to label my grub boot options with the correct kernel version/build. After building and installing a new kernel with "make install" I had to edit my grub.conf by hand. To avoid this, I've decided to write this little command line to: 1. read the version/build part of the filename to which the kernel symlinks point 2. replace the first label lines of grub.conf grub.conf label lines must be in this format: Latest [{name}-{version/build}] Old [{name}-{version/build}] only the {version/build} part is substituted. For instance: title Latest [GNU/Linux-2.6.31-gentoo-r10.201003] would turn to title Latest [GNU/Linux-2.6.32-gentoo-r7.201004]"

Rename files in batch

list block devices
Shows all block devices in a tree with descruptions of what they are.

complete extraction of a debian-package
extracts the debian-package $debfile to $extractdir, including all packaging-information. to repack the package, just type: $dpkg-deb -b $extractdir

Install your ssh key file on a remote system

Terminal redirection
Will redirect output of current session to another terminal, e.g. /dev/pts/3 Courtesy of bassu, http://www.commandlinefu.com/commands/by/bassu

Changes a User Password via command line without promt
Used to change a password via a winscp faux shell

Selecting a random file/folder of a folder
Also looks in subfolders


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: