Frequently Used Commands - tlam/Wiki GitHub Wiki
-
Grepping multiple keywords(CRITICAL, ERROR or WARNING) from a file:
grep -E "CRITICAL|ERROR|WARNING" log.txt -
Remove all files of a specific extension:
find . -name "*.pyc" | xargs rm -
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 -
Delete files older than 5 days
find . -name "*.css" -mtime +5 -delete -
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" -
Tar and gzip a folder
tar -cvf my_folder.tar my_folder/ gzip my_folder.tar -
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
-
Search for a keyword in specific files
find . -name "*.py" -print | xargs grep "print" -n -
Determine public IP
curl http://api.externalip.net/ip -
Top - The three load-average values in the first line of top output are the 1-minute, 5-minute and 15-minute average.
-
Unzip a bz2
tar -xvjpf somepackage.tar.bz2 -
Running memcached on Mac
memcached -d -p 11211 -
Find all symlinks from the current directory:
find . -type l -exec ls -l {} \; -
Trace and ping together or online http://www.websitepulse.com/help/testtools.mtr-test.html:
mtr stackoverflow.com -
Show which processes are using a file, sometimes it only works with sudo
fuser logfile.log -
Testing slow response from website
time curl -v https:/example.com -
Get public IP from server:
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com -
Check network connection to a rabbitmq server
nc -v somequeue 5672 -
Check deleted opened files
lsof | grep deleted -
Check inodes usage
df -i
vi
-
.vimrc
set tabstop=4 set shiftwidth=4 set expandtab set autoindent set re=0 set mouse=r filetype plugin indent on syntax on -
Delete all lines with keywords:
:g/somekeywords/d -
Search and replace
:%s/search_string/replacement_string/g -
Remove
^Mcharacters::%s/[ctrlkey+v and ctrl-key+M]//g -
Copy entire file to clipboard(Mac):
:%w !pbcopy -
If the colour scheme is too bright on a white background, try the following colour scheme under
.vimrc:colorscheme delek
Vim Pathogen
-
Create the folder
.vim/bundleif it does not exist -
From
.vim/bundle, installvim-pathogen:git clone https://github.com/tpope/vim-pathogen.git -
In your
.vimrcfile, add the following to the top:" enable vim-pathogen runtime bundle/vim-pathogen/autoload/pathogen.vim execute pathogen#infect() -
You can then install custom themes such as onedark under
.vim/bundlewith:git clone https://github.com/joshdick/onedark.vim -
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
VMWare
-
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
-
Speed improvement on Mac. If your mac runs VMWare Fusion and the laptop is slow, shut down printer sharing.
- Select VMWare Fusion
- Virtual Machines > Settings > Printer
- Toggle
Share Mac printers with LinuxtoOFF
Regular expression tester
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---'