“   Une rubrique dédié aux différents points clé que je considère basique mais important à connaître pour tout développeur qui se respect :). Cette page n'a pas pour objectif de remplacer un livre mais de lever la curiosité sur certaines commandes que vous pourriez ne pas connaître. Je vai enrichir la page au fûr et à mesure que je repère d'autres points essentiels que j'aimerais vous montrer. J'espère que des développeurs trouveront cet rubrique utile à leur apprentissage.   ”

  • Operation on server
    • connection to a server : ssh root@domainename or ssh root@IPaddress
    • copy a file to a server : scp name_file.tgz root@domaine_name:/path/to/go
    • close server connection : exit
  • .bash_profile file configuration

    This file is located to the root of each user working space ~/.bash_profile

    • set a command alias in the bash_profile : alias aliasname="ls -l"
    • some alias command I find useful :
      • alias ll="ls -l"
      • alias lla="ls -la"
      • alias e="mate"
      • alias o="open"
      • alias ..="cd .."
    • set a environment variable in the bash_profile : export VAR_NAME="application_name"
      • example : export SVN_EDITOR="vi"
    • add environment path in the bash_profile : export PATH=/other/environment/path:$PATH
      • This is useful when you installed a new version of php in /usr/local/bin/ for instance
    • check and load .back_profile : source .bash_profile
      • Do this if you want to stay on the same terminal window after a change to the bash_profile file
  • Dayly used commands
    • Find and remove (here I give 3 options) :
      • find . -name 'something*' -print0 | xargs -0 rm -rf
      • or find . -name "FILE-TO-FIND" -exec rm -rf {} \;
      • or find . -type f -name "FILE-TO-FIND" -exec rm -rf {} \;
    • compress a directory : tar czvf name_file.tgz dir_name
    • extract a compressed (tgz) file : tar xzvf name_file.tgz
    • unzip a compressed (gz) file : gunzip name_file.gz
    • create a symbolic link : ln -s /path/of/the/directory link_name
    • display processes : ps aux
    • download something : curl -O url
    • visualisation de log tout les 10eme de sec : tail -f log.log -s 0.1
    • search pattern in multi-files with file and dir filters and nice display : grep -nrs --exclude=*.phtml --exclude-dir=.svn "word to search" .
      • (if you're running OSX then do run 'sudo port install grep' before to extend grep and use exclude-dir)
    • creating a file containing the command linux : find /path/ -name "filter" > list_result
      • here I write the result to the file list_result
  • Some Apache Command

    In the following, if you're running apache 1 then remove the number 2 on each command lines.

    • starting, restarting or stopping apache :
      • apache2ctl start
      • apache2ctl restart
      • apache2ctl stop
    • enable or disable an apache site on ubuntu :
      • go to: /etc/apache2/site-available/default
      • a2ensite site_name
      • a2dissite site_name
  • Get environment info
    • check if a shell variable exists : echo $ + tab(x2)
    • get environment path used : $PATH
      • useful when you're working on a new unix platform and you want to see where's located all the applications
    • get system and architecture information : uname -a
  • Miscelleanous
    • Cancel current command line : CTRL + C
    • Clear the terminal reading : clear or CTRL + L
  • Daily used commands
    • add and remove file/dir to the repository : svn add /path/to/file_or_dir and svn del /path/to/file_or_dir
    • force to remove the file/dir : svn del --force /path/to/file_or_dir
    • get the file/dir status : svn status /path/to/file_or_dir
    • get repository info (path, revision, etc.) : svn info /path/to/project
    • get log between revision R1 and R2 : svn log /path/to/project -rR1:R2
    • get summarize of the modified file from revision R1 to the current revision : svn diff -r R1:HEAD --summarize
    • Output the content of specified files or URLs with revision and author information in-line : svn blame /path/to/file
  • Project Administration
    • creating repository : svnadmin create --fs-type fsfs /path/to/svn
    • create a new path/dir for a new project : svn mkdir file:///path/to/svn/project -m "Created project directory"
    • importing an existing project : svn import /path/to/project/ file:///home/user/svn/project/trunk -m 'Initial import'
    • checkout the trunk : svn co file:///home/user/svn/project/trunk /path/to/project
    • checkout the trunk and ignore externals : svn --ignore-externals co file:///home/user/svn/project/trunk /path/to/project
    • relocate svn url : svn switch newurl or svn switch --relocate oldurl newurl .
  • Vi modes
    • Insert Mode : i
    • Replace Mode : R
    • Visual Mode : v
    • Visual Block Mode : V
  • The most daily used native vim command
    • delete, copy the line : dd, yy
    • delete, copy the N next lines : Ndd, Nyy
    • go to line N : :N or NG
    • go to beginning and ending of the file : 1G, GG
    • move several lines up and down : Ctrl + u, Ctrl + d
    • save file : :u or :up or :save /path/to/file_name
    • replace pattern with confirmation question : :%s/pattern/replacing_word/gcI
    • go to file under cursor : gf
    • move left, up, down and right N lines : Nh, Nj, Nk, Nl
    • word auto complete : Ctrl + p
    • programming function auto complete : Ctrl + x keep pressing Ctrl and press o
      • example: on php file write 'array_' and then do the command and it will show a list php functions beginning by array_
    • search in file : /pattern
    • search in multi files with file filter : vimgrep /pattern/ **/*.php
    • display last search list result : :cl
    • go to the file search result number N : :cc N
    • place cursor to the next window : Ctrl + ww
    • make a crossfile tag and go the tag : m[A-Z] and '[A-Z]
    • go right word by word on beginning of each word : w
    • go right word by word on ending of each word : e
    • go left word by word on beginning of each word : b
    • open a file or edit new file on a new tab : :tabedit filename or :tabedit
    • reorganize scripts indentation : select block with Ctrl + V then press =
  • My favourite vim extensions with their most used commands
    • NERD_tree (A tree explorer plugin for navigating the filesystem)
      • open menu for editing file and directory : m
      • open file in a new tab : t
    • NERD_commenter (A plugin that allows for easy commenting of code for many filetypes)
      • comment a line or a block : ,c{space} (can be used in visual block mode)
    • BufExplorer
      • open bufexplorer : \be
      • delete a buffer : d
    • CloseTag (Functions and mappings to close open HTML/XML tags)
    • DelimitMate (Provides auto-balancing and some expansions for parens, quotes, etc.)
    • MatchIt (extended % matching for HTML, LaTeX, and many other languages)
    • SnipMate (TextMate-style snippets for Vim)
    • Surround (Delete/change/add parentheses/quotes/XML-tags/much more with ease)
      • swith ' comment to " delimiter : cs'"
  • my .vimrc
    • filetype plugin on
      
      set nocompatible
      set bs=2 "set backspace to be able to delete previous characters. Enable line numbering, taking up 6 spaces
      set number
      
      "Turn off word wrapping
      set wrap!
      
      " highlight search
      set hlsearch
      
      "Turn on smart indent
      set smartindent
      set tabstop=4 "set tab character to 4 characters
      set expandtab "turn tabs into whitespace
      set shiftwidth=4 "indent width for autoindent
      filetype indent on "indent depends on filetype
      
      "Turn on incremental search with ignore case (except explicit caps)
      set incsearch
      set ignorecase
      set smartcase
      
      "Set color scheme
      "set t_Co=256
      " colorscheme desert256
      syntax enable
      
      "Hide buffer when not in window (to prevent relogin with FTP edit)
      set bufhidden=hide
      
      "Have 3 lines of offset (or buffer) when scrolling
      set scrolloff=3
      
      "Set line numbering to take up 5 spaces
      set numberwidth=5 "Highlight current line"
      
      set cursorline
      
      "Turn on spell checking with English dictionary
      "set spell
      "set spelllang=en
      "set spellsuggest=9 "show only 9 suggestions for misspelled words
      
      " key mapping for some vim extensions used
      nnoremap   :TlistToggle
      nnoremap   :NERDTreeToggle
      nnoremap  m :NERDTreeMirror
      
      " statusline
      set statusline=%t\ %y\ format:\ %{&ff};\ [%c,%l]
      set laststatus=2
                      

  • Mysql command lines
    • select a db : use db_name
    • execute a sql script from a file : source /path/to/file
    • display select result on vertical format : select request\G
  • Mysql operation after install
    • put a password to the root user :
      • SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
      • SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
      • SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');
    • remove the anonymous user :
      • DROP USER ''@'localhost';
      • DROP USER ''@'host_name';
    • check if you can use query cache : SHOW VARIABLES LIKE 'have_query_cache';
    • set a cache size superior to 40K to be active : SET GLOBAL query_cache_size = 1000000;
    • check cache status : show status like 'qcache%';
    • check cache variables : show variables like 'query_cache%';
  • Mysql operation on each new database creation
    • create a new user with less rights
      • create user 'newuser'@'localhost' identified by 'newuserpwd';
      • grant select,insert,update,delete on newdbname.* to 'newuser'@'localhost';
  • Mysqldump command lines
    • dump a db : mysqldump db_name > dump_file -u root -p
  • Differences between MySAM and InnoDb engines
    • MySAM is faster
    • InnoDb can use query's cache
    • InnoDb can use foreign keys constraint
    • MySAM have a storage file for each table where as InnoDb have only a single storage file for all tables in the db