Bash
Home |
Table of Contents
USEFUL COMMANDS
#remove all .svn directories find -type d -name '.svn' -exec rm -rf {} \; #automatically sanitize file names, renaming the strange characters detox -r directory #rename all files and folders to lowercase find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \; # run top and log the output for 10 hours: top –b –n 12000 > myprocesslog # limit CPU usage cpulimit -e firefox -l 30 cpulimit -p 1313 -l 30 # combine nice and ionice together. Avoid disk intensive process to use too much disk cycles: nice -n 19 ionice -c2 -n7 /path/to/shell.script #Perl compatible GREP pcregrep 'Apr\s+(29|30)' /var/log/messages.1 # simply build a mplayer playlist. -shuffle option to randomize play find . -name "*.mp3" > files.list mplayer -shuffle -playlist files.list #Opens midnight comander via ssh mc /#sh:user@192.168.1.23 # LFTP via SSH lftp sftp://user@example.com #Usage: mirror [OPTS] [remote [local]] #When using -R, the first directory is local and the second is remote. #mirror -R test/ # amazon S3 s3cmd s3cmd sync s3://subdomain.domain.com/download/somedir ./ #sftp to another port different than default 22 sftp -oPort=2222 user@192.168.1.23 #Lazy umount - to unmount a dead NFS connection. sudo umount /media/backup1 umount.nfs: /media/backup1: device is busy umount.nfs: /media/backup1: device is busy sudo umount -l /media/backup1 # check what package a command belongs dpkg -S $(which ls) coreutils: /bin/ls # list all files contained in a package dpkg -L coreutils # Convert wav to mp3 ffmpeg -i REC014.wav -ar 44100 REC014.mp2 lame -V2 REC014.mp2 REC014.mp3 # delete all empty directories (it works because it will refuse #to delete directories containing files) find . -depth -type d -exec rmdir {} \; 2>/dev/null # delete all empty files or directories in current directory find . -empty -delete #The "-empty" option matches either empty files or directories, but since we're #specifying "-type d" as well, we'll only match empty directories (though you #could leave off the "-type d" and remove zero length files as well, and possibly #clean up even more directories as a result). The "-delete" option removes any #matching directories. What's cool about "-delete" is that it automatically #enables the "-depth" option so that we don't have to specify it on the command #line. # delete empty directories find . -type d -empty -delete #################### Images ############## # Generate an image thumbnail with Image Magic convert -size 240x180 image.jpg -thumbnail 120x90 thumbs/image.gif # Mogrify generates thumbnails for an entire directory of images, but be careful # not to overwrite the images you want to conserve mogrify -path thumbs -format gif -size 240x180 -thumbnail 120x90 '*.jpg' ## Full Documentation www.imagemagick.org/Usage/thumbnails convert -size 600x400 maby002.png -thumbnail 300x250 maby002.gif ################## Networking ## restart network card sudo ifconfig eth1 down sudo ifconfig eth1 up 192.168.1.2 sudo /etc/init.d/networking restart sudo route -n ping 8.8.8.8 sudo vim /etc/resolv.conf
1 Getting the source code of packages
for example, to download the package coreutils:
apt-get source coreutils cd coreutils-8.21 ./configure ## for debugging, turn off optimization -O0 make CFLAGS='-g -Wall -O0'
To build a package from source, first install the build dependencies:
sudo apt-get build-dep <package>
Then use dpkg-buildpackage to create a .deb file. From APT and Dpkg Quick Reference Sheet:
dpkg-buildpackage Builds a Debian package from a Debian source tree. You must be in the main directory of the source tree for this to work. Sample usage:
dpkg-buildpackage -rfakeroot -uc -b
Where -rfakeroot instructs it to use the fakeroot program to simulate root privileges (for ownership purposes), -uc stands for "Don't cryptographically sign the changelog", and -b stands for "Build the binary package only"
In a terminal, cd into the directory containing the package source (e.g ~/code/hellanzb-0.13) and run the following command:
dpkg-buildpackage -rfakeroot -uc -b
If the build is successful, there will be a .deb file located in the parent directory (e.g ~/code/hellanzb0.13-6.1all.deb).