File operations

Remove files

Sometimes a file starts with a dash (-), for example, you ended up with a file named "-help". (don't ask me how you did it...) Of course you can remove the higher directory, but there are other ways of removing this file:

rm -- -help
rm ./-help

Change files

Change the serial of a zone file. This is for BSD.

sed -i '' 's/2020022301/2020022302/g' filename

Extract files

Extract all files out of an image.

binwalk --dd='.*' file.bin

Mount ISO partitions

This is a raspberry pi image:

user@wks010~/Download$ sudo parted disk.bin unit s print
Model:  (file)
Disk /home/user/Download/disk.bin: 581632s
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End      Size     Type     File system  Flags
 1      8192s   49151s   40960s   primary  fat16        boot, lba
 2      57344s  581631s  524288s  primary  ext2

To calculate the offset, its in this case the start value times 512, so 8192 * 512 = 4194304

user@wks010~/Download$ sudo mount -o loop,offset=4194304 /home/user/Download/disk.iso /mnt/mydisk

List operations

Sort IP adresses

Sort a list of IP adresses.

sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4

Thanks: https://www.madboa.com/geek/sort-addr/

Processes

Kill processes

Kill your current process.

kill -9 $$

Networking operations

Scan PTR records

Do a reverse scan of an IP range.

for i in `seq 1 254`; do host 192.168.1.$i 8.8.8.8; done |grep pointer

Howto/Shell (last edited 2020-03-07 11:05:16 by Sciuro)