Skip to main content

Posts

Showing posts with the label snippet

How to play a video on a Raspberry Pi Desktop by double-clicking on a file...

The article describes how to open video, audio, and other media files in the Raspberry Pi desktop (the LXDE file manager) using the GPU-based player program. Does double-clicking on a video file in Raspbian result in slow blocky playback in SMPlayer and VLC on your Raspberry Pi? The short answer is that those video players will not work because at this time (Nov. 2013), they do not make use of the GPU on the Raspberry Pi. You need to use the hardware accelerated player, omxplayer, that is used in XBMC Live and OpenELEC.  The problem is that omxplayer is a command line player that is designed to be embedded in the XBMC based distributions.  I present below a way to make it play videos, if you double-click them in the Raspbian Desktop. Others have presented this method, but I've added a little bit of abstraction to make management easier. To start, open LXTerminal and the follow the process below. Step One - Get rid of the CPU-based media players sudo aptitu...

Programatically named variables in bash.

Suppose you wanted to do the following in bash: for label in a b c d e f do variable_${label}=${label} done This has the intended result of setting a series of variables: variable_a variable_b variable_c variable_d variable_e variable_f But if what if you want to dereference them programatically? for label in a b c d e f do echo ${variable_${label}} done is not acceptable bash syntax. But there is a way... We can abuse export and env . We set them with: for label in a b c d e f do export variable_${label}=${label} done We can then programmatically dereference the variables by searching for them in the output of env and using awk to get their value. for label in a b c d e f do echo "`env | grep variable_${label} | awk -F= '{print $2}'`" done How's that for bash abuse?

How do I clean up old large files on Linux?

Many people who have run Linux file servers and ftp servers have at some point wanted to free up some space. One good algorithm to do this efficiently is to remove old data starting with the largest files first. So how to generate such a list? One method is to use a " find -exec du " command: find /path/to/full/file/system -type f -mtime +10 -exec du -sk {} \; | sort -n > /var/tmp/list_of_files_older_than_10_days_sorted_by_size Once you have that list, you can selectively delete files from the bottom of it. Note that the list will likely be exponentially sorted. That is, the bottom 10% of the list will take up a huge chunk of the used storage space.

How the find the Active Directory Domain Controllers listed in DNS on Linux...

Assumptions: You have the "host" utility from BIND. You can do a zone transfer from the local DNS server Your Active Directory admins have properly configured DNS for Active Directory If you have the above, use the following command: host -t srv -l your.active.directory.dns.domain | grep _kerberos._tcp.*._sites.dc._msdcs.your.active.directory.dns.domain Replace your.active.directory.dns.domain with your actual AD DNS domain.

"cmore": Colorized text paging using vim...

Sometimes, I want colorized syntax and nice navigation for paging. We can use vim to provide this service. This assumes your terminal client supports the terminal type "xterm-color". If you need another color terminal type, customize accordingly. Install all of the standard vim packages Add  alias cmore="TERM=xterm-color vim -R -" to your ~/.profile Add the following [1] to your ~/.vimrc syntax on hi Comment ctermfg=Blue guifg=Blue hi String ctermfg=LightRed guifg=LightRed Reload your profile: source ~/.profile Usage: cat some.script.sh | cmore    It's vim in read-only mode, so use :q to quit. [1] I found the default colors to be too dark.

How do I convert spaces to underscores in file names and directory names on Linux?

Have you ever wanted to change all the spaces to underscores in a directory?  After going through various methods, the following is the most reliable way that I have found for bash users. Note, that there are many ways to accomplish this task. These examples should be typed in as a single line : find . -depth -maxdepth 1 -name "* *" -exec sh -c 'mv "${0}" "${0// /_}"' {} \; Note that '-maxdepth 1' changes spaces to underscores for files, directories, and links in the current directory. Changing that number to 2 or more will change spaces to underscores two or more levels deep in the current file system tree in addition to the current directory. Leaving out -maxdepth 1 will change spaces to underscores in the entire tree. Note also that the '.' means start in the current directory . You can certainly put other paths in place of the dot.  You can even put what is called a globbing pattern : find music* -depth -maxdepth 1...

Linux command line to find all open files...

Useful for restoring deleted files that might be held in memory by a running process: find /proc -type l -wholename "/proc/*/fd/*" -exec ls -l {} \; | egrep -v '.*->.*:.*' Have you ever accidentally deleted an active apache log file while investigating an issue? Backups are useless since the last one was the night before. You may be in luck, though! If there is a running process holding that file in memory, you can get the in-memory copy of the file from /proc on Linux. Run the above command to list files currently held in memory by processes. To restore, copy the "symlink" back to its original location. This will get you the file in the state that the particular process has in memory. The egrep strips out sockets, devices, etc.

Method for finding disk space faster than du.

Mount all of the areas with your data with unique paths. E.g., /mnt/fileserver1/mystuff, /mnt/fileserver2/mystuff, etc. With cron, do periodic 'find -ls' runs to a file across all of you personal paths. To count a certain directory: cat find_ls_file | awk ' /^some\/sub\/path/ {sum += $7} END  { gb=(sum/1024/1024/1024); printf"%0.2f GB\n",gb}' where find_ls_file holds the results of your find.  Even more useful is adding up any pattern, e.g., all .xvid files. cat find_ls_file | awk ' /\.xvid/ {sum += $7} END  { gb=(sum/1024/1024/1024); printf"%0.2f GB\n",gb}' Also, be sure to exclude snapshot directories from your find, if you have them (e.g., NetApp, ZFS) Another advantage of this method is parallelism. You can farm out the finds if you need to. Cheers, Adam

Script to convert MAC Address to format used by PXELinux

This script takes CCCC.CCCC.CCCC or CC:CC:CC:CC or cc:cc:cc:cc and spits out 01-cc-cc-cc-cc for a PXELinux MAC address file on the "first network segment." #!/bin/sh # Name: pxemac # Usage: pxemac ${MAC Address} OS=`uname -s` type () { TYPE=`echo $1 | sed s/[A-Za-z0-9]*//g` if [ "$TYPE" = ".." ] then return 0 else return 1 fi } linux () { if type $1 then echo $1 | sed -e "s/\./-/g" -e "s/^/01-/" -e "s/-[A-Za-z0-9]\{2\}/&-/g" | tr A-Z a-z else echo $1 | sed -e "s/\:/-/g" -e "s/^/01-/" | tr A-Z a-z fi } nonlinux () { if type $1 then echo $1 | sed -e "s/\./-/g" -e "s/^/01-/" -e "s/-[A-Za-z0-9]\{2\}/&-/g" | tr [A-Z] [a-z] else echo $1 | sed -e "s/\:/-/g" -e "s/^/01-/" | tr '[A-Z]' '[a-z]' fi } if [ "$OS" = "Linux" ] then linux $1 else nonlinux $1 fi