Tag Archives: terminal

Splitting a text file into two

Today I was trying to open a text file with a Node.js script and failed, apparently because it exceeded Node’s maximum buffer size. The most straight-forward solution was to split the file in half and open the two new files separately.

How do you split a text file by two, though? With a quick hack using head and tail of course.

head -n 1000 input-file > output1
tail -n +1001 input-file > output2

The + in the tail command tells it to count lines from the top, instead of from the bottom which is the usual case of tail.

Source: unix.stackexchange

Installing rupa/z

z is a command-line tool that would make jumping around your favorite directories much, much faster. It sits in the background and monitors where you cd to often, like a creep. 8-O And whenever you need to change to that ~/pictures/lol/cats directory, all you have to type in is z cats and you’ll be there. How it achieves this feat is by overriding the default cd‘s functionality with a custom shell function. Bad, bad z. :twisted:

Install rupa/z somewhere in your $PATH, say ~/bin.

cd ~/bin
curl -O https://raw.githubusercontent.com/rupa/z/master/z.sh
chmod +x z.sh
source z.sh

You might get a ‘no such file or directory’ error the first time, just ignore that. z works in both bash and zsh. You might need to add the source ~/bin/z.sh line in your .bashrc or .zshrc so it starts up with your shell session.

Update:

Optionally, you can install the z man page as well. Jump to a directory in your MANPATH (you can find these using the command man -w) and download the man file.

cd /usr/local/man/man1
sudo curl -O https://raw.githubusercontent.com/rupa/z/master/z.1

Chocolatey brings package management to Windows

Chocolatey is the topic in the town these days. When it comes to installing software, Windows is far behind most Linux distributions. Chocolatey is a package manager like apt-get on Debian and Ubuntu. Install it by entering the command

@powershell -NoProfile -ExecutionPolicy unrestricted -Command “iex ((new-object net.webclient).DownloadString(‘http://bit.ly/psChocInstall’))” && SET PATH=%PATH%;%systemdrive%chocolateybin

(yes, in a Windows command prompt) and you’re good to go. The list of available packages can be found here. There’s no huge list of apps like in apt-get as yet though. If you want to install, say, expresso, just type

cinst expresso

in the command prompt. It’s said Chocolatey works in Cygwin as well, but I’m yet to try that out.