Linux Commands

This is intended to become a catch-all repository of useful commands and possibly some helpful tips. We'll see how it works out. :-)

Online manpages: Ubuntu | die.net

Wi-Fi Scan

nmcli d wifi
(source) - See also linssid (graphical) and wavemon (text-based). Wavemon shows hidden SSIDs.

Remove Old Kernels

echo $(dpkg --list | grep linux-image | awk '{ print $2 }' | sort -V | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep linux-headers | awk '{ print $2 }' | sort -V | sed -n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo apt-get -y purge
(source)

ifconfig Replacement

 $ ip a

traceroute Replacement

 $ mtr -r HOSTNAME

or

 $ mtr --report HOSTNAME

These are faster because they don't resolve host names:

 $ mtr -rn HOSTNAME

or

 $ mtr --report --no-dns HOSTNAME

View Disk Space Usage

ncdu(1) (for NCurses Disk Usage) is a utility for seeing what directories are using your disk space.

 $ ncdu

Browse an SMB Network

This is similar to the "Network Neighborhood" found on Windows computers (except it's better).

 $ smbtree

Discover LAN Hosts

 $ netdiscover

or use passive mode

 $ netdiscover -p

Vim Run Control

This is a sample ~/.vimrc file that, among other things, defaults to colors suitable for a dark terminal background. Chances are you'll want to make some adjustments.

""""""""""""""""""""""""""""""""""""""
" ~/.vimrc - run-control file for Vim

" Switch to colors for a dark background and tweak the default color of comments.
if has("syntax")
  set background=dark
  highlight Comment ctermfg=DarkCyan
endif

" Have Vim jump to the last position when a file is reopened.
if has("autocmd")
  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
endif

" Make the completion menus readable
highlight Pmenu ctermfg=0 ctermbg=3
highlight PmenuSel ctermfg=0 ctermbg=7

" Remap : to ; for faster entering of commands.
nore ; :
nore , ;

" Accommodate some command-typos.
:command WQ wq
:command Wq wq
:command W w
:command Q q

" Load indentation rules and plugins according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif

" Indent 4 spaces instead of tabs
set shiftwidth=4
set softtabstop=4
set expandtab
" Alt.: Use hard tabs for indent
"set shiftwidth=4
"set tabstop=4

" Highlight searches
set hlsearch
" Map <C-L> (redraw screen) to also turn off highlighting until the next search.
nnoremap <C-L> :nohl<CR><C-L>

" These cause vim to behave a lot differently from regular Vi.
set cul               " Highlight the curent line.
"set showcmd           " Show (partial) command in status line.
"set showmatch         " Show matching brackets.
"set ignorecase        " Do case insensitive matching
"set smartcase         " Do smart case matching
"set incsearch         " Incremental search
"set autowrite         " Automatically save before commands like :next and :make
"set hidden            " Hide buffers when they are abandoned
"set mouse=a           " Enable mouse usage (all modes)
"set cmdheight=2       " Set the command window height
"set autoindent        " Use filetype-specific indenting
"set nostartofline     " Allow non-vi-like behavior start-of-line behavior
"set backspace=indent,eol,start  " Allow non-vi-like backspacing behavior

Run a Program Remotely

 $ ssh -Y <Remote IP>

Show Installed RAM

If you're exploring upgrading a machine's RAM boot into Linux and run this command:

 $ sudo lshw -short | grep DIMM
 $  sudo dmidecode --type 17

Show Detailed System Information

See also: Ubuntu manpage |

 $ inxi -Fxzc0

 -F Full output
 -x add verbosity
 -z Hide MAC address
 -C0 Color Scheme 0 (monochrome)

Optionally show some unique-identifying information.

 $ sudo inxi -FxZc0

 -Z override the "IRC filter"
Page last modified on January 28, 2020
Powered by PmWiki