# Debug commands Cheat Sheet

**URL:** <https://www.wago.community/t/debug-commands-cheat-sheet/112>\
**Category:** Hardware and Linux\
**Created:** [June 9, 2022, 7:19am UTC](https://www.wago.community/t/debug-commands-cheat-sheet/112 "2022-06-09T07:19:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![quenorha](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/quenorha/32/429_2.png) [@quenorha](https://www.wago.community/u/quenorha)\
**Post date:** [June 9, 2022, 7:19am UTC](https://www.wago.community/t/debug-commands-cheat-sheet/112/1 "2022-06-09T07:19:15Z")

</div>

Here you will find a list of useful shell commands I use for my daily debugging tasks.  
Please give us your own useful commands !

- Display kernel version information :

```auto
uname -a

```

- Display firmware version :

```auto
cat /etc/REVISIONS

```

- List running processes :

```auto
ps -A

```

- Open an interactive process viewer (with ressources) :

```auto
htop

```

- List processes using the file :

```auto
lsof myfile //where myfile is the filename

```

- List files used by a process

```auto
lsof –p 3255 //where 3255 is the process number

```

- Count all files opened

```auto
lsof | wc -l

```

- List all IP sockets

```auto
lsof -i

```

- List all files opened by a process

```auto
ls -l /proc/3255/fd/

```

- List all TCP connections

```auto
netstat -tap

```

- List all UDP connections

```auto
netstat -udp

```

- List all open ports with associated processes

```auto
netstat -tulpn | grep LISTEN

```

- Display total and used space on file system

```auto
df –h

```

- Display all messages from the kernel ring buffer

```auto
dmesg

```

- Capture and display network traffic on interface br0

```auto
tcpdump -i br0

```

- Capture and display network traffic on interface br0 in ASCII format

```auto
tcpdump -i br0 -A

```

- Capture and display network traffic on interface br0 in HEX format

```auto
tcpdump -i br0 -XX

```

- Capture network traffic on interface br0 and save it to .pcap file (can be open with Wireshark)

```auto
tcpdump -w capture.pcap -i br0

```

- Open .pcap file and display content

```auto
tcpdump -r capture.pcap 

```

- Capture and display TCP packets on interface br0

```auto
tcpdump -i br0 tcp

```

- Capture and display traffic on interface br0 with specific port

```auto
tcpdump -i br0 port 502

```

- Capture and display traffic on interface br0 with specific source ip address

```auto
tcpdump -i br0 src 192.168.0.2

```

- Capture and display traffic on interface br0 with specific destination ip address

```auto
tcpdump -i br0 dst 192.168.0.44

```

---

<div class="post-metadata">

**Author:** ![WagoIcard](https://sea2.discourse-cdn.com/flex016/user_avatar/www.wago.community/wagoicard/32/1508_2.png) [@WagoIcard](https://www.wago.community/u/WagoIcard)\
**Post date:** [June 13, 2022, 11:55pm UTC](https://www.wago.community/t/debug-commands-cheat-sheet/112/2 "2022-06-13T23:55:23Z")

</div>

Advanced use of the “ps” command to print only the top 6 process from CPU usage, memory usage, CPU Time:

> ps -A --format user,uid,comm,pid,pcpu,pmem,time,tty --sort=-pcpu | head -n 6  
> ps -A --format user,uid,comm,pid,pcpu,pmem,time,tty --sort=-pmem | head -n 6  
> ps -A --format user,uid,comm,pid,pcpu,pmem,time,tty --sort=-time | head -n 6

Batch ping an ip range (It return only the alive IP):

> for i in {1…254} ;do (ping 192.168.1.$i -c 1 -w 5 \>/dev/null && echo “192.168.1.$i” &) ;done

Run TCPdump in the background and save a new file automatically after a certain size:

> /usr/sbin/tcpdump -U -i eth0 -w /media/sd/log\_$(date +%Y-%m-%d\_%H%M%S).pcap -C 10 &\>/dev/null &

Print the different port used (With option for filtering what state they are on)

> lsof -i -P -n  
> lsof -i -P -n | grep LISTEN  
> lsof -i -P -n | grep ESTABLISHED  
> lsof -i -P -n | grep CLOSE\_WAIT  
> lsof -i -P -n | grep FIN\_WAIT
