strace -f -e trace=network -o /tmp/strace.txt -s 10000 <cmd> <args>
Tag: linux
Bash history substitution trick
I saw the following neat little trick in this link:
# renaming a long file-name using a regex
$ touch config.txt
$ mv config.txt !#:1:s/txt/json
The exact meaning of the !#
is, quoting from the man page:
Event Designators An event designator is a reference to a command line entry in the history list. Unless the reference is absolute, events are relative to the current position in the history list.
! Start a history substitution, except when followed by a blank, newline, carriage return, = or ( (when the extglob shell option is enabled using the shopt builtin).<snipped>
!# The entire command line typed so far.
From ‘man bash’
i.e. most people know that bash can insert things from history using commands like !!
and !50
(i.e. rerun last command and rerun the 50th history item respectively).
But !#
let’s you take something from the existing line and re-use it.
Here is another example, from here:
curl http://beyondgrep.com/ack-2.14-single-file > ~/bin/ack && chmod 0755 !#:3
In this case, !#:3
takes the 3rd element from the existing command. Starting from zero, that turns out to be ~/bin/ack
in this case.
Some nmap one-liners
- Port scan, os detection:
nmap -sS -P0 -sV -O 192.168.0.58
- All active IPs in a network
nmap -sP 192.168.0.*
- Ping a range of IPs
nmap -sP 192.168.0.2-254
- Find unused IPs in a subnet
nmap -T4 -sP 192.168.0.0/24 && egrep "00:00:00:00:00:00" /proc/net/arp
See whitespace with cat
Use this:
cat -v -t -e <somefile>
-e
: Add a trailing$
at the end of a line.-t
: Show tabs as^I
Deleting files with odd names
There’s more than one way. Here’s one: find the inode with ls -i
, then delete with:
find -inum <inode-number> -exec rm -i {} \;
Formatting & wrapping on the terminal
Huh, who knew this existed:
cat <some-verbose-output> | fold -70
-
fold -s
folds at whitespace -
Also look at the
fmt
command, which seems similar to emacs’fill-paragraph
. -
pr
gives a pretty display with margins, headers, and page numbers.