TIL
I created this to keep log of things I learn on daily basis when working on different problems.
Extract Links using CURL
xargs -n 1 curl -sL < 2018.txt | grep -Eo "<title>.*</title>" The command to extract links using curl
curl -sL https://news.ycombinator.com/item\?id\=18740939 | grep -Eo 'href="(https|http):[^\"]+"' Command to extract the links from hackernews
grep -aEo "<title>.*</title>"
-a option to process binary file link to sol
use ``` backticks to run a command in bash
Counting files in directory
To count specific files in the directory you can use the following command
ls *.<file_extension> | wc -l
lets say if you want to see how many css files you have in a directory you might use this command as
ls *.css | wc -l
Generating a Grub File
We can use this command to generate a grub configuration file.
sudo grub-mkconfig -o /boot/grub/grub.cfg
As grub-mkconfig scans hardrives for bootable operating systems such as windows, mac or linux distros
Assigning Programs to Workspaces
To open programs on specific windows when using i3 window mananger add the following to the i3 config
assign [class="<use your program name here e.g. - Firefox>"] $workspace <eg 5>
After adding to the config make sure to refresh i3-msg reload
Resize images on Commandline
In order to resize images using command you can use the convert command.
convert img.jpg -resize 200x200 img-1.jpg
and you can also convert to different extenstions using convert command.
convert img.png img.jpg
If you don't have convert installed you can install from a package manager.
Setting up printer using CUPS
To add a printer on linux use CUPS.
Access the web admin http://localhost:631/
Killing port on Linux
fuser -k <port_name>/tcp use fuser to kill specific ports on linux
Revert Chmod
chmod -x allows you to revert the executable created by chmod +x
Enabling BLuetooth on Linux
In order to enable the bluetooth in Linux especially when using a command line, do the following
sudo systemctl enable bluetooth.service
To stop the bluetooth service
sudo systemctl enable bluetooth.service
Then you can use bluetoothctl to connect or pair devices using bluetooth
Unzip files in Linux
You can unzip .7z extension file using the following command on linux
7za x <file.7z>
Saving a file with root permissions
In order to save a file with root permission using vim you can do
:w !sudo tee %
Vim Notes
These are learning notes when learning vim key bindings
Vim has three modes
INSERT: You can useifor the insert modeVISUAL: You can usevfor visual mode.NORMAL MODE: just pressESCto get into normal mode
Basic Navigation
- In order to get into insert mode use
i. ggtakes you to the first line of the document.Shift-Gtakes you to the last line of the document.- You can also move to the specfic line by
<line number> G. - you can use
xto delete a character. - you can use
uto undo a change. - you can also specific the number of characters you want to delete
<num of char> x - to delete a whole word use
dw. - to delete a line use
dd. - to number of lines use
<num of lines> dd. - to move one word at a time
w.it goes to the beginning character of the word. - to move using last character use
e. - to move number of words use
<num of words> wfor example10 wthis moves 10 words. - to move backward a word you can use
b. - to move number of words backward use
<num of words> b10 b. - use
0to go to the beginning of the line. - you use
pto put a line to desired line number for example you candda line then10 Gand then dopto put the line on line 10 - You can replace a word or a character by using
r. Changeto get into change command you can change words by usingceto get the end of the word.c$to change the entire line- navigating using command
f:(forward <to_word>) and uppercase does this in reverse. for example,fewill take to the character e andFewill take you backward. - to delete a specific line you can do
:<line>d
Different Insert Modes.
Atakes to the end of the line and enters in to insert mode.atakes you into insert mode.Sdeletes the entire line and enters you into the insert mode.sdelete the character and enters you into the insert mode.oenters you into the insert mode in the next line.Oenters you into the insert mode in the preceding line.Cdeletes the entire linec$d$deletes everything from the cursor to the end of the line. You can useDto do the same thing.
Yanking
Its the copy command in the vim editor
- to copy a word just use
ywyou can paste by usingp. yyto copy the entire line.y$to copy from the cursor to the end of the line.Pputs to the preceding line
Searching through the code/doc
/search forward in the doc. then hitnto goto the next instance.?searches backward in the doc.
Replacing
- You can
:%s/oldstring/newstring/gto replace a word - you can also give line numbers
1,2s/old/new/g :%s/old/new/gcgives a prompt.
Executing a command in vim
! <cmd>to execute a commandcntrl-dto see what commands are available
note: you can enable vim mode in zsh by adding bindkey -v to zshrc
VIM Macros
- You can record vim macros by using the
qkey and followed whatever key you want to assign that macro to. - to run the macro number of occurences and key where you saved the macro.
Vim Splits
:splitdoes horizontal split:sp:vsplitdoes vertical split:vscntrl-w ccloses the split.- you can also specific the height when doing a split
10sp <filename> - you can do
cntrl-w Rto swap the split cntrl-w jandcntrl-w kmoves you up and downcntrl-w handcntrl-w lmoves you left and right- you can also resize the splits
vertical resize +5orresize +5for horizontal split. - you can also open terminal in vim. especially in split
:vs | :terminal
Command Mode in Vim.
- you can run shell commands in vim
:! lsthis will print the files of your directory. - you can also read the outputs of the command and add it to the document
:read !date - you can also use ranges when replacing the text
11,16s/old/new/g :g/vim/dthis will delete vim from every line where it finds the word.!g/vim/dthis will delete that will delete that's not vim.g/^/pu/ =\"\n\"puts spaces.g/<word>/m$moves the lines containing that word to the end of the file
Vim Tabs
- You can edit a file in a new tab by
tabedit <filename> - you can
gtto cycle through the tabs.
Few Notes
ddpallows you to swap a line.g/<word>/+1m-2>allows you to indent111,114>:{range} '<,'>' norm A"adds"at the end of the line.:{range} '<,'>' norm I"adds"at the beginning of the line.cgnallows you to change the next instance when doing a search.- you can also set abbreviations
:ab rtfm Read The Friend Manualand usecntrl-vif you don't want to expand it. - Read commandline commands into vim
:r !ls "+yallows you to copy the selection to the clipboard in vim
Deleting Git Branches Locally and Remotely
In order to delete a branch on git locally you can use git branch --delete <branchname> and if you want to do it remotely you can do
git push --delete <branchname>
Deleting Git Commit History
To delete git commit history do the following
git checkout --orphan <new_branch_name>git add -Agit commit --all -m "a message"git branch -D <delete the main branch>git branch -m <rename the new branch to main branch>git push -f origin <new branch>
jinja line break
{% autoescape false %} {{ org.backgroundInfo | replace(ā\nā, ā<br>ā) }} {% endautoescape %}