Skip to main content

20 posts tagged with "bash"

View All Tags

Date created: 2024-09-27

Dump hex code from a binary executable

$ od -A n -t x1 <binary-file>

Where:

  • The -A n flag is short for --address-radix=n, with n being short for "none". Without this part, the command would output an ugly numerical address prefix on the left side. This is useful for large dumps, but for a short string it is unnecessary.
  • The -t x1 flag is short for --format=x1, with the x being short for "hexadecimal" and the 1 meaning 1 byte.

Display hex and string from binary using xxd

$ xxd <binary-file>

Date created: 2024-09-27

Dump octal code from a binary executable

$ od -A n -t o1 <binary-file>

Where:

  • The -A n flag is short for --address-radix=n, with n being short for "none". Without this part, the command would output an ugly numerical address prefix on the left side. This is useful for large dumps, but for a short string it is unnecessary.
  • The -t o1 flag is short for --format=o1, with the o being short for "octal" and the 1 meaning 1 byte.

Date created: 2024-10-01

Crontab for running cron tasks on linux

$ crontab -e

Tasks get updated upon closing the editor.

Manual as provided inside the crontab

# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command

Date created: 2025-02-14

Go wild here

Typically you can use curl to download a file by simply doing

$ curl -o thingy.txt 'https://example.com/text.txt'

This would download it as thingy.txt.

But if you want to keep the original name you can use

$ curl -O 'https://example.com/text.txt'

Urls without a filename in them

If there's no file name attached to the url, you can use the file header as the file name.

$ curl -O -J 'https://example.com/text.txt'

Following redirects

Sometimes a download will silently fail by downloading 0 bytes. An example is downloading from github releases. This can be solved by using the -L flag, which means "follow redirects".

$ curl -JLO 'https://github.com/text.txt'
-O, --remote-name          Write output to a file named as the remote file  
-J, --remote-header-name Use the header-provided filename
-L, --location Follow redirects

Note

Wrapping the url in quotes is recommended to avoid problematic symbols like &.

Date created: 2024-09-23

To immediately start a process as a background job:

firefox &

To run it in the background silenced:

firefox </dev/null &>/dev/null &

The whole story

The above is a shorthand for starting a process normally, then stopping it by hitting <C-z>, and typing bg into the terminal. This resumes the process as a background job. In this scenario its stdout/stderr/stdin are still connected to the terminal - meaning it's not silenced.

Date created: 2024-09-26

Typical usage

Named stash (stash with message)

$ git stash -m 'stash message'

Stash including untracked files

$ git stash -u -m 'stash message'

List stashes, and take note of the index of the one you need

$ git stash list

Apply unstashes a stash, but keeps the stash

$ git stash apply <index-of-stash-to-apply>

Pop unstashes a stash, and removes it from the list of stashes

$ git stash pop <index-of-stash-to-apply>

Date created: 2024-09-23

Resources and links

https://www.reddit.com/r/AskProgramming/comments/wai4i4/comment/ii3jiyk/

Go wild here

#!/bin/bash

set -e

if [ $# -eq 0 ]; then
cat <<EOF
usage: gitlazy [log message]

This script pulls the latest source, adds all files, commits and pushes
back to master. You can run as per the example below

$ gitlazy updated modules for user management
$ On branch master
$ Your branch is up to date with 'origin/master'.
$ Everything up-to-date

EOF
exit 1
fi

git pull
git add -A
git commit -m "$@"
git push

Date created: 2024-09-24

Go wild here

$ grep -R "text to search for" .

Where the . signifies the current directory. This will search recursively for the provided string in all directories under the current one.

Date created: 2024-10-10

Resources and links

https://wiki.documentfoundation.org/ReleaseNotes/7.2#Document_Conversion https://wiki.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options#Tokens_1_to_5

Description

This shit is crazy... look at the links above for some context.

Each of those things after the : column has a meaning, and is mentioned as a "Token" in the documentation.

The linked documentation seems to not be up to date, as it says there are only 9 possible Tokens, and yet, we have like 12 in the command below.

The last token, being -1 is what splits each "wokrsheet" into its own file.

Go wild here

libreoffice --headless --convert-to csv:"Text - txt - csv (StarCalc)":44,34,UTF8,1,,0,false,true,false,false,false,-1 Profile.xlsx --outdir testis