linux
I've been using debian since potato
, now mainly use ubuntu
.
I'm using awesome window manager now.
My setup is on github: usrjim/env
I've been a vim user for a long time, but now emacs is my primary editor.
sub pages
debian 6 squeeze
build mongodb extension for PHP under Debian 6 squeeze
$ apt-get install php5-dev build-essential php-pear
$ pecl install mongo
install / uninstall services
$ update-rc.d service-name defaults
$ update-rc.d -f service-name remove
basic commands
list one level dir by size
$ du -k --max-depth=1|sort -nr|more
resize image
$ convert original.jpg -resize 640x640 resized.jpg
find file in a folder
$ find -maxdepth x|grep 'name'
take screenshot
$ import screenshot.png
paste to terminal
$ shift-ins
get file full path
$ find `pwd` -name the_file
tar and ssh file
$ tar cf - dir | ssh remote_host "(cd dir2; tar xf -)"
playing the top
command:
| h | help |
|---------+-----------------------------------|
| f | fields |
| V | forest view |
| H | threads |
| R | sort |
|---------+-----------------------------------|
| i | toggle idle task |
|---------+-----------------------------------|
| L | locate string |
| & | find again |
| > and < | move sort column |
|---------+-----------------------------------|
| x | toggle highlight for sort field |
| y | toggle highlight for running task |
| z | toggle color |
| B | toggle bold |
|---------+-----------------------------------|
| A | alternative display |
| a | move to next field group |
| w | move to previous field group |
| g | enter field group |
|---------+-----------------------------------|
| k | kill a pid |
display non-idle with one frame: top -ibn 1
ps
sort by cpu: ps aux --sort c
show memory usage in detail: pmap -x [pid]
lolcat
: a colorful cat
about acl on ubuntu, FilePermissionsACLs, a quick note:
copy acl from one dir to another: getfacl dir1 | setfacl -b -n -M - dir2
Output from getfacl is accepted as input for
setfacl
when using-M
,-b
clear ACLs,-n
do not recalculate effective rights mask,-
read from stdin.
check permission recursively:
namei /path/to/file
to check permission on file/dir:
sudo -u user stat /path/to/dir/or/file
to check write permission:
sudo -u user test -w /path/to/dir/or/file; echo $?
or
sudo -u user test -w /path/to/dir/or/file && echo "ok" || echo "not ok"
check read and execute permission use -r
and -x
flags.
and for tmux
, to highlight the active pane, can set both fg and bg color, which will show as a bold line for the active pane:
set-option -g pane-active-border-fg red
set-option -g pane-active-border-bg red
LVM
to test I created a 3G disk from virtualbox, and resize it to 1G.
create
$ fdisk -l
$ fdisk -c -u /dev/sdb
here:
n -> p -> 1
t -> 8e
p
w
$ pvs
$ pvcreate /dev/sdb1
$ vgs
$ vgcreate -s 32M sitedata /dev/sdb1
$ vgdisplay sitedata (get PE)
$ lvs
$ lvcreate -l 95 -n sitephotos sitedata
$ mkfs.ext4 /dev/sitedata/sitephotos
$ mount /dev/sitedata/sitephotos /opt/sitephotos
$ df -h
resize
$ umount /opt/sitephotos
$ e2fsck -ff /dev/sitedata/sitephotos
$ resize2fs /dev/sitedata/sitephotos 1G
$ lvreduce -L -2G /dev/sitedata/sitephotos
$ mount /dev/sitedata/sitephotos /opt/sitephotos
create from free space
$ vgdisplay sitedata (get PE)
$ lvcreate -l 64 -n sitedoc sitedata
$ mount /dev/sitedata/sitedoc /opt/sitedoc
$ df -h
find modified files during an installation:
$ touch /tmp/afile
$ find /etc -newer /tmp/afile
can check accessed too:
$ find /etc -anewer /tmp/afile
to find between custom peroid:
$ touch -t 200712021345.00 /tmp/file1
$ touch -t 200712040130.00 /tmp/file2
$ find /etc -newer /tmp/file1 -a ! -newer /tmp/file2
bash
(note, on iTerm
, set profile keys
option to +Esc
)
(from Bash Shortcuts For Maximum Productivity)
Command Editing Shortcuts
| Ctrl + a | go to the start of the command line |
| Ctrl + e | go to the end of the command line |
| Ctrl + k | delete from cursor to the end of the command line |
| Ctrl + u | delete from cursor to the start of the command line |
| Ctrl + w | delete from cursor to start of word (i.e. delete backwards one word) |
| Ctrl + y | paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor |
| Ctrl + xx | move between start of command line and current cursor position (and back again) |
| Alt + b | move backward one word (or go to start of word the cursor is currently on) |
| Alt + f | move forward one word (or go to end of word the cursor is currently on) |
| Alt + d | delete to end of word starting at cursor (whole word if cursor is at the beginning of word) |
| Alt + c | capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word) |
| Alt + u | make uppercase from cursor to end of word |
| Alt + l | make lowercase from cursor to end of word |
| Alt + t | swap current word with previous |
| Ctrl + f | move forward one character |
| Ctrl + b | move backward one character |
| Ctrl + d | delete character under the cursor |
| Ctrl + h | delete character before the cursor |
| Ctrl + t | swap character under cursor with the previous one |
| Ctrl + _ | undo |
Command Recall Shortcuts
| Ctrl + r | search the history backwards |
| Ctrl + g | escape from history searching mode |
| Ctrl + p | previous command in history (i.e. walk back through the command history) |
| Ctrl + n | next command in history (i.e. walk forward through the command history) |
| Alt + . | use the last word of the previous command |
Command Control Shortcuts
| Ctrl + l | clear the screen |
| Ctrl + s | stops the output to the screen (for long running verbose command) |
| Ctrl + q | allow output to the screen (if previously stopped using command above) |
| Ctrl + c | terminate the command |
| Ctrl + z | suspend/stop the command |
Bash Bang (!) Commands
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
| !! | run last command |
| !blah | run the most recent command that starts with ‘blah’ (e.g. !ls) |
| !blah:p | print out the command that !blah would run (also adds it as the latest command in the command history) |
| !$ | the last word of the previous command (same as Alt + .) |
| !$:p | print out the word that !$ would substitute |
| !* | the previous command except for the last word (e.g. if you type ‘find some_file.txt /‘, then !* would give you ‘find some_file.txt‘) |
| !*:p | print out what !* would substitute |