Skip to content

General

GradedJestRisk edited this page Sep 12, 2019 · 17 revisions

Table of Contents

Overview

RTFM : man COMMAND_NAME

Versions, etc..

List:

  • kernel: uname -r
  • distribution: lsb_release -a
  • file manager xdg-mime query default inode/directory

Startup

All mount element in /etc/fstab are mounted on startup (except those with noauto option).

Terminal

Get default terminal (look for *)
sudo update-alternatives --config x-terminal-emulator
Default config file is ~/.bashrc , loaded at terminal start

Aliases

Overview

  • list alias
  • add alias ALIAS_NAME='COMMAND'
  • remove unalias ALIAS_NAME
  • run without alias \command
Sample: list
  • in list
  • directories blue and DIRECTORY_NAME/
  • readable size
  • print only file modification date and file name
  • aligned

Gives alias ls='ls -lFh --color=always | awk '\''{print $5,$6,$7,$8,$9}'\'' | column -t'

Command prompt

Alter PS1 variable in .bashrc
PS1='\u \w $ ' => USER_NAME WORKING_DIRECTORY $

To format the prompt, use ASCII escape sequence

Use escape
Open Body Close
\[ ESCAPE_SEQUENCE \]

Here's the codes

Escape sequence
Need Syntax Full (use around $foo)
red \e[31m \[\e[31m$foo\]
blue \e[36m \[\e[36m$foo\
bold \e[1m \[\e[1m$foo\
reset \e[0m No use with $foo

Always add \[\e[0m\] at end of PS1

Full list of escape codes

To get local-function feedback PS1='$(FUNCTION_NAME) :'

To dynamically return color-code

set_bash_prompt(){
    PS1="[\w] $(COLORCODING_FUNCTION_NAME) \$ "
}
PROMPT_COMMAND=set_bash_prompt

Folder

Overview:

  • list last 5 modified files ls -ltr | tail -5
  • get total size of files in directory matchin pattern du -csh *temp* | tail -1 | cut -f 1

Processes

Identify the binary location of a command
which COMMAND_NAME

Logon

User initialization scripts:

  • main : ~/.bash_profile
  • main in Ubuntu: ’~/.profile`
  • system-wide environment variables /etc/environment
  • all: echo exit | strace bash -li |& less | grep '^open'
Clone this wiki locally