# bring img on sd card
sudo pv -tpreb name.img | sudo dd of=/dev/mmcblk0 bs=4M
# create image from sd card
sudo pv -tpreb /dev/mmcblk0 | sudo dd of=name.img bs=4M
sudo dd bs=4M if=/dev/mmcblk0 | gzip > /home/yourusername/yourbackupdircetory/image`date +%d%m%y`.gz
sudo gzip -dc /home/yourusername/yourbackupdircetory/image `yourneededdate`.gz | sudo dd bs=4M of=/dev/mmcblk0
cat file.md | pandoc --from markdown --to rst -o file.rst
pstree -A | awk '{print " "$0}'
pkill -KILL -u username
find ./ -type f -exec cp '{}' ./ \;
find /media/cdrom -type f -name "*.jpg" -exec cp {} /home/user/pics/ \;
find /path/to/directory/ -type f \ ( -iname '*.jpg' -o -iname '*jpeg' \) -print0 |xargs -0 tar c | (cd /newpicfolder ; tar x)
find . -iname '*.jpg' -exec echo '<img src="{}">' \; > gallery.html
They were last modified, pausing to confirm before each removal, type:
$ find ~ -used +365 -ok rm '{}' ';' [RET]
find files/ -type f | while read line; do if [ $((i++%100)) -eq 0 ]; then mkdir $((++folder)); fi; cp $line $folder/; done
find /path/to/images -name '*.JPG' -exec rename "s/.JPG/.jpg/g" \{\} \;
i=0; f=$(find . -type f -iregex ".*jpg");c=$(echo $f|sed "s/ /\n/g"| wc -l);for x in $f;do i=$(($i + 1));echo "$x $i of $c"; mogrify -strip $x;done
find . -iname "*.jpg" -print0 | tr '[A-Z]' '[a-z]' | xargs -0 cp --backup=numbered -dp -u --target-directory {location} &
Use if you have pictures all over the place and you want to copy them to a central location
Synopsis:
Find jpg files
translate all file names to lowercase
backup existing, don't overwrite, preserve mode ownership and timestamps
copy to a central location
DISPLAY=:0.0 import -window root /tmp/shot.png
ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
F - fullscreen
z - random
D - time display in sec.
feh -Fr -D 5 ~/Images
echo “dear admin, please ban johnlame” | wall
Broadcast Message from [email protected] (/dev/pts/2) at 20:32 …
dear admin, please ban johnlame
diff <(lsusb) <(sleep 3s && lsusb)
I often use it to find recently added or removed device, or using find in
/dev, or anything similar.
Just run the command, plug the device, and wait to see him and only him
file -s /dev/sd* file(1) can print details about certain devices in the
/dev/ directory
(block devices in this example).
This helped me to know at a glance the location and revision of my
bootloader, UUIDs,
filesystem status,
which partitions were primaries / logicals, etc.. without running several
commands. See also file -s /dev/dm-* file -s /dev/cciss/* etc..
for i in ~/.adobe ~/.macromedia ; do ( rm $i/ -rf ; ln -s /dev/null $i
) ; done
Brute force way to block all LSO cookies on a Linux system with the
non-free Flash browser plugin. Works just fine for my needs. Enjoy.
wall <<< “Broadcast This”
ssh -f -L 5900:localhost:5900 your.ssh.server “x11vnc -safer -localhost
-nopw -once -display :0″; vinagre localhost:5900
cmp file1 file2
ssh -R 5497:127.0.0.1:22 -p 62220 [email protected]
host B (you) redirects a modem port (62220) to his local ssh.
host A is a remote machine (the ones that issues the ssh cmd).
once connected port 5497 is in listening mode on host B.
host B just do a
ssh 127.0.0.1 -p 5497 -l user
and reaches the remote host’ssh. This can be used also for vnc and so on.
gdb -batch -ex “run” -ex “bt” ${my_program} 2>&1 | grep -v ^”No stack.”$
For automated unit tests I wanted my program to run normally, but if it
crashed, to add
a stack trace to the output log. I came up with this command so I wouldn’t
have to mess around with core files.
The one downside is that it does smoosh your program’s stderr and stdout
together.
xargs -n 2 mv < file_with_colums_of_names
Maybe simpler, but again, don’t know how it will work with space in
filename.
> file
mycommand 2> >(while read line; do echo -e “\e[01;31m$line\e[0m"; done)
perl -wlne'/title>([^<]+)/i&&rename$ARGV,”$1.html”‘ *.html
The above one-liner could be run against all HTML files in a directory. It
renames the HTML files based on
the text contained in their title tag. This helped me in a situation where
I had a directory containing
thousands of HTML documents with meaningless filenames.
alias vim="vim -p"
I always add this to my .profile rc so I can do things like: "vim *.c" and
the files are opened in tabs.
head -100000 /dev/urandom | strings|tr '[A-Z]' '[a-z]'|sort >temp.txt &&
wget -q http://www.mavi1.org/web_security/wordlists/webster-dictionary.txt
-O-|tr '[A-Z]' '[a-z]'|sort >temp2.txt&&comm -12 temp.txt temp2.txt
wget -qO- www.commandlinefu.com/commands/by/PhillipNordwall | awk -F\>
'/num-votes/{S+=$2; I++}END{print S/I}'
echo <percentage> > /proc/acpi/video/VGA/LCD/brightness
Run as root. Path may vary depending on laptop model and video card (this
was tested on an Acer laptop with ATI HD3200 video).
cat /proc/acpi/video/VGA/LCD/brightnessto discover the possible values for
your display.
infocmp rxvt-unicode | ssh 10.20.30.40 "mkdir -p .terminfo && cat >/tmp/ti
&& tic /tmp/ti"
I frequently use this trick to send my terminal settings to HPUX and older
RHEL systems. This is due to the fact that terminfo support for
rxvt-unicode (my preferred terminal app) does not exist on many older Linux
and Unices.
dd if=/dev/sdb | pigz | gpg -r <recipient1> -r <recipient2> -e --homedir
/home/to/.gnupg | nc remote_machine 6969
Acquires a bit-by-bit data image, gzip-compresses it on multiple cores
(pigz) and encrypts the
data for multiple recipients (gpg -e -r). It finally sends it off to
a remote machine.
exec 5< <(grep -i "$*" $(locate CharName.pm));while read <&5;do h=${REPLY%%
*};/usr/bin/printf "\u$h\tU+%s\t%s\n" "$h" "${REPLY##$h }";done
cut -f2 -d`echo -e '\x01'` file
cat /dev/urandom | hexdump -C | highlight ca fe 3d 42 e1 b3 ae f8 | perl
-MTime::HiRes -pnE "Time::HiRes::usleep(rand()*1000000)"
Nobody wants the boss to notice when you're slacking off. This will fill
your shell with random data, parts of it highlighted.
Note that 'highlight' is the Perl module App::highlight, not "a universal
sourcecode to formatted text converter." You'll also need Term::ANSIColor.
xfreerdp --plugin rdpsnd -g 1280x720 -a 24 -z -x m -u $username -p
$password 10.20.30.40
This example uses xfreerdp, which builds upon the development of rdesktop.
This example usage will also send you the remote machine's sound.
echo ::memstat | mdb -k
man -t manpage | ps2pdf - filename.pdf
Quick and dirty version. I made a version that checks if a manpage exists
(but it's not a oneliner). You must have ps2pdf and of course Ghostscript
installed in your box.
pv access.log | gzip > access.log.gz
Pipe viewer is a terminal-based tool for monitoring the progress of data
through a pipeline. It can be inserted into any normal pipeline between two
processes to give a visual indication of how quickly data is passing
through, how long it has taken, how near to completion it is, and an
estimate of how long it will be until completion. Source:
http://www.catonmat.net/blog/unix-utilities-pipe-viewer/
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /'
-e 's/-/|/' Prints a graphical directory tree from your current directory
rm !(*.foo|*.bar|*.baz) Deletes all files in a folder that are NOT *.foo,
*.bar or *.baz files. Edit the pattern inside the brackets as you like.
some_very_long_and_complex_command # label When using reverse-i-search you
have to type some part of the command that you want to retrieve. However,
if the command is very complex it might be difficult to recall the parts
that will uniquely identify this command. Using the above trick it’s
possible to label your commands and access them easily by pressing ^R
and typing the label (should be short and descriptive).
? () { echo "$*" | bc -l; } defines a handy function for quick calculations
from cli.
once defined:
? 10*2+3 ## DISPLAY A COOL CLOCK ON YOUR TERMINAL
watch -t -n1 "date +%T|figlet" This command displays a clock on your
terminal which updates the time every second. Press Ctrl-C to exit.
A couple of variants:
A little bit bigger text:
watch -t -n1 "date +%T|figlet -f big"You can try other figlet fonts, too.
Big sideways characters:
watch -n 1 -t '/usr/games/banner -w 30 $(date +%M:%S)'This requires
a particular version of banner and a 40-line terminal or you can adjust the
width (“30″ here).
strace -ff -e trace=write -e write=1,2 -p SOME_PID
awk '!x[$0]++' <file>
Using awk, find duplicates in a file without sorting, which reorders the
contents. awk will not reorder them, and still find and remove duplicates
which you can then redirect into another file.
ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/outputFile.mpg Grab X11
input and create an MPEG at 25 fps with the resolution 800×600
mount /path/to/file.iso /mnt/cdrom -oloop “-o loop” lets you use a file as
a block device
!:- /usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.google.com/then
!:- http://www.urfix.com/is the same as
/usr/sbin/ab2 -f TLS1 -S -n 1000 -c 100 -t 2 http://www.urfix.com/ ##
CONVERT SECONDS TO HUMAN-READABLE FORMAT
date -d@1234567890 This example, for example, produces the output, “Fri Feb
13 15:26:30 EST 2009″
^Z $bg $disown You’re running a script, command, whatever.. You don’t
expect it to take long, now 5pm has rolled around and you’re ready to go
home… Wait, it’s still running… You forgot to nohup it before running it…
Suspend it, send it to the background, then disown it… The ouput wont go
anywhere, but at least the command will still run…
vim scp://username@host//path/to/somefile
watch -n 1 mysqladmin --user=<user> --password=<password> processlist Watch
is a very useful command for periodically running another command – in this
using mysqladmin to display the processlist. This is useful for monitoring
which queries are causing your server to clog up.
More info here:
http://codeinthehole.com/archives/2-Monitoring-MySQL-processes.html
\[command] e.g. if rm is aliased for ‘rm -i’, you can escape the alias by
prepending a backslash:
rm [file] # WILL prompt for confirmation per the alias
\rm [file] # will NOT prompt for confirmation per the default behavior of
the command
ss -p for one line per process:
ss -p | catfor established sockets only:
ss -p | grep STAfor just process names:
ss -p | cut -f2 -sd\"or
ss -p | grep STA | cut -f2 -d\" ## SEND POP-UP NOTIFICATIONS ON GNOME
notify-send ["<title>"] "<body>"
The title is optional.
Options:
-t: expire time in milliseconds.
-u: urgency (low, normal, critical).
-i: icon path.
On Debian-based systems you may need to install the ‘libnotify-bin’
package.
Useful to advise when a wget download or a simulation ends. Example:
wget URL ; notify-send "Done"
mv filename.{old,new}
rm -f !(survivior.txt)
strings /dev/urandom | grep -o '[[:alnum:]]' | head -n 30 | tr -d '\n';
echo Find random strings within /dev/urandom. Using grep filter to just
Alphanumeric characters, and then print the first 30 and remove all the
line feeds.
echo "rm -rf /unwanted-but-large/folder" | batch Good for one off jobs that
you want to run at a quiet time. The default threshold is a load average of
0.8 but this can be set using atrun.
watch -n 1 'echo "obase=2;`date +%s`" | bc' Create a binary clock.
dd if=/dev/zero of=/dev/null bs=1M count=32768 Read 32GB zero’s and throw
them away.
How fast is your system?
for I in $(mysql -e 'show databases' -s --skip-column-names); do mysqldump
$I | gzip > "$I.sql.gz"; done
watch -d -n 2 ‘df; ls -FlAt;’
wget –random-wait -r -p -e robots=off -U mozilla http://www.example.com
-p parameter tells wget to include all files, including images.
-e robots=off you don’t want wget to obey by the robots.txt file
-U mozilla as your browsers identity.
–random-wait to let wget chose a random number of seconds to wait, avoid
get into black list.
Other Useful wget Parameters:
–limit-rate=20k limits the rate at which it downloads files.
-b continues wget after logging out.
-o $HOME/wget_log.txt logs the output
du -h –max-depth=1
time read (ctrl-d to stop)
time read -sn1 (s:silent, n:number of characters. Press any character to
stop)
man ascii
net rpc shutdown -I ipAddressOfWindowsPC -U username%password
This will issue a shutdown command to the Windows machine. username must be
an administrator on the Windows machine. Requires samba-common package
installed. Other relevant commands are:
net rpc shutdown -r : reboot the Windows machine
net rpc abortshutdown : abort shutdown of the Windows machine
Type:
net rpc
to show all relevant commands
(cd /tmp && ls)
ps aux | sort -nk +4 | tail
ps returns all running processes which are then sorted by the 4th field in
numerical order and the top 10 are sent to STDOUT.
history | awk ‘{a[$2]++}END{for(i in a){print a[i] ” ” i}}’ | sort -rn
| head
<alt> + <print screen/sys rq> + <R> – <S> – <E> – <I> – <U> – <B>
If the machine is hanging and the only help would be the power button, this
key-combination will help to reboot your machine (more or less) gracefully.
R – gives back control of the keyboard
S – issues a sync
E – sends all processes but init the term singal
I – sends all processes but init the kill signal
U – mounts all filesystem ro to prevent a fsck at reboot
B – reboots the system
Save your file before trying this out, this will reboot your machine
without warning!
http://en.wikipedia.org/wiki/Magic_SysRq_key
less +F somelogfile
Using +F will put less in follow mode. This works similar to ‘tail -f’. To
stop scrolling, use the interrupt. Then you’ll get the normal benefits of
less (scroll, etc.).
Pressing SHIFT-F will resume the ‘tailling’.
ping -i 60 -a IP_address
Waiting for your server to finish rebooting? Issue the command above and
you will hear a beep when it comes online. The -i 60 flag tells ping to
wait for 60 seconds between ping, putting less strain on your system. Vary
it to your need. The -a flag tells ping to include an audible bell in the
output when a package is received (that is, when your server comes online).
echo “The date is: $(date +%D)” This is a simple example of using proper
command nesting using $() over “. There are a number of advantages of $()
over backticks. First, they can be easily nested without escapes:
program1 $(program2 $(program3 $(program4)))versus
program1 `program2 \`program3 \`program4\`\``Second, they’re easier to
read, then trying to decipher the difference between the backtick and the
singlequote: `’. The only drawback $() suffers from is lack of total
portability. If your script must be portable to the archaic Bourne shell,
or old versions of the C-shell or Korn shell, then backticks are
appropriate, otherwise, we should all get into the habit of $(). Your
future script maintainers will thank you for producing cleaner code.
echo “You can simulate on-screen typing just like in the movies” | pv -qL
10
This will output the characters at 10 per second.
python -m smtpd -n -c DebuggingServer localhost:1025
This command will start a simple SMTP server listening on port 1025 of
localhost. This server simply prints to standard output all email headers
and the email body.
lsof -i
diff <(sort file1) <(sort file2)
bash/ksh subshell redirection (as file descriptors) used as input to diff
mplayer -ao pcm -vo null -vc dummy -dumpaudio -dumpfile <output-file>
<input-file>
replace accordingly
tr -c “[:digit:]” ” ” < /dev/urandom | dd cbs=$COLUMNS conv=unblock | GREP_COLOR=”1;32″ grep –color “[^ ]“
sudo dd if=/dev/mem | cat | strings
A fun thing to do with ram is actually open it up and take a peek.
cat /etc/issue
alias ‘ps?’='ps ax | grep ‘
echo “!!” > foo.sh
Sometimes commands are long, but useful, so it’s helpful to be able to make
them permanent without having to retype them. An alternative could use the
history command, and a cut/sed line that works on your platform.
history -1 | cut -c 7- > foo.sh
wget -qO – “http://www.tarball.com/tarball.gz” | tar zxvf -
nc -vv -l -p 1234 -e /bin/bash
This will launch a listener on the machine that will wait for a connection
on port 1234. When you connect from a remote machine with something like :
nc 192.168.0.1 1234
You will have console access to the machine through bash. (becareful with