Ever wanted to have a real-time clock on your linux terminal? We can create one with a single line of bash, like so: Let’s look at how this works: date is a common unix tool used to print the current date and time. The $(…) means that the date command is run, and the output is placed here instead. For …
Start reading Linux Terminal ClockBlog
There are a number of ways to read keyboard input with python. One easy option is to use the curses library, using the getch() method, as shown below: The program above initialises the curses library, then sits in an infinite loop, printing a message whenever any keyboard buttons are pressed. Use ctrl-c to interrupt the loop and clean up curses before exiting gracefully. Note that …
Start reading Reading keyboard input with PythonIf you have a filename or list of filenames, you may want to strip the extension. There are a few ways of “detecting” which part of the filename is the extension, but may not work if your file has multiple extensions (e.g. .tar.gz), contains spaces or periods, or meets other weird criteria. If you know …
Start reading Removing a known extension from a filenameTips for research scholars – manuscript preparation tips IMRaD Introduction Methods Results Discussion Download Presentation
Start reading Research Document TipsIf you’ve got a string of items in bash which are delimited by a common character (comma, space, tab, etc) you can split that into an array quite easily. Simply (re)define the IFS variable to the delimiter character and assign the values to a new variable using the array=($<string_var>) syntax. The new variable will now be an array of …
Start reading Convert a delimited string into an array in BashSo you’ve got a USB drive, and you need to reformat it. You can do this all quite easily on the command line using the fdisk utility. First, get the device location. This will be something like /dev/sdd. You want the location of the device, not a partition on the device ie: /dev/sdd instead of /dev/sdd1. The instructions below work for …
Start reading Formatting a usb drive in linuxSometimes in a terminal you want to strip out the first line of output from a command. For example, you may want to generate a list of users which have tasks running using the ps command. This command puts a header at the top of the output. You can remove this header by piping the output to sed …
Start reading Ignoring the first line of output in a unix terminalEver jumped onto an Ubuntu server somewhere without knowing which operating system version it’s running? You can find this out with one simple command: This will provide output like:
Start reading Checking the Ubuntu version numberIn Bash you quite often need to check to see if a variable has been set or has a value other than an empty string. This can be done using the -n or -z string comparison operators. The -n operator checks whether the string is not null. Effectively, this will return true for every case except where the string contains no …
Start reading Checking for empty string in BashCVS is annoying in that if you want to find out which files have been modified or need updating, you can’t simply use the cvs status command as there’s too much information displayed. In order to make it useful, you really need to filter the output. Note: the following tutorial only works for linux computers using the …
Start reading List files which are not up to date in CVS