Linux Commands: Difference between revisions
No edit summary |
|||
Line 5: | Line 5: | ||
<source lang="bash">while :; sleep 5; do killall -s SIGHUP1 dd; done</source> |
<source lang="bash">while :; sleep 5; do killall -s SIGHUP1 dd; done</source> |
||
This will force '''dd''' to update its status every 5sec. |
This will force '''dd''' to update its status every 5sec. |
||
== dpkg == |
|||
Package manager for Debian / Ubuntu. |
|||
<source lang="bash"> |
|||
dpkg -L <package> # List files in a package |
|||
dpkg -S <file> # List packages providing given file |
|||
dlocate <file> # ... fast version of dpkg -S (require package dlocate) |
|||
</source> |
|||
== grep == |
== grep == |
||
Line 18: | Line 27: | ||
grep -R PATTERN *.in # Idem, but matching pattern "*.in" also applies to folders. |
grep -R PATTERN *.in # Idem, but matching pattern "*.in" also applies to folders. |
||
</source> |
</source> |
||
== [http://netcat.sourceforge.net/ netcat] == |
|||
TCP-IP swiss army knife |
|||
''(equivalent of the telnet program. Check [[wikipedia:netcat]]. Also known as command '''nc''')''. |
|||
== [http://en.wikipedia.org/wiki/Netstat netstat] == |
|||
Print network connections, routing tables, interface statistics, masqurade connections, and multicast memberships |
|||
<source lang="bash"> |
|||
netstat -atpn #All, tcp, socket program PID, numeric |
|||
netstat -rn #Kernel route table, numberic |
|||
</source> |
|||
When listing sockets (default output), you'll get an output like: |
|||
{| |
|||
|- |
|||
| |
|||
% netstat -at |
|||
Active Internet connections (servers and established) |
|||
Proto Recv-Q Send-Q Local Address Foreign Address State |
|||
tcp 0 0 *:time *:* LISTEN |
|||
tcp 0 0 localhost:mysql *:* LISTEN |
|||
tcp 0 0 andLinux.local:43449 windows-host:x11 ESTABLISHED |
|||
| |
|||
% netstat -atn |
|||
Active Internet connections (servers and established) |
|||
Proto Recv-Q Send-Q Local Address Foreign Address State |
|||
tcp 0 0 0.0.0.0:37 0.0.0.0:* LISTEN |
|||
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN |
|||
tcp 0 0 192.168.11.150:43449 192.168.11.1:6000 ESTABLISHED |
|||
|} |
|||
:;Local Address |
|||
::'''*''' or '''0.0.0.0''' means that the process accepts connection from any interface. |
|||
::'''127.0.0.1''' means it only accepts connection on localhost loopback (and so only connection that originates from local PC as well). |
|||
::Any other IP address means that the process listen on the given port at the given IP address |
|||
== recode == |
|||
<source lang="bash"> |
|||
recode /cl../cr <dos.txt >mac.txt |
|||
recode /cr.. <mac.txt >unix.txt |
|||
recode ../cl <unix.txt >dos.txt |
|||
recode charset1/surface1..charset2/surface2 <input.txt >output.txt |
|||
</source> |
|||
{| class="wikitable" |
|||
|- |
|||
! colspan=2 | charset |
|||
! colspan=2 | surface |
|||
|- |
|||
| '''us''' || ASCII (7 bits) |
|||
| '''/cr''' || Carriage return as end of line (Mac text) |
|||
|- |
|||
| '''l1''' || ISO Latin-1 (ISO-8859-1, Western Europe, 8 bits) |
|||
| '''/cl''' || Carriage return line feed as end of line (DOS text) |
|||
|- |
|||
| '''EUCJP''' || EUC-JP for Japanese (Unix) |
|||
| '''/''' || Line feed as end of line (Unix text) |
|||
|- |
|||
| '''SJIS''' || Shift-JIS for Japanese (Microsoft) |
|||
| '''/d1''' || Human readable bytewise decimal dump |
|||
|- |
|||
| '''ISO2022JP''' || Mail encoding for Japanese (7 bits) |
|||
| '''/x1''' || Human readable bytewise hexidecimal dump |
|||
|- |
|||
| '''u2''' || UCS-2 (Universal Character Set, 2 bytes) |
|||
| '''/64''' || Base64 encoded text |
|||
|- |
|||
| '''u8''' || UTF-8 (Universal Transformation Format, 8 bits) |
|||
| '''/QP''' || Quoted-Printable encoded text |
|||
|} |
|||
== rpm == |
== rpm == |
||
Line 86: | Line 166: | ||
''socat'' can be easily used as a replacement of ''telnet'': |
''socat'' can be easily used as a replacement of ''telnet'': |
||
<source lang="bash">socat tcp:<host>:<port> - #<port> can be a port number or service name (telnet,imap...)</source> |
<source lang="bash">socat tcp:<host>:<port> - #<port> can be a port number or service name (telnet,imap...)</source> |
||
== [http://netcat.sourceforge.net/ netcat] == |
|||
TCP-IP swiss army knife |
|||
''(equivalent of the telnet program. Check [[wikipedia:netcat]]. Also known as command '''nc''')''. |
|||
== [http://en.wikipedia.org/wiki/Netstat netstat] == |
|||
Print network connections, routing tables, interface statistics, masqurade connections, and multicast memberships |
|||
<source lang="bash"> |
|||
netstat -atpn #All, tcp, socket program PID, numeric |
|||
netstat -rn #Kernel route table, numberic |
|||
</source> |
|||
When listing sockets (default output), you'll get an output like: |
|||
{| |
|||
|- |
|||
| |
|||
% netstat -at |
|||
Active Internet connections (servers and established) |
|||
Proto Recv-Q Send-Q Local Address Foreign Address State |
|||
tcp 0 0 *:time *:* LISTEN |
|||
tcp 0 0 localhost:mysql *:* LISTEN |
|||
tcp 0 0 andLinux.local:43449 windows-host:x11 ESTABLISHED |
|||
| |
|||
% netstat -atn |
|||
Active Internet connections (servers and established) |
|||
Proto Recv-Q Send-Q Local Address Foreign Address State |
|||
tcp 0 0 0.0.0.0:37 0.0.0.0:* LISTEN |
|||
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN |
|||
tcp 0 0 192.168.11.150:43449 192.168.11.1:6000 ESTABLISHED |
|||
|} |
|||
:;Local Address |
|||
::'''*''' or '''0.0.0.0''' means that the process accepts connection from any interface. |
|||
::'''127.0.0.1''' means it only accepts connection on localhost loopback (and so only connection that originates from local PC as well). |
|||
::Any other IP address means that the process listen on the given port at the given IP address |
|||
== Miscellaneous == |
== Miscellaneous == |
Revision as of 12:59, 5 November 2008
dd
Convert and copy a file.
dd returns current copy status when sent an HUP signal. Type in another shell:
while :; sleep 5; do killall -s SIGHUP1 dd; done
This will force dd to update its status every 5sec.
dpkg
Package manager for Debian / Ubuntu.
dpkg -L <package> # List files in a package
dpkg -S <file> # List packages providing given file
dlocate <file> # ... fast version of dpkg -S (require package dlocate)
grep
grep -Rsl PATTERN [FILE] # Recursive, no error output, only list filename
grep BASIC-REG-EXP-PATTERN [FILE] # Use classic regexp (like "dma\|DMA")
egrep EXT-REG-EXP-PATTERN [FILE] # Same as grep -E. Use extended regexp (like "dma|DMA")
fgrep FIXED-STRINGS-REG-EXP [FILE] # Same as grep -F. Pattern is a list of strings to match.
grep -n PATTERN [FILE] # Print matched line numbers.
grep -- "-s" [FILE] # Search for text "-s"
grep -e "-s" [FILE] # Search for text "-s" - alternative solution
grep -R -include=*.in PATTERN * # Search recursively through folders, limiting to files matching pattern "*.in"
grep -R PATTERN *.in # Idem, but matching pattern "*.in" also applies to folders.
netcat
TCP-IP swiss army knife (equivalent of the telnet program. Check wikipedia:netcat. Also known as command nc).
netstat
Print network connections, routing tables, interface statistics, masqurade connections, and multicast memberships
netstat -atpn #All, tcp, socket program PID, numeric
netstat -rn #Kernel route table, numberic
When listing sockets (default output), you'll get an output like:
% netstat -at Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:time *:* LISTEN tcp 0 0 localhost:mysql *:* LISTEN tcp 0 0 andLinux.local:43449 windows-host:x11 ESTABLISHED |
% netstat -atn Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:37 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN tcp 0 0 192.168.11.150:43449 192.168.11.1:6000 ESTABLISHED |
- Local Address
- * or 0.0.0.0 means that the process accepts connection from any interface.
- 127.0.0.1 means it only accepts connection on localhost loopback (and so only connection that originates from local PC as well).
- Any other IP address means that the process listen on the given port at the given IP address
recode
recode /cl../cr <dos.txt >mac.txt
recode /cr.. <mac.txt >unix.txt
recode ../cl <unix.txt >dos.txt
recode charset1/surface1..charset2/surface2 <input.txt >output.txt
charset | surface | ||
---|---|---|---|
us | ASCII (7 bits) | /cr | Carriage return as end of line (Mac text) |
l1 | ISO Latin-1 (ISO-8859-1, Western Europe, 8 bits) | /cl | Carriage return line feed as end of line (DOS text) |
EUCJP | EUC-JP for Japanese (Unix) | / | Line feed as end of line (Unix text) |
SJIS | Shift-JIS for Japanese (Microsoft) | /d1 | Human readable bytewise decimal dump |
ISO2022JP | Mail encoding for Japanese (7 bits) | /x1 | Human readable bytewise hexidecimal dump |
u2 | UCS-2 (Universal Character Set, 2 bytes) | /64 | Base64 encoded text |
u8 | UTF-8 (Universal Transformation Format, 8 bits) | /QP | Quoted-Printable encoded text |
rpm
- RPM RedHat Package Manager
- Using RPM: THe Basics (Part I)
- Install commands
rpm -ivh package # Installing a package - verbose and progress bars
rpm -iv -nodeps package # Installing a package (verbose), ignore dependencies
- Query commands
rpm -ql package # List files provided by a package
- To query a package that has not been installed, add -p option to the command:
rpm -qpl package # List files provided by a package
sed
sed [OPTION]... {script-only-if-no-other-script} [input-file]...
sed -n # Silent - suppress automatic printing of pattern space
sed -r # Use extended regular expression
sed -i "s/foo/bar/" *.txt # In-place file modification
References
- The SED Homepage on SourceForge
- The SED FAQ
- The SED man page
- Sed, a stream editor
- The sed one-liners
Regular expressions
The information below is only illustrative. See e.g. Wikipedia page for reference information. The list below is actually for extended regular expressions, which can be obtained in sed using option -r (sed -r).
Regexp | Description |
---|---|
. | Match any character |
gray|grey | Match gray or grey |
gr(a|e)y | Match gray or grey |
gr[ae]y | Match gray or grey |
file[^0-2] | Match file3 or file4, but not file0, file1, file2. |
colou?r | (zero or one) - Match Color or Colour. |
ab*c | (zero or more) - Match ac, abc, abbc, .... |
ab+c | (one or more) - Match abc, abbc, abbbc, .... |
a{3,5} | (at least m and not more than n times) - Match aaa, aaaa, aaaaa. |
^on single line$ | (start and end of line) - Match on single line on a single line. |
When using standard (non-extended) regular expression, some special meta-characters (like the parenthesis ( ), or braces { }) must be quoted with backslash \.
socat
Command-line utility that establishes two bidirectional byte streams and transfers data between them ([1]). socat is the more powerful version of netcat.
socat -ly 'TCP4-LISTEN:143,reuseaddr,fork' PROXY:ton.imap.server:143|TCP:134.27.168.36:8080
ProxyCommand socat - 'PROXY:%h:%p,proxyauth=user:pass|SSL,verify=0|PROXY:my.server:443,proxyauth=user:pass|TCP:big.brother.proxy:8080' #Using v2.0.0 beta
socat can be easily used as a replacement of telnet:
socat tcp:<host>:<port> - #<port> can be a port number or service name (telnet,imap...)
Miscellaneous
- htop
- an improved top command (http://htop.sourceforge.net/index.php)
- iconv
- locale encoding conversions
- konwert
- fancy encoding conversions
- mimencode
- binary file conversion for the mail.;mkfifo
- make FIFOs (named pipes)
- pv, pipeview, pipebench
- monitor the progress of data through a pipe
- reformime
- MIME E-mail reformatting tool
- strace
- trace system calls and signals
- tee
- read from standard input and write to standard output and files
- tree
- List the contents of directories in a tree-like format.
- uuencode, uudecode
- binary file conversion for Unix.
- watch
- Execute a program periodically, showing output full screen