2013-07-31 04:48:07 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
import sys
|
|
|
|
|
2013-07-31 05:25:36 +02:00
|
|
|
# assemble a keyphrase out of all params passed to the script
|
|
|
|
keyphrase = ' '.join(sys.argv[1:])
|
|
|
|
|
2013-07-31 05:33:31 +02:00
|
|
|
# create a dictionary of cheatsheets
|
|
|
|
cheatsheets = {
|
2013-07-31 04:48:07 +02:00
|
|
|
|
2013-08-10 05:46:34 +02:00
|
|
|
# @todo:
|
|
|
|
# - adb
|
|
|
|
# - apt-cache
|
|
|
|
# - dd
|
|
|
|
# - fdisk
|
|
|
|
# - mount
|
|
|
|
# - nc
|
|
|
|
# - rsync
|
|
|
|
# - shred
|
|
|
|
# - useradd / adduser
|
|
|
|
|
|
|
|
# @see: http://www.thegeekstuff.com/2010/11/50-linux-commands/
|
|
|
|
|
2013-08-10 05:17:22 +02:00
|
|
|
########## bash ###############################################################
|
|
|
|
'bash' : '''
|
|
|
|
To implement a for loop:
|
|
|
|
for file in `ls .`;
|
|
|
|
do echo 'file';
|
|
|
|
echo 'found';
|
|
|
|
done
|
|
|
|
|
|
|
|
@todo: if (esp. file/directory)
|
|
|
|
''',
|
|
|
|
|
|
|
|
########## convert ###########################################################
|
2013-08-10 03:56:42 +02:00
|
|
|
'convert' : '''
|
|
|
|
To resize an image to a fixed width and proportional height:
|
|
|
|
convert original-image.jpg -resize 100x converted-image.jpg
|
|
|
|
|
|
|
|
To resize an image to a fixed height and proportional width:
|
|
|
|
convert original-image.jpg -resize x100 converted-image.jpg
|
|
|
|
|
|
|
|
To resize an image to a fixed width and height:
|
|
|
|
convert original-image.jpg -resize 100x100 converted-image.jpg
|
|
|
|
|
|
|
|
To resize an image and simultaneously change its file type:
|
|
|
|
convert original-image.jpg -resize 100x converted-image.png
|
|
|
|
|
|
|
|
To resize all of the images within a directory:
|
2013-08-10 05:17:22 +02:00
|
|
|
To implement a for loop:
|
|
|
|
for file in `ls original/image/path/`;
|
2013-08-10 03:56:42 +02:00
|
|
|
do new_path=${file%.*};
|
|
|
|
new_file=`basename $new_path`;
|
|
|
|
convert $file -resize 150 conerted/image/path/$new_file.png;
|
|
|
|
done
|
|
|
|
''',
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
########## dhclient ##########################################################
|
|
|
|
'dhclient' : '''
|
2013-08-10 05:17:22 +02:00
|
|
|
To release the current IP address:
|
|
|
|
sudo dhclient -r
|
|
|
|
|
|
|
|
To obtain a new IP address:
|
|
|
|
sudo dhclient
|
|
|
|
|
|
|
|
Running the above in sequence is a common way of refreshing an IP.
|
2013-07-31 05:57:04 +02:00
|
|
|
''',
|
|
|
|
|
|
|
|
########## find ##############################################################
|
2013-07-31 04:48:07 +02:00
|
|
|
'find' : '''
|
2013-08-10 05:17:22 +02:00
|
|
|
To find files by extension (ex: .jpg):
|
|
|
|
find . -iname "*.jpg"
|
|
|
|
|
|
|
|
To find directories:
|
|
|
|
find . -type d
|
|
|
|
|
|
|
|
To find files:
|
|
|
|
find . -type f
|
|
|
|
|
|
|
|
To find files by octal permission:
|
|
|
|
find . -type f -perm 777
|
|
|
|
|
|
|
|
To find files with setuid bit set:
|
|
|
|
find . -xdev \( -perm -4000 \) -type f -print0 | xargs -0 ls -l
|
2013-07-31 04:48:07 +02:00
|
|
|
''',
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
########## git ###############################################################
|
2013-07-31 04:48:07 +02:00
|
|
|
'git' : '''
|
|
|
|
To set your identify:
|
|
|
|
git config --global user.name "John Doe"
|
|
|
|
git config --global user.email johndoe@example.com
|
|
|
|
|
|
|
|
To enable color:
|
|
|
|
git config --global color.ui true
|
|
|
|
''',
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
########## ln ################################################################
|
2013-07-31 04:48:07 +02:00
|
|
|
'ln' : '''
|
|
|
|
To create a symlink:
|
2013-08-10 03:56:42 +02:00
|
|
|
ln -s path/to/the/target/directory name-of-symlink
|
2013-07-31 04:48:07 +02:00
|
|
|
''',
|
|
|
|
|
2013-08-10 03:56:42 +02:00
|
|
|
########## netstat ###########################################################
|
|
|
|
'netstat' : '''
|
|
|
|
To view which users/processes are listening to which ports:
|
|
|
|
sudo netstat -lnptu
|
|
|
|
''',
|
|
|
|
|
|
|
|
########## sockstat ##########################################################
|
|
|
|
'sockstat' : '''
|
|
|
|
To view which users/processes are listening to which ports:
|
|
|
|
sudo sockstat -l
|
|
|
|
''',
|
2013-07-31 05:57:04 +02:00
|
|
|
|
|
|
|
########## ssh ###############################################################
|
|
|
|
'ssh' : '''
|
|
|
|
To execute a command on a remote server:
|
2013-08-10 03:56:42 +02:00
|
|
|
ssh -t user@example.com 'the-remote-command'
|
|
|
|
|
|
|
|
To tunnel an x session over SSH:
|
|
|
|
ssh -X user@example.com
|
2013-07-31 05:57:04 +02:00
|
|
|
|
2013-08-10 03:56:42 +02:00
|
|
|
To launch a specific x application over SSH:
|
|
|
|
ssh -X -t user@example.com 'chromium-browser'
|
|
|
|
|
|
|
|
For more information, see:
|
|
|
|
http://unix.stackexchange.com/q/12755/44856
|
|
|
|
''',
|
2013-07-31 05:57:04 +02:00
|
|
|
|
|
|
|
########## tar ###############################################################
|
2013-07-31 04:48:07 +02:00
|
|
|
'tar' : '''
|
|
|
|
To extract an uncompressed archive:
|
|
|
|
tar -xvf /path/to/foo.tar
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
To extract a .gz archive:
|
2013-07-31 04:48:07 +02:00
|
|
|
tar -xzvf /path/to/foo.tgz
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
To create a .gz archive:
|
2013-07-31 04:48:07 +02:00
|
|
|
tar -czvf /path/to/foo.tgz /path/to/foo/
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
To extract a .bz2 archive:
|
2013-07-31 04:48:07 +02:00
|
|
|
tar -xjvf /path/to/foo.tgz
|
|
|
|
|
2013-07-31 05:57:04 +02:00
|
|
|
To create a .bz2 archive:
|
2013-07-31 04:48:07 +02:00
|
|
|
tar -cjvf /path/to/foo.tgz /path/to/foo/
|
|
|
|
''',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-08-10 05:46:34 +02:00
|
|
|
# @todo: demonstrate some keyphrase aliases here
|
|
|
|
|
2013-07-31 05:33:31 +02:00
|
|
|
# print help if requested
|
2013-07-31 05:57:04 +02:00
|
|
|
if keyphrase in ['', 'help', '--help', '-h']:
|
2013-08-10 04:24:12 +02:00
|
|
|
cheatsheets_sorted = cheatsheets.keys()
|
|
|
|
cheatsheets_sorted.sort()
|
|
|
|
|
|
|
|
print "Usage: cheat [keyphrase]\n"
|
|
|
|
print "Available keyphrases:"
|
|
|
|
print "\n".join(cheatsheets_sorted)
|
2013-07-31 05:25:36 +02:00
|
|
|
exit()
|
|
|
|
|
2013-07-31 05:33:31 +02:00
|
|
|
# print the cheatsheet if it exists
|
|
|
|
print cheatsheets[keyphrase] if keyphrase in cheatsheets.keys() else 'No cheatsheet found.'
|