Skip to content

Instantly share code, notes, and snippets.

@tachesimazzoca
Last active May 5, 2019 11:36
Show Gist options
  • Select an option

  • Save tachesimazzoca/2a7f53e7d74d5f91f6f917ba76ce6c31 to your computer and use it in GitHub Desktop.

Select an option

Save tachesimazzoca/2a7f53e7d74d5f91f6f917ba76ce6c31 to your computer and use it in GitHub Desktop.
Un*x Cheat Sheet

Un*x Cheat Sheet

tail

$ tail -f /path/to/multibyte.log | while read LINE; do echo $LINE | iconv -f <from-encoding>; done

ls

Listing all the files and directories in the current directory, excluding . and ..:

# The stat command has some difference in its options between GNU's and BSD's.
ls -d * .[!.]* .??* | sort -u | while read x; do stat "$x"; done

iptables

# List rules
$ iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

# Add rules
$ iptables -A INPUT -p tcp -s localhost --dport 25 -j ACCEPT
$ iptables -A INPUT -p tcp --dport 25 -j DROP
$ iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
ACCEPT     tcp  --  127.0.0.1            0.0.0.0/0           tcp dpt:25
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:25
...

# Delete a rule by its line number
$ iptables -nL --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  127.0.0.1            0.0.0.0/0           tcp dpt:25
2    DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:25

Chain FORWARD (policy ACCEPT)
...

$ iptables -D INPUT 2
$ iptables -nL --line-numbers
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination
1    ACCEPT     tcp  --  127.0.0.1            0.0.0.0/0           tcp dpt:25

Chain FORWARD (policy ACCEPT)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment