You are on page 1of 22

B Linux Shell

WowUbuntu / Isspy

B Linux Shell
Top Ten One-Liners from CommandLineFu Explained
: boypt / isspy / riku / riku
: 2010 9 10
:CC 2.5
Isspy Wow! Ubuntu

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

@isspy Wow! Ubuntu (


riku ) Linux CLI

: http://wowubuntu.com/tag/linuxshell

Catonmat Top Ten One-Liners from CommandLineFu


Explained shell
shell

ShellUnix

""Shell

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

=== ===
1.SUDO
$ sudo !!
sudo
sudo
sudoCtrl-pCtrl-asudo
sudo !!

bashevent designators!!
!-1!-2!-50bash
~/.bash_history500history
The Definitive Guide to Bash Command Line
History
2.HTTP
$ python -m SimpleHTTPServer
PythonSimpleHTTPServerPythonLinux

8000HTTP
ttp://ip:8000
3.VIMROOT
:w !sudo tee %

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

sudovim/etc
vim
sudo cpvim

vim:help :w:w!{cmd}vim{cmd}
stdin
teestdin
%vim
vim
4.
$ cd -
cd -cd $OLDPWDbash$OLDPWD

$PWDshell
5.
$ ^foo^bar^
event designatorfoo
bar

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

!!:s/foo/bar/
!!vimsed

The Definitive Guide to Bash Command Line


History
6.
$ cp filename{,.bak}
filenamefilename.bak
bashfilename{,.bak}
filename filename.bakcp
bash
$ echo {a,b,c}{a,b,c}{a,b,c}
:
aaa aab aac aba abb abc aca acb acc
baa bab bac bba bbb bbc bca bcb bcc
caa cab cac cba cbb cbc cca ccb ccc
shell"Set Operations in the Unix Shell"
7.SSH
$ ssh-copy-id remote-machine
~/.ssh/authorized_keys
ssh
ssh-keygen

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

your-machine$ scp ~/.ssh/identity.pub remote-machine:


your-machine$ ssh remote-machine
remote-machine$ cat identity.pub >> ~/.ssh/authorized_keys
authorized_keys

8.LINUX
$ ffmpeg -f x11grab -s wxga -r 25 -i :0.0 -sameq /tmp/out.mpg
3D
ffmpegX11
ffmpeg

-f x11grab x11
ffmpeg
-s wxga wxga1366*768-s
800600
-r 25
-i :0.0 X0.0
-sameq
ffmpeg
How to Extract Audio Tracks from YouTube Videos
Converting YouTube Flash Videos to a Better Format with ffmpeg

=== ===
1.
command <CTRL-x CTRL-e>

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

<CTRL-x CTRL-e> vim


$EDITOR
mencoder/ffmpeg3
4
readlinebashemacs
<CTRL-x CTRL-e>vi <ESC
v>
~/.bashrcexport EDITOR=nano
fcFix Command
^foo^bar^fcfc -s foo=bar
2.
> file.txt
>shell

:>file.txt:bash
$touch file.txttouch

3.SSH
ssh -N -L2001:remotehost:80 user@somemachine
20012001somemachine
remotehost80
3
somemachinelocalhost
IP
80ssh
------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

webIP

ssh -f -N -L 0.0.0.0:443:twitter.com:443 shell.cjb.net


ssh -f -N -L 0.0.0.0:80:twitter.com:80 shell.cjb.net
/etc/hosts127.0.0.1 twitter.com
squidnginxssh

4.
reset
cat
reset

resetBusyBoxreset

printf(\033c\033(K\033[J\033[0m\033[?25h);
Shell
\033c: ESC c ;
\033(K: ESC ( K ;
\033[J: ESC [ J ;
\033[0m: ESC [ 0 m ;
\033[?25h: ESC [ ? 25 h ;

5.
echo cmd | at midnight
------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

atcronatcron

at tomorrow, next week


man at
6.
dd if=/dev/dsp | ssh username@host dd of=/dev/dsp

/dev/dspLinuxDigital Signal Proccessor

ddifofstdin/stdout

dd if=/dev/dsp of=/dev/dsp

alsaarecordaplay:
arecord | ssh username@host aplay

arecord | aplay

cat /dev/urandom | ssh username@host aplay


7.

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

mount -t tmpfs -o size=1024m tmpfs /mnt/ram


1G

fstab
/dev/shm
FirefoxFF
ShellextmpfsFirefox tmpfs Firefox
IIspeeding up firefox with tmpfs and automatic rsync
LinuxQQIO
8.DIFF
ssh user@host cat /path/to/remotefile | diff /path/to/localfile diff-stdin
sshwebsshfs---

9.
netstat -tulnp
NetstatLinux
-t: TCP
-u: UDP
-l:
-n: ip
-p: PIDroot
socketslsof

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

=== ===
1.
mount | column -t
column
columnt
mount
$ mount
/dev/root on / type ext3 (rw)
/proc on /proc type proc (rw)
/dev/mapper/lvmraid-home on /home type ext3 (rw,noatime)
column -t
$ mount | column -t
/dev/root on / type ext3 (rw)
/proc on /proc type proc (rw)
/dev/mapper/lvmraid-home on /home type ext3 (rw,noatime)

$ (echo "DEVICE - PATH - TYPE FLAGS" && mount) | column -t


DEVICE - PATH - TYPE FLAGS
/dev/root on / type ext3 (rw)
/proc on /proc type proc (rw)
/dev/mapper/lvmraid-home on /home type ext3 (rw,noatime)
24 awk
$ (echo "DEVICE PATH TYPE FLAGS" && mount | awk '$2=$4="";1') | column -t
DEVICE PATH TYPE FLAGS
/dev/root / ext3 (rw)
/proc /proc proc (rw)

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

/dev/mapper/lvmraid-home /home ext3 (rw,noatime)


nicemount
$ nicemount() { (echo "DEVICE PATH TYPE FLAGS" && mount |
awk '$2=$4="";1') | column -t; }

$ nicemount
DEVICE PATH TYPE FLAGS
/dev/root / ext3 (rw)
/proc /proc proc (rw)
/dev/mapper/lvmraid-home /home ext3 (rw,noatime)
2. Shell "bar" "foo"
!!:gs/foo/bar
!! :gs/foo/bar
!!
3.
watch -d -n 1 'df; ls -FlAt /path'
/path watch -d
-n 1 1
df; ls -FlAt /path df ls -FlAt /path

ls -FlAt
-F */=>@| *
/ = ( sockets) > @ |

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

-l
-A . ..
-t
4. SSH
sshfs name@server:/path/to/folder /path/to/mount/point
SSH
FUSE sshfs

sshfs " Ubuntu sshfs


ssh "
fusermount
fusermount -u /path/to/mount/point
5. DNS Wikipedia
dig +short txt <keyword>.wp.dg.cx
David Leadbeater DNS
TXT Wikipedia

"hacker"
$ dig +short txt hacker.wp.dg.cx
"Hacker may refer to: Hacker (computer security), someone involved
in computer security/insecurity, Hacker (programmer subculture), a
programmer subculture originating in the US academia in the 1960s,
which is nowadays mainly notable for the free software/" "open
source movement, Hacker (hobbyist), an enthusiastic home computer
hobbyist http://a.vu/w:Hacker"
dig DNS +short
txt TXT

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

wiki() { dig +short txt $1.wp.dg.cx; }

$ wiki hacker
"Hacker may refer to: Hacker (computer security), ..."
dig host
host -t txt hacker.wp.dg.cx
6. Wget
wget --random-wait -r -p -e robots=off -U Mozilla www.example.com

- -random-wait 0.5 1.5


-r
-e robots=off robots.txt
-U Mozilla User-Agent Mozilla

- -limit-rate=20K 20K
-o logfile.txt
-l 0 5
--wait=1h 1
7.
ALT + . (or ESC + .)
shell emacs

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

$ echo a b c
abc
$ echo <Press ALT + .>
$ echo c

$ echo 1 2 3
123
$ echo a b c
abc
$ echo <Press ALT + .>
$ echo c
$ echo <Press ALT + .> again
$ echo 3
12 n ALT + 1 ( ESC +
1) ALT + 2 ( ESC +2)

$ echo a b c
abc
$ echo <Press ALT + 1> <Press ALT + .>
$ echo a
a
$ echo <Press ALT + 2> <Press ALT + .>
$ echo b
b
"Emacs Editing Mode Keyboard Shortcuts "
8. history
<space> command
Bash shell shell
------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

bash history
(~/.bash_history) $HISTIGNORE shell
HISTIGNORE="&:[ ]*" history
$HISTIGNORE
"The Definitive Guide to Bash
Command Line History"
9.
du -h --max-depth=1
- -max-depth=1 du 1
1 2 2 -h
Mb G

ncdu
10. 10
ps aux | sort -nk +4 | tail

ps aux sort sort


4 tail 10
htop top ps
python SMTP
python -m smtpd -n -c DebuggingServer localhost:1025
Python smtpd -m smtpd ) SMTP
1025

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

-n Python setuid ( "nobody"

-c DebuggingServer Python
localhost:1025 Python 1025 SMTP
25 sudo
root 1-1024
sudo python -m smtpd -n -c DebuggingServer localhost:25

=== ===
1.ASCII
man 7 ascii
asciiascii
Linux Manpage
ascii
manprintfC
printfbashprintfman 3 printfman 1 printf
1
man man
manpages
man 1 intro - Linux
man 2 syscalls -
man 2 select_tut - select()
man 3 string -
man 3 stdio - /
man 3 errno - errornoC

man 4 console_codes - Linux

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

man 4 full - /dev/full""/dev/null

man 5 proc - /proc


man 5 filesystems - Linux
7
man 7 bootparam -
man 7 charsets - gbkgb2312
man 7 glob - glob
man 7 hier - Linux
man 7 operator - C
man 7 regex -
man 7 suffixes -
man 7 time - Linux
man 7 units -
man 7 utf8 - UTF-8
man 7 url - URLURIURN
2.
time read
Enterms
time
$ time ls /opt
...
real 0m0.008s
user 0m0.003s
sys 0m0.007s
realuser
sys
readread LINE
$LINE

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

time read

3.WINDOWS
net rpc shutdown -I IP_ADDRESS -U username%password
WindowsnetRPC
winnet use file:///C|/ip/ipc%24 *IPC

Linuxnetsambasmbclientwindows
rpc
Windowsshutdown
winnetwin
4.SHELL
(cd /tmp && ls)
ls /tmp
shell
shell
Shell`ls /tmp`shell

echo $(echo -e file:///C|/x%24%28printf "%x" 65))


5.SSH
ssh -t host_A ssh host_B
host_B
host_Ahost_B

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

host_B

ssh -t host1 ssh -t host2 ssh -t host3 ssh -t host4 ...


FBI CIA
6.
<CTRL+l>;
reset

tput clear
tputman tput
7.
ping -a IP

4scsi16Redhat

pingaudible ping-aping
8.10
history | awk '{a[$2]++}END{for(i in a){print a[i] " " i}}' | sort -rn | head
historyawksort
head10

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

9.GMAIL
curl -u you@gmail.com --silent "https://mail.google.com/mail/feed/atom" |
perl -ne \
'
print "Subject: $1 " if /<title>(.+?)<\/title>/ && $title++;
print "(from $1)\n" if /<email>(.+?)<\/email>/;
'
GmailAtom feedGmail
atom
perlatomsed/awk
10.TELNET
telnet towel.blinkenlights.nl
ASCIIipv6

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

B Linux Shell
WowUbuntu / Isspy

ShellShell
TIOBE
GUI

ShellShellCPerlPython

Shell
Shell
Shell

Shell
Shell
Advanced Bash-ScriptingBash Guide for Beginners
""unix
""

------ Twitter: @isspy

@Ubuntu_tips @riku / @utips --------

You might also like