Tech notes for unix

Insert one file into the middle of another using Sed

Let's say you have a file called file1. And let's also say you have a file called file2.

And within file1 you have this text in the middle of your file: Yusef Lateef.

If you run this command,

sed -e '/Yusef Lateef/r file2' file1

Then below Yusef Lateef in file1 you will find the content of file2.

unix sed

Connect to wifi networks from the Linux command line

You can easily connect to an open network though

iwconfig wlan0 essid "THE NETWORK NAME"

Closed networks work with wpa_supplicant. You normally send a configuration file with that but you can simulate the file with a named pipe:

wpa_supplicant -iwlan0 -c <(echo -e 'network={\n ssid="THE NETWORK NAME" \n psk="THE PASSWORD" \n}') -B

wlan0 is your network interface name. -B means go into the background. The \ns in the configuration file is needed sadly and so we pass -e to echo to interpret them.

iwconfig should show your new connection but perhaps only after a second.

After this dhclient wlan0 will get you a dhcp address and you'll be ready to go. You may want to kill any prior instances of dhclient.


List the open wifi networks from the linux command line

If you want to use the command line and iwlist scan to list all the open wifi networks you can:

a=`iwlist wlan0 scan | grep 'ESSID\|key:' | sed 's/.*ESSID:"\(.*\)".*/\1/g' | sed 's/.*key:\(.*\).*/key:\1/g' | sed 's/\n//'`

This first lists all the networks and grabs the network name and whether there's a key on this network.

This gives us a list of network's key state and the network name.

Let's now join the network key state and the network name into one line with sed 'N;... and swap the variables around to show the network name first.

echo "$a" | sed 'N;s/\n/,/' | awk -F ',' '{print $2" ("$1")"}'

Put these two lines in a bash script and run that to see all the networks and whether they're open networks or not.

unix-wifi unix

Upload to an image to imgur from the command line with curl

First, go to and register as a client. Create a new client and you'll eventually get a Client ID and a Client secret.

Now take the client ID, and use this curl command:

curl --request POST --url --header 'authorization: Client-ID YOUR_CLIENTID_HERE'   
--header 'content-type: multipart/form-data;' -F "image=@/LOCATION/OF/THE/IMAGE.png"

You should get some JSON back like this:

unix imgur unix-curl

Upload an image to an imgur album from the command line with curl

First make sure you have a client id through registering at

Then make a command to create an album:

curl --request POST   --url   
--header 'authorization: Client-ID YOUR_CLIENT_ID'

This will return an anonymous public album. Note the 'deletehash' id in the below:


The empty album is available at

Now let's upload an image to that album. Because it's public and anonymous we need to use the deletehash as the album ID:

curl --request POST   --url   --header 'authorization: Client-ID YOUR_CLIENT_ID'   
--header 'content-type: multipart/form-data;' -F "album=THE_DELETE_HASH" -F "image=@/PATH/TO/THE/IMAGE.png"

The json returned should say everything is okay. Upload a couple of images to that album and you should be able to see them at

You can get a json response of all the images in that album through `curl --request GET --url --header 'authorization: Client-ID YOUR_CLIENT_ID'. It will include the array of images:

"images":[{"id":"ANOTHER_ID",... link":"https:\/\/\/ANOTHER_ID.png"},...]

The link property is the direct link to the image without all the html around it.

unix imgur unix-curl

Page 2 of 13
prev next
Click me