Frequently Used Commands - tlam/Wiki GitHub Wiki

  1. Grepping multiple keywords(CRITICAL, ERROR or WARNING) from a file:

     grep -E "CRITICAL|ERROR|WARNING" log.txt
    
  2. Remove all files of a specific extension:

     find . -name "*.pyc" | xargs rm
    
  3. Testing a new domain name In @/etc/hosts@, set the server's IP to the new domain name:

     xx.xxx.xx.xx  my-new-domain-name.com
    
  4. Delete files older than 5 days

     find . -name "*.css" -mtime +5 -delete
    
  5. Find for a specific pattern(Country) in a file(*.py) and excluding searching in a specific folder(migrations)

     find . -name "*migrations*" -prune -o -name "*.py" -print | xargs grep "Country"
    
  6. Tar and gzip a folder

     tar -cvf my_folder.tar my_folder/
     gzip my_folder.tar
    
  7. Changing default subversion user

  • Remove the file containing the current user from @.subversion/auth/svn.simple@
  • Run an svn up and specify the new username
  1. Search for a keyword in specific files

     find . -name "*.py" -print | xargs grep "print" -n
    
  2. Determine public IP

     curl http://api.externalip.net/ip
    
  3. Top - The three load-average values in the first line of top output are the 1-minute, 5-minute and 15-minute average.

  4. Unzip a bz2

     tar -xvjpf somepackage.tar.bz2
    
  5. Running memcached on Mac

     memcached -d -p 11211
    
  6. Find all symlinks from the current directory:

     find . -type l -exec ls -l {} \;
    
  7. Trace and ping together or online http://www.websitepulse.com/help/testtools.mtr-test.html:

     mtr stackoverflow.com
    
  8. Show which processes are using a file, sometimes it only works with sudo

     fuser logfile.log
    
  9. Testing slow response from website

     time curl -v https:/example.com
    
  10. Get public IP from server:

     dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
    
  11. Check network connection to a rabbitmq server

     nc -v somequeue 5672
    
  12. Check deleted opened files

     lsof | grep deleted
    
  13. Check inodes usage

     df -i
    

vi

  1. .vimrc

     set tabstop=4
     set shiftwidth=4
     set expandtab
     set autoindent
    
  2. Delete all lines with keywords:

     :g/somekeywords/d
    
  3. Search and replace

     :%s/search_string/replacement_string/g
    
  4. Remove ^M characters:

     :%s/[ctrlkey+v and ctrl-key+M]//g
    
  5. Copy entire file to clipboard(Mac):

     :%w !pbcopy
    
  6. If the colour scheme is too bright on a white background, try the following colour scheme under .vimrc:

     colorscheme delek
    

Vim Pathogen

  1. Create the folder .vim/bundle if it does not exist

  2. From .vim/bundle, install vim-pathogen:

     git clone https://github.com/tpope/vim-pathogen.git
    
  3. In your .vimrc file, add the following to the top:

      " enable vim-pathogen
      runtime bundle/vim-pathogen/autoload/pathogen.vim
      execute pathogen#infect()
    
  4. You can then install custom themes such as onedark under .vim/bundle with:

     git clone https://github.com/joshdick/onedark.vim
    
  5. Activate the theme by adding the following in your .vimrc:

     colorscheme onedark
    

Apache

Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

Assuming your server has hostname lnx-something and IP a.b.c.d, add the following line in /etc/hosts:

    a.b.c.d lnx-something

Understanding Apache, SSL, VirtualHost

  1. NameBasedSSLVHosts
  2. CommonMisconfigurations
  3. SSL vhosts
  4. NameBasedSSLVHostsWithSNI

VMWare

  1. A VM can made accessible to a network by:

     Virtual Machine > Settings > Network
    

Change the network adapter is configured to: Connect directly to the physical network (Bridged) Using: Autodetect

  1. Speed improvement on Mac. If your mac runs VMWare Fusion and the laptop is slow, shut down printer sharing.

    1. Select VMWare Fusion
    2. Virtual Machines > Settings > Printer
    3. Toggle Share Mac printers with Linux to OFF

Regular expression tester

Regex 101

RabbitMQ

Check for any pending messages:

sudo rabbitmqctl list_queues name messages messages_unacknowledged messages_ready consumers

SASS

In case of the following error Error: File to import not found or unreadable: compass, set the SASS_PATH:

export SASS_PATH=$BASE/static:$BASE/other_locations

Virtual Box

Use Bridged Adapter to allow ssh into the guest vm. Another way: http://stackoverflow.com/questions/5906441/how-to-ssh-to-a-virtualbox-guest-externally-through-a-host

Vagrant - Run specific tags

In the Vagrantfile, set the tags

ansible.tags = "some-task"

Running vagrant provision will only run some-task

Alternatively:

ANSIBLE_TAGS="some-tasks"; vagrant provision

Ansible

Private keys can have their new line characters preserved by storing them between single quotes in the vault file, for example:

private_key: '----PRIVATE KEY---- abc\n123\ndef\n---'

ZSH