Linux Notes

Commands to remember

linux
Author

Christian Knudsen

Published

March 18, 2018

mc - midnight commander

Oh the nostalgia. It looks exactly like I remember Norton Commander!

Command: mc

Install: sudo apt install mc

whatis

What does this command do? For when you’ve forgotten what it does.

Command: whatis man

whereis

What it says on the tin. Where is that file?

Command: whereis myfile.txt

ncdu - disk usage

Easily locate those ginormous files that need to be deleted.

Command: ncdu

Install: sudo apt install ncdu

htop - find processes

top in itself is usefull to locate the process that for some reason needs to be killed. htop makes it easy to actually complete the hit.

Command: htop

Install: sudo apt install htop

alias - make your own commands

alias update=‘sudo apt update && sudo apt upgrade’

But that is only temporarily. Add it to your ~/.bashrc file, to make it permanent.

Copy-paste

Ctrl+c and ctrl+v is not working on the console. But ctrl-shift-c/v is.

rsync

I have a Raspberry Pi Zero w, have connected to it using SSH from a laptop running Ubuntu. Now I want to transfer a file from the laptop, to the Raspberry Pi.

sudo rsync /path/to/local/file pi@raspberrypi.local:/home/pi

grep

Searches files for lines matching a regular expression. Useful parameters (or at least parameters I have a regular use for):

-c returns a count of the lines matching.

-n returns the linenumber (in the file) of the matching line.

tail

Returns the last part of a file

-n 6 returns the last 6 lines of the file (standard 10)

cut

Removes sections of lines in a file (or other input)

-d x. Splits the line at x. Use ’ ’ for space -f 1. Select the first field.

wc

Counts stuff in files.

-l. counts the lines in the file (or other input) -w count the words in the file (or other input)

|

Piping. Takes the result of the command in front of it, and pass it to the command after it (and that is the direction. If you find examples on Stackoverflow that will only give the desired result if the direction is reversed, don’t be surprised if it does not work…)

cat

Prints one or more files to standard output (your screen).

But if we print to another output, eg with “> file.name”, we can concatenate several files.

find

Searches for files. “find .” finds everything. Pipe it to grep to search for something specific. eg “find . | grep ‘acta’” to find all files containing the string “acta”.

  • print prints the complete filename.
  • print0 prints the complete filename even if it includes a newline.

csvsql

Commandline tool for analysing csv-files using sql-syntax

csvstat

Commandline tool for analysing csv-files