Utilities
lnav
Very handy tool to view the log files for 3 reasons,
- It mixes the files in the given directory on time stamps, latest last
- It has tail -f functionality by default
- You don't have to run it as root.
It also has coloring but that does not add that much.
Usage :
| lnav | |
|---|---|
nmap
To find out the hard way to see what servers are running in a network segment you can do :
| nmap | |
|---|---|
... And get a cup of coffee...
passwords
A password generator
This entry is just here because i keep forgetting the name. Usage :
It generates password that are strong BUT rememberable. Example :
pwgen
Easy generator for password that are easy to remember for humans. apt-get install pwgen pwgen Some tweaking can be done , for instance longer passwords and rules about numbers and capitals. The default is 8 characters but you could make : pwgen -0 -A 20 For passwords with no numbers and no capitals, 20 characters long :
pwqgen
Even better : apt-get install passwdqc pwqgen You will get passwords like : bump4Ordeal=Trial Sneak$male=Other And my all time favourite : invent2lick_Neatly For overall safety, i ran this through howsecureismypassword.
- pwgen standard, 8 digits (iequ1Zee) gives 15 hours protection
- pwgen 10 , 10 digits (fai7aquieV) gives 6 years protection
- pwqgen, 18 digits (Fuzzy4venice_pierce) : 5 quintillion years
So this all depends on how lazy you are, or how frustrated you get when you mistype a password. For this i did a test on weather backspace work within a password entry :
- ssh : yes
- main login screen linux : untried yet
- windows : untried yet
ink
| ink | |
|---|---|
Ok not helpful but it works. And the other printer :
| ink | |
|---|---|
| output | |
|---|---|
text utils
Find
find is a useful unix command which i usually use in combination with grep
| find | |
|---|---|
But it can also be used directly as in :
| find | |
|---|---|
Though this is more typing it can be useful when you use the exec option for find. The next command for instance will recursively remove all class files from a java tree :
| exec | |
|---|---|
For an alternative to this with a more rememberable syntax, see xargs below.
Xargs
xargs is a nice way to turn output of other commands into executable commands. So you can for instance put the output of find trough xargs and execute a command for all names that find has found. An example is the removal of all .svn directories in a source tree.
| xargs | |
|---|---|
If you are afraid of using it, this version would first print all files.
| xargs | |
|---|---|
But not always the argument appears as the last item on the line, you can steer this with the -I option
| arguments | |
|---|---|
I use {} here because it corresponds with the find -exec syntax, but this would work just the same :
| arguments | |
|---|---|
when using vim, you might get into problem with the tty handling. This will work but not quite perfect.
| find | |
|---|---|
don't use xargs with vim, but use : vim $(find -name 'x')
Note that -l means only print the file and stop after the first match, ideal for editing the search result.
Without an explanation, or see if you understand this : https://superuser.com/questions/336016/invoking-vi-through-find-xargs-breaks-my-terminal-why
Use the -o option :
| works but vim $() works better | |
|---|---|
The -o option is non standard, if absent or always use vim $(find -name 'x')
This is the easiest way to edit a list of find results:
| vim version | |
|---|---|
grep
Some option you might want to permanently add to your search line :
| grep | |
|---|---|
- -s : be silent about files that cannot be opened like access rights
- -I : do not include binary files
- -r : recursive search
unrar
Simple tip: do not install unrar-free, it does not work : apt-get install unrar
Ctags
typescript ctags
This .ctags file should be able to generate a tags file for typescript :
It does work well indeed but it does not handle local member functions only public private and protected ones. A small alteration in the next line fixes that :
| fix | |
|---|---|
This is a regular expression that recognizes a member function. :
| member functions | |
|---|---|
This version gives far more lines in the tag file than before.
java ctags
Ctags can be used for java, with one problem, that it uses dot notation which you want to be resolved as well. If you use ctags normally : ctags -R src You get entries like :
But if you use the special flag : ctags -R --extra=+q src/ It looks like :
You can now use (in vim) :tag XMap.getDistance In the plain ctags file you would always go to the first 'getDistance' encountered. However, it is kind of annoying in normal search mode.
To use the tags file in a directory tree like java usually is structured as, you can use this setting in ~/.vimrc
| zoom out upto root | |
|---|---|
It means look for the file tags in the current directory and than upwards upto root '/'. The ; us the separator. So you could also let it stop in your home directory :
| zoom out upto ~ | |
|---|---|
tree
For dumping a directory tree :
I have had a problem where tree does not show unicode characters : This occurs when you have the LANG environment variable wrong :
Will produce :
| output | |
|---|---|
| without | |
|---|---|
Utf8 is most probably a wrong code, I changed it for user kees Dec 2013. There is discussion that utf8 is used only where a dash (-) is not allowed. But the standard definitely seems to be UTF-8 (capitols AND dash).
ant
Here is a section for ant to run ctags :
| build.xml | |
|---|---|
Vim
syntax
Dart is not yet supported in vim, here is how to install with pathogen.
| dart | |
|---|---|
Add this to the top of ~/.vimrc
Should work now.
auto indent
forget about toggling the various indent methods, use ':set paste' instead.
This is mostly a helpful option, but when you want to paste some text into vim it become a real pain. I used to disable auto indent with something like :
| ~/.vimrc | |
|---|---|
For no auto indent no smart indent and no c indent And reset everything again after pasting.Not only is that a lot of typing, it does not seem to work anymore. Especially with comments, if you paste after a commented line, everything you paste becomes commented. This does work and is shorter.
| ~/.vimrc | |
|---|---|
And afterwards
| ~/.vimrc | |
|---|---|
file type indentation
If you are just annoyed with the indentation rules of one type of file, say .rst files, you only need to create a file called ~/.vim/indent/rst.vim with the following content:
| ~/.vimrc | |
|---|---|
Files ending in .rst will now no longer indent. Rst indentation is particularly annoying because it indents bullet lists etc.
completely disable auto indent
If you really don't want indenting at all.. you can disable filetype based indentation by checking this setting in ~/.vimrc (or a local vim file) :
Yes .. filetype autoindent is off by default, so you should disable these lines. But if you are using InstantRst (see elsewhere in this page), at least the filetype plugin needs to be enabled, so find the entry where InstantRst is installed with vundle, and just remove the indent from this line :
| ~/.vimrc | |
|---|---|
gvim
Related to the previous issue, it seems gvim does not read all settings from .vimrc. To get the horrible autoindentation to stop i added set paste at the end of my .vimrc file, and gvim just blatantly ignores it while it does take other settings like the color scheme !?!? For this the solution is rather simple : create a ~/.gvimrc file and put the option there :
| ~/.vimrc | |
|---|---|
If you run the command :scriptnames you get the list of scripts that gvim reads on startup. .vimrc is a lot earlier than .gvimrc so my guess is one of the plugins in between does the damages, and my guess is this one :
digraphs
For instance to input a euro sign. Vim digraphs are a short way of inserting special characters. Just hit CTRL-k and then 2 keys. Those two keys usually make 'sense' to construct certain characters, like :
You get the idea, but some are not that easily constructed so type :help digraphs for a complete list. Beware that both xterm and rxvt do not show all characters correctly, a view at :help digraphs is handy to see which are. The "Gnome Terminal" program does show a lot (all ?) characters. Some more handy ones :
These could also be entered with CTRL-V +
spelling
Yes, works perfectly :
Set the Language in your .vim.custom file or ~/.vimrc like this:
The bg=dark is in case you can't read the highlighting. Now you can see which words are wrong :
- red highlight: misspelled
- blue highlight: capitalized wrong.
- orange highlight: rare words
Standing on a highlighted word you have a couple of two letter commands, starting with z:
- zg: add the word to the word list : ~/.vim/spell/en.utf-8.add
- z=: display an alternatives list, you can choose by number which one
- ]s and [s to search forward and backward for spelling cases.
Ideal for preparing for a sphinx spell check.
eclipse
getting a stack trace on every exception
On the breakpoints tab (in debug view), you see a button called "J!", this is where you can enter breakpoints for events. You have to add all exceptions you wish to catch, so I took the most general one "Exception" and added that. Untested ... Yet, had no exceptions... Yet ;)
Xapian omega
This is a tool for searching a local site, the search bar on this site uses it. Installation is straightforward :
| install | |
|---|---|
The executable will directly be placed in a /usr/lib/cgi-bin/omega and usable on your site. However you will first have to create your database first. I only got it to work in the directory /var/lib/xapian-omega/data/default for some reason. And the 'default' part did not exist so :
| prepare | |
|---|---|
Yes.. I only got this all working as root, sorry. omindex generates the index database in the given --db path. The first part of --url is the relative path you would use on your website, the second is a physical directory on the system where the files are. Most probably you need to alter the file /etc/omega.conf to point to the correct directories. Test it from the command line :
| test | |
|---|---|
It will prompt for a search term, so on this site "network" would give some result. The output will be html, but if there is an error it will show clearly. If it works, try it as a cgi-bin program. "http://localhost/cgi-bin/omega/omega" The documentation says to put the omega.conf file into /usr/lib/cgi-bin/omega, but it seems to work fine with the file in /etc only.
Visual C++
This is mainly about visual studio 2008. Currently needed for programming windows mobile 5.0 / 6.5.
getting F4 to work
I used to have F4 go to the next error after compilation, but that failed. You can however restore the (correct) setting by choosing :
| F4 | |
|---|---|
Now remember Microsoft ... Do it right the first time or DO NOT CHANGE .
no printf output in the console
Or the "output" window of visual C++. It seems the 2003 pocket pc version does not send the output of printf there, but the 2005 version '''does''' You can see when you switch the platform (at the top of the properties page) you get another emulator as well. So take the mobile 5.0 pocket pc version or higher !!
alternative
Or.. If you need the smart phone version you might try opening the serial console because I saw that my printf()'s went to that window as well (untried on smart phone emulator)
- emulator config file -> configure ->peripherals tab -> enable "create console window for serial port 1"
smartphone vs pocketpc
Actually let's take all Microsoft's flavors :
- SmartPhone : a phone with some extras , usually no touchscreen
- Pocket PC : a PDA with no phone, and WITH a touchscreen
- Pocket PC Phone Edition : a pocket pc with phone functionality built into it
- Portable Media Center : basically a portable music and video player
The HC700 is not a phone and it has a stylus/touchscreen so it must be a pocketpc.
aptitude
Know when to use apt-get and when to use aptitude. For searching it would recommend aptitude, because it also supports wildcards (perl-style regular expression). For instance when searching python modules, you will be clicking next a lot if you search on 'python' when looking for a module. Try instead, if you for instance look for a module with gl in it for :
| aptitude | |
|---|---|
Though gl is a very noisy term, the choices are reduced to about 30. Which you can scan for the one you search for easily.
when not to use
Those instances where you want to uninstall one item and aptitude attempts to wipe the complete gnome installation. It is because that item was part of a meta-package. In those cases : quit aptitude and use apt-get, it will be more surgical and after that aptitude will behave again as well.
: NEVER, hit g g in a row in aptitude !!, there is no way of stopping it destroying your system. Hit g : THEN EXAMINE
Searching the package descriptions
Normally, when you hit '/' in the interface you search term will only apply to the package titles. If you want to search the package descriptions as well, type ~d before the search term, for instance : ~d VRP (did not find anything ;)
swap space and utility
Mostly i needed this for osrm network generation, you don't want to use swap at all but if needed i like to see what is going on. Perfect way to view both the swap space and what is used is this command :
| /proc/swaps | |
|---|---|
It neatly updates what is going on with lines like this :
You will see the swap climbing and when it reaches size, it will probably give an error like this :
| warning | |
|---|---|
Enlarging swap is an option, but more memory is always preferred. However if you don't have memory you could try it with a swap file :
| fallocate | |
|---|---|
This can actually be done while the generation is still going, your watch command will just show the new space without blinking. Cool...
wipefs
Whenever you get an IO error on startup about a disk partition table that cannot be recognized, it is usually a disk previously used as ZFS disk. Linux will keep bothering you about this if you don't wipe the strings in the partition table.
Do not use wipefs -a -f /def/sdX, it will also wipe the partitioning data.
And if you already done it, look at the testdisk section below. If you are going to re-partition anyhow the command -a -f may be your fastest option.
| wipefs | |
|---|---|
Will print only the first offset at which some data is found, it looks something like this :
| offset | type |
|---|---|
| 0x1fe | dos [partition table] |
| 0x23000 | zfs_member [raid] LABEL: bigsafe UUID: 140029292226195743 |
Clearly this is a zfs member and if you really want to reuse it as a normal disk linux will complain about the data at offset 0x23000. You can surgically remove it with this command (-f is needed if it is mounted)
| wipefs | |
|---|---|
But if you than run wipefs without options again you will find there is another offset, and another etc. There are probably 20 of these. You can erase them all (-a) but that would take out the partition table as well (trust me.. i tried).
testdisk
If you did fuck up the partition table in the previous chapter, you might recover it with this tool.
| testdisk | |
|---|---|
It will ask you some questions, which are probably obvious to answer:
- log file : sure why not : [create]
- choose which disk you want to recover
- partition table type : [Intel]
The hit [ Analyze ] ... and prey... If it finds the boundaries back, you just hit [ write ] and in my case i had my disk drive back again !!
blkid
To prevent fstab from failing when you swap disks around, or add new ones, you probably should not use drive letters but UUID in /etc/fstab.
This leads to a recovery prompt when you /dev/sda is not the disk you meant. It should be something like this :
However, how to get this UUID, you can find that all by listing /dev/disk/by-uuid
Ok.. works, you can see by the link that it should be 2956cd13-4956-4114-89a8-335914254cce, but blkid is probably much handier :