Linux tips

From Wiki

Jump to: navigation, search

How big is a directory?

sort -n -r

du -hs /dirpath/dirname du -hs /dirpath/dirname/*


Search filesystem discarding "Permission denied" errors:BR Append 2>/dev/null to find statementBR {{{ find / -name "*ayn*" 2>/dev/null }}} Don't descend directories on other filesystems: {{{ sudo find / -mount -name "*ayn*" }}} Find directories only in the current directory that were modified at least 43 days ago {{{ find . -maxdepth 1 -type d -mtime +43 -print }}}


Find a file and execute a specific command:


{{{ find path conditions -exec command {} \;

find ./ -name “*.php” -exec cat {} \;

find . -name desktop.ini -exec rm {} \; #delete all files named desktop.ini in current directory and subdirectories }}}


The open/close curly bracket marks where the name of each file found will be substituted and the backslash-semicolon marks the end of the command to execute.

Example:BR List user and owner of all folders in the current directory:

{{{ find . -type d -exec ls -alsd {} \; }}}


Search for files modified within the past n days:

{{{ find path -mtime -n

find ./ -mtime -7 }}}


Search for files modified before the past n days:


{{{ find path -mtime +n

find /tmp -mtime +3 }}}


E-mail a text file from command line:

mail -s "subject line" my@email.com

mail -s "subject line" my@email.com < file.txt rmail -w my@email.com < file.txt



Look inside a zipped file:

more



Compress and encrypt a file/directory

{{{ zip -e compressedFileName.zip /path/dir/file }}}


Copy your work to a file:

{{{ script -a(ppend) log.txt }}}

To end: exit


Mount a flash drive:

grep -i "SCSI device"

fdisk -l mkdir /mnt/usbflash mount -t vfat /dev/sda1 (or sda) /mnt/usbflash umount /mnt/usbflash



Secure Copy

{{{ scp files destination scp *.CEL ruser@server:dir }}}


Convert image files with ImageMagick:

{{{ convert x.png -format tiff -resample 600 (dpi) x.tif }}}


Make thumbnail images with ImageMagick:

{{{ mkdir thumbs mogrify [-format gif] -path thumbs -thumbnail 100x100 *.jpg }}}


Show all disk information {{{ /sbin/fdisk -l }}} To append /sbin to the end of your current path use: {{{ export PATH=`echo $PATH`:/sbin }}}


Show a calendar for May 2008 (or any other month) {{{ cal 5 2008

     May 2008      

Su Mo Tu We Th Fr Sa

            1  2  3
4  5  6  7  8  9 10

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 }}}



Get all expressed genes in the Cerebral Cortex {{{ for i in 1 2 3 4 5 6 7 8 9 10 11 12 do

 echo $i
 wget http://mouse.brain-map.org/GeneExpression/Cerebral+cortex/$i.xml

done

for i in 1 2 3 4 5 6 7 8 9 10 11 12 #OR for i in $(seq 1 12) do

 echo $i
 cat $i.xml >> cortex.xml

done

sed 's/</\n/g;' < cortex.xml > cortex.txt grep genesymbol cortex.txt > symbols.txt sed '/\/genesymbol\>/d;' < symbols.txt > symbols_2.txt sed 's/genesymbol>//;' < symbols_2.txt > symbols_3.txt mv symbols_3.txt cortexGenes.txt

Other "for" syntax: for i in {a..z} {0..9} do

 curl http://.../.../

done > all.xml }}}

symbol


For construction unexpected oddness

Calling the variable before a string can result in losing the variable,

 i.e. bill.jpg becomes .jpg instead of bill_new.jpg
 One solution is to make the string a variable too 

{{{ for barcode in `cat 0534306526.txt` do hflip="_hflip.jp2" mv /projects/spinalcord/vol1/prod19/$barcode/$barcode.jp2 /projects/spinalcord/vol1/prod19/$barcode/$barcode$hflip mv /projects/spinalcord/vol1/prod19/$barcode/downsample.png /projects/spinalcord/vol1/prod19/$barcode/downsample_hflip.png mv /projects/spinalcord/vol1/prod19/$barcode/mask.png /projects/spinalcord/vol1/prod19/$barcode/mask_hflip.png done }}} ---

How to get USB GPS to work with Garmin Map Source running via WINE/Crossover

{{{ su - cd /home/wayne/.cxoffice/Unsupported/dosdevices ln -s /dev/ttyUSB0 /home/wayne/.cxoffice/Unsupported/dosdevices/com1 chmod 777 /dev/ttyUSB0

     #can ls /dev, plug in USB device, ls again to confirm where the USB device is added to /dev

}}}

Given a file full of path/filenames, find which files are older than 222 days

{{{

 for file in `cat 20090311_350ics.csv`; do find $file -mtime +222 >> 350ics.out; done

}}}

Personal tools