When I was working on my Ubuntu with Vim to write or to view source code, I had no simple way to find certain functions scattering in the files by their name or key words.
Now I have one useful tool which is named pss written by Eli Bendersky. The tool is written in Python and that is attractive to me, because I can read the source code and maybe learn something from it. :-)
Download: https://bitbucket.org/eliben/pss/downloads
Showing posts with label CLI. Show all posts
Showing posts with label CLI. Show all posts
Thursday, October 20, 2011
Tuesday, May 31, 2011
Tile Figures with Montage (ImageMagick)
Suppose you have several figures for articles ,papers, blogs, or anything else. You want to combine these figures into a bigger frame, and they have gaps between each other. How? I had used Inkscape to import the figures, arrange them, and export the final result. No, don't do that again. It is not necessary to launch your image editors with GUI to accomplish this kind of work. I found the most convenient way is to use some commands offered by the magic ImageMagick.
Good examples have been given in ``ImageMagick v6 Examples -- Montage, Arrays of Images,'' and the following is my own test with some notes.
Good examples have been given in ``ImageMagick v6 Examples -- Montage, Arrays of Images,'' and the following is my own test with some notes.
Sunday, May 22, 2011
Tetris in Command Line
Ha ha! That's really funny. I never think about even sed can be used to write games such as Tetris!
I just wondered how to play Tetris in command line. Googled it and found several results with source code. There are three of them I've played:
In Ubuntu, just install the ncurses-dev.
I just wondered how to play Tetris in command line. Googled it and found several results with source code. There are three of them I've played:
- Tetris for the command line with Python Curses (in Python)
- Play Tetris at the command line (in sed)
- tt: Tetris for Terminals (in C)
utils.c:32:20: error: curses.h: No such file or directory
utils.c:33:18: error: term.h: No such file or directory
In Ubuntu, just install the ncurses-dev.
Thursday, September 02, 2010
Converting filenames from UPPERCASE to lowercase
I searched and found the following thread:
http://blog.mc-thias.org/?title=rename-files-from-upper-case-filename-to&more=1&c=1&tb=1&pb=1
Based on the post given by Jadu Saikia, I got the bash script of my own version as follows:
One new thing I've learned in this example is the ``\L'' part, which can be found in sed's FAQ.
http://blog.mc-thias.org/?title=rename-files-from-upper-case-filename-to&more=1&c=1&tb=1&pb=1
Based on the post given by Jadu Saikia, I got the bash script of my own version as follows:
ls * | sed -e p -e 's/.*/\L&/g' |xargs -n 2 mv
One new thing I've learned in this example is the ``\L'' part, which can be found in sed's FAQ.
Friday, June 11, 2010
[QnA] Command line rocks!! Combine several data files...
I have several data files. Each of them has only one column which presents acceleration along one axis. I want to combine them into one single file so that I can read them into my Python program with opening only one file.
To illustrate the situation, here are some sample contents of the files:
ACC_X.txt
126
127
129
127
137
ACC_Y.txt
132
106
109
114
105
ACC_Z.txt
137
139
138
138
144
What I want is to combine them in columns within a single files as:
ACC.txt
126,132,137
127,106,139
129,109,138
127,114,138
137,105,144
The first thing came into my head is using awk. However, I am not familiar with awk script. With brief searching, I found two easy ways in the command line: paste and pr.
The command using paste could be:
$ paste -d, ACC_X.txt ACC_Y.txt ACC_Z.txt > ACC.txt
Or you can use pr like this:
$ pr -mts, ACC_X.txt ACC_Y.txt ACC_Z.txt > ACC.txt
The comma in the commands means I am using it as the delimiter or separator.
Simple and fast. Command line really rocks!
To illustrate the situation, here are some sample contents of the files:
ACC_X.txt
126
127
129
127
137
ACC_Y.txt
132
106
109
114
105
ACC_Z.txt
137
139
138
138
144
What I want is to combine them in columns within a single files as:
ACC.txt
126,132,137
127,106,139
129,109,138
127,114,138
137,105,144
The first thing came into my head is using awk. However, I am not familiar with awk script. With brief searching, I found two easy ways in the command line: paste and pr.
The command using paste could be:
$ paste -d, ACC_X.txt ACC_Y.txt ACC_Z.txt > ACC.txt
Or you can use pr like this:
$ pr -mts, ACC_X.txt ACC_Y.txt ACC_Z.txt > ACC.txt
The comma in the commands means I am using it as the delimiter or separator.
Simple and fast. Command line really rocks!
Friday, March 12, 2010
[SW] Convert XLS to CSV
I got a bundle of xls files and want to extract their data for further analysis. The first thought occurred to me was to find some command line tools to help me convert all the xls files into some kind of text files. Then I found xls2csv, which can be got via apt-get by installing catdoc. So what you need is typing
The catdoc is useful when you want to take a look at the textual information in doc files.
$ sudo apt-get install catdocin your Ubuntu terminal.
The catdoc is useful when you want to take a look at the textual information in doc files.
Saturday, February 27, 2010
[SW] Two CLI screensavers
Actually, I do not use screensavers. I always turn off the monitor when I have to leave my PC for a while. As a CLI fan, however, I am willing to see a CLI screensaver running on my monitor, especially when the screensaver is cool.
Cmatrix is a cool screensaver and it's easy for Ubuntu users to install. Just use the command

The second one I installed is ASCIIQuarium. I found it on the Mostly CLI blog (Is that a Fish in Your CLI? The asciiquarium Screensaver.), which is worth visiting if you are also a CLI fan. Followed the steps, I download the Term::Animation module but got a warning when I runned the ``perl Makefile.PL'' command. The warning message was
Cmatrix is a cool screensaver and it's easy for Ubuntu users to install. Just use the command
$ sudo apt-get install cmatrixto get it, and you can have a really Matrix-like screensaver. Looks really cool, doesn't it?

The second one I installed is ASCIIQuarium. I found it on the Mostly CLI blog (Is that a Fish in Your CLI? The asciiquarium Screensaver.), which is worth visiting if you are also a CLI fan. Followed the steps, I download the Term::Animation module but got a warning when I runned the ``perl Makefile.PL'' command. The warning message was
Warning: prerequisite Curses 1.06 not found.Then I tried to find out how to installed the so called ``curses'' in my Ubuntu 8.04, even install the libncurses5-dev (it's not the right one), but got no luky. Then, I noticed that all the packages are related to Perl! I am not familiar with Perl so I had no clear idea what searching strategy was right. Finally I knew that the libcurses-perl is the key. So if you encounter the same problem I had, please use the following command to install the libcurses-perl package.
$ sudo apt-get install libcurses-perlThen here comes the ASCII fishes (as well as other things...).
Sunday, February 21, 2010
[SW] Mutt usage and setting -- with Gmail
Thank Andrew! I followed his blog article and finally make Mutt work with Gmail!
Here is the excellent instruction for newbies who want to try Mutt but have no idea how to to:
Using Mutt with Gmail
I have changed some settings for the inbox folder from
/var/spool/mail/your_username
to
$HOME/mail/inbox
Although there are more things I need to learn, Andrew's guidance has given a good start. Hope you can benefit from this.
Here is the excellent instruction for newbies who want to try Mutt but have no idea how to to:
Using Mutt with Gmail
I have changed some settings for the inbox folder from
/var/spool/mail/your_username
to
$HOME/mail/inbox
Although there are more things I need to learn, Andrew's guidance has given a good start. Hope you can benefit from this.
Friday, February 19, 2010
[SW] Invoke Okular from the command line -- use soft symbolic link
I have installed Okular in my Ubuntu for several months and appreciated its annotation functions which allow me more freedom with my own documents. When I want to invoke Okular from the command line, however, it cannot be found by the system. After some investigations, the symbolic link seems to be the handiest solution.
Go to /usr/bin and use ln to make a symbolic link:
$ sudo ln -s /usr/lib/kde4/bin/okular okular
This is my first time to use ln, and it works as expectation. :-)
Go to /usr/bin and use ln to make a symbolic link:
$ sudo ln -s /usr/lib/kde4/bin/okular okular
This is my first time to use ln, and it works as expectation. :-)
Tuesday, February 09, 2010
[QnA] Convert MOD to AVI using transcode -- without audio ouput
Sometimes we might take videos with some environmental noise or conversations which are not suitable to be heard by others. Also, we don't need or want to add other audio into the original video, so just export the video without audio is fine enough.
I had some MOD files to be converted by using transcode before, and this time I want to export my MOD files into avi files with no sound. It's can be done by apply the ``null'' option as the following
transcode -i input.MOD -y xvid,null -o output.avi
That's all.
I had some MOD files to be converted by using transcode before, and this time I want to export my MOD files into avi files with no sound. It's can be done by apply the ``null'' option as the following
transcode -i input.MOD -y xvid,null -o output.avi
That's all.
Saturday, November 14, 2009
[QnA] Taking screenshots of virtual consoles?
I am trying to find ways to take screenshots of virtual consoles. This article shows the method of taking screenshots from console using the ImageMagick. The author said that the method also works for consoles with the command as the follows
$ sudo chvt N; sleep T; import -display :0.0 -window root output.png; sudo chvt M
where N is the target console and T is the time in seconds. The last chvt command is just for returning the original working console.
After testing with the command, however, I found the png file was generated but the image itself is not what I expected. At the beginning I thought that might due to my framebuffer setting so I disabled the corresponding setting in the /boot/grub/menu.lst. Nothing has been improved and I still can only get the following useless image.
$ sudo chvt N; sleep T; import -display :0.0 -window root output.png; sudo chvt M
where N is the target console and T is the time in seconds. The last chvt command is just for returning the original working console.
After testing with the command, however, I found the png file was generated but the image itself is not what I expected. At the beginning I thought that might due to my framebuffer setting so I disabled the corresponding setting in the /boot/grub/menu.lst. Nothing has been improved and I still can only get the following useless image.
[QnA] FrameBuffer setting
Several months ago, I learned the way to view images in the virtual console. I happened to recall the framebuffer and want to know more about it, so I began to search related information again.
Here are several informative web pages:
Here are several informative web pages:
- Images and Videos on the Command Line? YES!
- Using framebuffer devices on Intel platforms
- Ubuntu wiki: FrameBuffer
In the 2nd web page, there is a table showing the values for different resolution as follows:Furthermore, from the 3rd reference I found more useful setting such as
Colours 640x400 640x480 800x600 1024x768 1152x864 1280x1024 1600x1200
--------+--------------------------------------------------------------
4 bits | ? ? 0x302 ? ? ? ?
8 bits | 0x300 0x301 0x303 0x305 0x161 0x307 0x31C
15 bits | ? 0x310 0x313 0x316 0x162 0x319 0x31D
16 bits | ? 0x311 0x314 0x317 0x163 0x31A 0x31E
24 bits | ? 0x312 0x315 0x318 ? 0x31B 0x31F
32 bits | ? ? ? ? 0x164 ?
- ``vga=normal'', or ``nofb'', disables the framebuffer
- ``vga=ask'' will able you to set a value at each boot good for testing out the various modes.
Friday, November 13, 2009
[QnA] Sound volume control in command line
I've used wmii for several weeks, and it meets most of my need well. Sometimes, however, I want to control the volume but there is no the control panel as in the Gnome desktop environment.
Here is the solution: amixer (or alsamixer, which has the ncurses interface).
To use alsamixer is easier due to the straightforward interface. If you get the following error message when you type ``alsamixer'' in the command
---
Ref:
http://ubuntuforums.org/showthread.php?t=597765
http://ubuntuforums.org/showpost.php?p=3631606&postcount=4
Here is the solution: amixer (or alsamixer, which has the ncurses interface).
To use alsamixer is easier due to the straightforward interface. If you get the following error message when you type ``alsamixer'' in the command
alsamixer: function snd_ctl_open failed for default: Connection refusedthen do the following steps:
$ rm ~/.asoundrc and then dowhere the foo is one of the sound cards listed by `asoundconf list.'
$ asoundconf list
$ asoundconf set-default-card foo
---
Ref:
http://ubuntuforums.org/showthread.php?t=597765
http://ubuntuforums.org/showpost.php?p=3631606&postcount=4
Monday, October 26, 2009
[QnA] Using the terminal in Ubuntu -- simple but useful commands
Here is a web page for newbies: UseingTheTerminal. Most of the commands are simple but could be useful in daily operation.
Tuesday, October 13, 2009
[QnA] Redirect the error message given by gcc compiler
I tried the redirect operator ``>'' to write the error and warning message to files, but it didn't work. There was nothing written into the files. Then, I found the solution:
$ gcc $> file
The ``$'' character is needed to make the redirection work.
Links:
$ gcc $> file
The ``$'' character is needed to make the redirection work.
Links:
- How to redirect or echo gcc messages to file?
- Advanced Bash-Scripting Guide: I/O Redirection
[QnA] Mount smb folders from command line
Here are simple procedures to mount remote folders using command line interface.
$ sudo apt-get install smbfs
$ sudo mkdir /media/theFolderInYourPC
$ sudo mount -t smbfs -o username=theUsername,password=thePassword //theRemotePCsIP/theRemoteFolder /media/theFolderInYourPC
Links:
$ sudo apt-get install smbfs
$ sudo mkdir /media/theFolderInYourPC
$ sudo mount -t smbfs -o username=theUsername,password=thePassword //theRemotePCsIP/theRemoteFolder /media/theFolderInYourPC
Links:
Monday, August 10, 2009
[QnA] Convert MOD to AVI using transcode
Sunday, May 24, 2009
[QnA] How to increase the number of tty in Ubuntu
Because I like to work in virtual consoles (ttys), sometimes I feel only six ttys is not enough. But, how to increase more ttys than the default number, i.e. six, given by Ubuntu? I found there are many tty* in /dev, so I guessed there should be some way to ``enable'' these virtual consoles.
After searching on the internet, I got some information:
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.
start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec /sbin/getty 38400 tty1
Ah, the rule emerged. I copied the tty6 to be tty8 to tty12 (tty7 is for the GUI desktop, as I know...), then replaces the string ``tty6'' in all the copies to their corresponding tty number. Finally, I have 11 virtual consoles, i.e., tty1 to tty6 and tty8 to tty12.
After searching on the internet, I got some information:
- To open a tty, the file /etc/inittab is the key
- Ubuntu has no inittab, which has been replaced by the files in /etc/event.d
# tty1 - getty
#
# This service maintains a getty on tty1 from the point the system is
# started until it is shut down again.
start on stopped rc2
start on stopped rc3
start on stopped rc4
start on stopped rc5
stop on runlevel 0
stop on runlevel 1
stop on runlevel 6
respawn
exec /sbin/getty 38400 tty1
Ah, the rule emerged. I copied the tty6 to be tty8 to tty12 (tty7 is for the GUI desktop, as I know...), then replaces the string ``tty6'' in all the copies to their corresponding tty number. Finally, I have 11 virtual consoles, i.e., tty1 to tty6 and tty8 to tty12.
Monday, May 04, 2009
[SW] CLI: playing the video in ASCII art
I am just a normal PC user, but I like working with command line or text mode very much. The reason might be I think text mode is ``pure'' and ``simple.'' Of course, the word ``simple'' never mean it is simple for the users, but means the way of appearance or presentation.
After learning something useful in command line, e.g., writing and debugging code (gcc and gdb), surfacing the internet (elinks or w3m), and play audio files (mp3blaster), I began to curious about how to play video in command line mode.
To play a video, there are also methods to do it with the command line.
For VLC, try:
For Mplayer, try:
mplayer -vo aa yourVideoFile
mplayer -vo caca yourVideoFile
where -vo means video output driver. The drivers aa and caca are used for monochrome and color ASCII art video output, respectively.
The results are funny. When you look at the monitor at normal distance, you may hardly figure out what are you watching. There is only rapidly changed ASCII symbols! As you step back form the monitor, however, you will find all the dynamic images become clear and meaningful. You are watching video consists of many ASCII symbols!
Here is one screenshots captured on my monitor. Use mplayer with -vo caca:
(Original video can be viewed on YouTube: 元ちとせ-春のかたみ. By the way, I love songs of 元ちとせ [Hajime Chitose] very much.)

Of course, the above image was captured by playing the video using Terminal in the desktop environment (pty?). I don't know how to output the ``image'' in the real command line mode (tty?).
Also, there are still some problems I don't understand. The first one is when I invoke the vlc with -I ncurses option using pty, the video still be played via the GUI but not the expected ASCII way. Another problem is that the aa option of mplayer cannot paly the video properly. Only part of the image was shown, as the following scrrenshot:

The final problem is that, when invoked under the tty, the mplayer did not do these works as well as it did under the pty. The reverse is true for vlc, however. Maybe someday I will realize the underlying reason about all these problems... maybe. :-p
After learning something useful in command line, e.g., writing and debugging code (gcc and gdb), surfacing the internet (elinks or w3m), and play audio files (mp3blaster), I began to curious about how to play video in command line mode.
To play a video, there are also methods to do it with the command line.
For VLC, try:
vlc -I ncurses yourVideoFile
For Mplayer, try:
mplayer -vo aa yourVideoFile
mplayer -vo caca yourVideoFile
where -vo means video output driver. The drivers aa and caca are used for monochrome and color ASCII art video output, respectively.
The results are funny. When you look at the monitor at normal distance, you may hardly figure out what are you watching. There is only rapidly changed ASCII symbols! As you step back form the monitor, however, you will find all the dynamic images become clear and meaningful. You are watching video consists of many ASCII symbols!
Here is one screenshots captured on my monitor. Use mplayer with -vo caca:
(Original video can be viewed on YouTube: 元ちとせ-春のかたみ. By the way, I love songs of 元ちとせ [Hajime Chitose] very much.)

Of course, the above image was captured by playing the video using Terminal in the desktop environment (pty?). I don't know how to output the ``image'' in the real command line mode (tty?).
Also, there are still some problems I don't understand. The first one is when I invoke the vlc with -I ncurses option using pty, the video still be played via the GUI but not the expected ASCII way. Another problem is that the aa option of mplayer cannot paly the video properly. Only part of the image was shown, as the following scrrenshot:

The final problem is that, when invoked under the tty, the mplayer did not do these works as well as it did under the pty. The reverse is true for vlc, however. Maybe someday I will realize the underlying reason about all these problems... maybe. :-p
[SW] SoundConverter
I was searching a software to convert my ogg files to mp3 format (for my mp3 player, which doesn't know the ogg files). Several days ago, I found the SoundConverter, which is an application in GNOME environment.
If you have some sound or music files to convert the format, I think the SoundConverter is a good choice.
---
[edit: 2010/12/28]
To use the SoundConverter in the command line, here is an example to convert *.ogg to *.mp3.
(Why bother to convert ogg to mp3? Because I have an old music player which doesn't support ogg format! :-p )
Suppose you are in the folder containing ogg audio files:
If you have some sound or music files to convert the format, I think the SoundConverter is a good choice.
---
[edit: 2010/12/28]
To use the SoundConverter in the command line, here is an example to convert *.ogg to *.mp3.
(Why bother to convert ogg to mp3? Because I have an old music player which doesn't support ogg format! :-p )
Suppose you are in the folder containing ogg audio files:
$ soundconverter -b -m audio/mpeg -s .mp3 *.ogg
Subscribe to:
Posts (Atom)