ranger

Updated: 20 May 2023

https://github.com/ranger/ranger

A console file manager with VI key bindings.

Basic file management. Select file and then

:copy
:paste
:rename <newname>
:delete

Hidden files

:set show_hidden true|false

Rename

cw – set a completely new file name.
A – to append to extension.
a – to append to filename, before the extension.

sed

Updated: 24 July 2024

sed maintains two data buffers: the active pattern space, and the auxiliary hold space. Both are initially empty.

By default, sed reads a line from the input stream, removes the newline character and places it in the pattern space, then continues to process all commands in order. Commands without addresses affect all lines. Commands with addresses affect matching lines.

When the end of the script is reached, unless the -n option is in use, the contents of the pattern space are printed out, adding back any trailing newline. Then the cycle restarts with the next input line.

Unless special commands (like D) are used, the pattern space is deleted every two cycles. The hold space, on the other hand, keeps its data between cycles (see commands h, H, x, g, G to move data between both buffers).

Examples

Find and replace

sed -i -e 's/few/asd/g' hello.txt

-e the script to be executed.
-i edit file in place

Delete lines which contain the match

sed '/pattern/d' my-file

Delete blank lines

sed -i '/^\s*$/d' migration.php

Change lines

sed -i 's/^INSERT INTO.*$/-- INSERT was here/g' doctrine_migration.php

Delete a line from files in current and sub-directories, recursively

find . -type f -exec sed -i '/pattern/d' {} +

Find all named files and add a new line to each before line 11

find . -name "index.html" -exec sed -i 11a\ '<link rel="icon" href="/favicon.jpg">' {} \;

Target the last character of the last line of a file

sed '$s/}$/foo}/' Version20201006122408.php

Find and replace a string containing a backslash character

$ echo "example\.com" | sed 's|example\\\.com|mydomain\\\.com|'
mydomain\.com

Remove all trailing whitespace

sed -i -e 's/[ \t]*$//' messy_file.php

Add a line before a line

sed -i '/pattern-in-target-line/i text-of-line-to-add' file.php

less

Updated: 20 April 2023

Open file scrolled to the end:

less +G app.log
  • + run a command when the file is opened
  • G jump to end

date

Updated: 06 July 2024

Display the current time

date

Convert a timestamp to human readable date

date -d @641288145

Print Coordinated Universal Time

date --utc

Current Unix epoch time

date +%s

grep

Updated: 23 February 2025

Find all occurrences of foo in directories and files recursively, from the current directory

# -i: case insensitive
# -r: recursive but don't follow symlinks
# -n: show line number
# --text: treat binary files as text

grep -irn --exclude-dir=dir --text foo *

Interpret PATTERNS as --fixed-strings, not regular expressions

grep -F './dir/dir2' file.txt

Read-in a long regex, from a file

cat grep-me.log | grep --file=long-regex.txt

Word boundary

Search for the whole word 96730

grep "\<96730\>" app.log

Multiple patterns

Search for several patterns at once

grep 'pattern1\|pattern2\|pattern3' log.txt

Surrounding context

Find tell in trans.sql and show 3 lines of context surrounding the result

grep -C 3 tell trans.sql

Show 3 context lines before and 2 lines after matches

grep -B 3 -A 2 bar index.php

Show --only-matching parts of the matching line

grep -o foo index.php

curl

Updated: 12 November 2025

Ask for HTTP headers only

curl --head https://christaylordeveloper.co.uk

Write output to file instead of stdout

curl http://some.url --output <file>

Basic HTTP server authorisation

curl -u user:pass http://some.url
# or
curl http://user:pass@some.url

Make the operation more talkative

curl --verbose https://www.google.com

By default, every secure connection curl makes is verified to be secure before the transfer takes place. The --insecure option makes curl skip the verification step and proceed without checking.

curl --insecure https://www.example.com

Follow redirects

curl --location https://www.i-have-moved.com

Pretty print json response by piping through jq command

curl --insecure -X 'POST' \
    'https://localhost/authors' \
    -H 'accept: application/ld+json' \
    -H 'Content-Type: application/ld+json' \
    -d '{
  "Name": "string",
  "email": "string",
  "website": "string",
  "Twitter": "string"
}' | jq