Troca de conhecimentos sobre o uso da linha de comando e referencia direta ao site commandlinefu.com.
Show current working directory of a process
17 de Agosto de 2009, 0:00 - sem comentários ainda$ pwdx pid
by David Winterbottom (codeinthehole.com)
Go to parent directory of filename edited in last command
14 de Agosto de 2009, 0:00 - sem comentários ainda$ cd !$:h
Uses the last argument of the last executed command, and gets the directory name from it.
Use $!:t for the filename alone, without the dirname.
by David Winterbottom (codeinthehole.com)
return external ip
14 de Agosto de 2009, 0:00 - sem comentários ainda$ curl icanhazip.com
by David Winterbottom (codeinthehole.com)
Find the process you are looking for minus the grepped one
13 de Agosto de 2009, 0:00 - sem comentários ainda$ ps aux | grep [p]rocess-name
As an alternative to using an additional grep -v grep you can use a simple regular expression in the search pattern (first letter is something out of the single letter list ;-)) to drop the grep command itself.
by David Winterbottom (codeinthehole.com)
Release memory used by the Linux kernel on caches
12 de Agosto de 2009, 0:00 - sem comentários ainda$ free && sync && echo 3 > /proc/sys/vm/drop_caches && free
The Linux kernel uses unused memory in caches. When you execute "free" you never get the "real" available memory.
by David Winterbottom (codeinthehole.com)
Backup all MySQL Databases to individual files
11 de Agosto de 2009, 0:00 - sem comentários ainda$ for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump $I | gzip > $I.sql.gz"; done
by David Winterbottom (codeinthehole.com)
32 bits or 64 bits?
10 de Agosto de 2009, 0:00 - sem comentários ainda$ getconf LONG_BIT
Easy and direct way to find this out.
by David Winterbottom (codeinthehole.com)
find and delete empty dirs, start in current working dir
6 de Agosto de 2009, 0:00 - sem comentários ainda$ find . -empty -type d -exec rmdir {} +
A quick way to find and delete empty dirs, it starts in the current working directory.
If you do find . -empty -type d you will see what could be removed, or to a test run.
by David Winterbottom (codeinthehole.com)
Triple monitoring in screen
6 de Agosto de 2009, 0:00 - sem comentários ainda$ tmpfile=$(mktemp) && echo -e 'startup_message off\nscreen -t top htop\nsplit\nfocus\nscreen -t nethogs nethogs wlan0\nsplit\nfocus\nscreen -t iotop iotop' > $tmpfile && sudo screen -c $tmpfile
This command starts screen with 'htop', 'nethogs' and 'iotop' in split-screen. You have to have these three commands (of course) and specify the interface for nethogs - mine is wlan0, I could have acquired the interface from the default route extending the command but this way is simpler.
htop is a wonderful top replacement with many interactive commands and configuration options. nethogs is a program which tells which processes are using the most bandwidth. iotop tells which processes are using the most I/O.
The command creates a temporary "screenrc" file which it uses for doing the triple-monitoring. You can see several examples of screenrc files here: http://www.softpanorama.org/Utilities/Screen/screenrc_examples.shtml
by David Winterbottom (codeinthehole.com)
Move all images in a directory into a directory hierarchy based on year, month and day based on exif information
6 de Agosto de 2009, 0:00 - sem comentários ainda$ exiftool '-Directory<DateTimeOriginal' -d %Y/%m/%d dir
This command would move the file "dir/image.jpg" with a "DateTimeOriginal" of "2005:10:12 16:05:56" to "2005/10/12/image.jpg".
This is a literal example from the exiftool man page, very useful for classifying photo's. The possibilities are endless.
by David Winterbottom (codeinthehole.com)