Tag Archives: Command Line

OwnCloud webapp not reflecting true list of files

If you’re using OwnCloud and have a process whereby your add or remove files from directories via some sort of server process, you may find that you need to force OwnCloud to update/rescan the file listing. To do so you can manually run the following command…

sudo -u username php /path/to/owncloud/console.php files:scan --all

You may also want to consider adding it to the crontab for “username” on a daily basis.

Thanks to this site for pointing me in the right direction.

Sendmail isn’t sending to domain.com : Linux

Say you’re using sendmail to relay email on a web server that you own that’s named “domain.com”, and email is being delivered fine to any domain except domain.com. What could be the problem?

  1. Rename your server. No server should be named with an actual domain name.
  2. Change /etc/hostname to the new name for your server
  3. Update /etc/hosts to remove the domain name and replace with the new hostname
  4. Remove the domain name from /etc/mail/local-host-names
  5. Restart sendmail “sudo service sendmail restart”
  6. Restart your server “sudo reboot”

Once you’ve done that test sendmail out like so…

echo "command line test" | mail -s "Sendmail test" me@domain.com

Improved Linux command history

With four lines setup one time you can type the beginning of a command (ex: “ls”) then press the up and down arrows to see the most recent commands containing the text you typed (ex: “ls ~/scripts”) making it much easier to find what you’re looking for. To make this happen, create a text file called .inputrc in your home folder and put the following four lines inside:

"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on

Access a Console (including CYGWIN) from Notepad++

If you’re regularly in Notepad++ you may find the NPPConsole to be a huge help. With it you can access a windows console or even cygwin if you prefer (I do). To get started…

  1. Download the NPPConsole Plugin
  2. Extract the dll to your n++/plugins directory
  3. Restart Notepad++ if it was already running
  4. Use the Plugin Manager to make sure the plugin is available

If you want to just use the Windows console (DOS) you should be all set. To integrate with CYGWIN…

  1. Choose Plugins -> NppConsole -> About…
  2. In “Command to run” enter: C:\cygwin\bin\bash.exe ${–login -i}
  3. In Line number pattern after file name enter: :${LINE}

Linux ls output colors

If you’ve used linux much and your terminal is set to display files and directories in color, you know how frustrating it can be to have dark blue text on a black background like so (I’ve seen it much worse too)…


If you would like to modify the output so the colors are a bit more readable, you can add the following to your .bashrc file…

alias ls='ls --color'
export LS_COLORS

which will produce an easier to read version like so (with directories yellow, files a crayon/teal, and executable files red)…


As pointed out in this article

The first line makes ls use the –color parameter by default, which tells ls to display files in different colours based on the setting of the LS_COLORS variable.

The second line is the tricky one, and what I have worked out so far has been by trial and error. The parameters (di, fi, etc.) refer to different Linux file types. I have worked them out as shown

di = directory
fi = file
ln = symbolic link
pi = fifo file
so = socket file
bd = block (buffered) special file
cd = character (unbuffered) special file
or = symbolic link pointing to a non-existent file (orphan)
mi = non-existent file pointed to by a symbolic link (visible when you type ls -l)
ex = file which is executable (ie. has ‘x’ set in permissions).

The *.rpm=90 parameter at the end tells ls to display any files ending in .rpm in the specified colour, in this case colour 90 (dark grey). This can be applied to any types of files (eg. you could use ‘*.png=35’ to make jpeg files appear purple.) As many or as few parameters as you like can go into the LS_COLORS variable, as long as the parameters are separated by colons.

Using trial and error (and a little bash script I wrote… my first one ever! 🙂 I worked out all the colour codes, at least my interpretation of them –

0 = default colour
1 = bold
4 = underlined
5 = flashing text
7 = reverse field
31 = red
32 = green
33 = orange
34 = blue
35 = purple
36 = cyan
37 = grey
40 = black background
41 = red background
42 = green background
43 = orange background
44 = blue background
45 = purple background
46 = cyan background
47 = grey background
90 = dark grey
91 = light red
92 = light green
93 = yellow
94 = light blue
95 = light purple
96 = turquoise
100 = dark grey background
101 = light red background
102 = light green background
103 = yellow background
104 = light blue background
105 = light purple background
106 = turquoise background

Determine Default Java JVM HeapSize

In the life of a Java developer every now and then you’ll have one of your apps run out of memory. While this is usually due to poor coding (not closing resources, or managing large files) it helps to know exactly what the defaults are for your system. I had just this need today so went out looking for an answer.

What I found that was the most helpful was this page, but for quick reference here’s how to do it on Windows…

c:\>java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"
    uintx InitialHeapSize                          := 266634176       {product}
    uintx MaxHeapSize                              := 4267704320      {product}
    uintx PermSize                                  = 21757952        {pd product}
    uintx MaxPermSize                               = 85983232        {pd product}
     intx ThreadStackSize                           = 0               {pd product}
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

Note that the values returned are in bytes so throw them into google to convert them into something useful 🙂

Pass a Command Line Argument to an Alias

Ever want to pass in a command line argument to an alias? You would think you could just do it with $1, but actually you have to create a function and then call that function. So, for instance if you want to pass a portion of a log file name, you could set your alias like this…

alias catlog='function _catIt() { cat /var/logs/$1.log; };_catIt'

then, when you want to see the XX00D log, you just call your alias like so…

catlog XX00D

Checking and Maintaining Linux Disk Space

Ever need to find out what’s using the most space on your Linux box? There are a couple commands that will help make things easier…

To find out how much space you have use:

df -h .

Which will give you output like so…

Filesystem      Size  Used Avail Use% Mounted on
/dev/sda         20G   15G  4.2G  79% /

To list out the directories using the most space, use this handy command…

sudo du /usr/local | sort -n

… where /usr/local is the directory you want info for (you can also just start from root: /)

Learning VIM

So you would think that as a programmer for many moons now that I would have considerable experience in VIM and VI, but I’m hear today to admit that I am not. For years I’ve gotten by with my favorite Windows text editor notepad++, but the geek in me wanted to know why everyone loves Vim so much. To that end the 2 things I started with are…

I can’t say I’m a convert yet, but it’s always nice to have another tool in the toolbelt. Here for your and my reference is my quick VIM cheat sheet.

Connect to DB2 via UNIX Command Line

To access DB2 via the command line on a UNIX/Linux box you need…

  • The DB2 client installed on the box
  • The DB you’re trying to connect to cataloged in the client

Once you know you have that, simply source your db2profile and connect…

. /path/to/db2profile
db2 connect to DBCATNAME user yourid using yourpw

… where DBCATNAME is the name the DB is cataloged as on that box, yourid is your user ID for connecting to the DB, and yourpw is your password for connecting to the DB. Note, that if the actual database resides on the same box, and you want to login as the user your logged into the UNIX box as, you can simplify the connect string and not have to include your user ID or password…

. /path/to/db2profile
db2 connect to DBNAME