Posts Tagged ‘empty’

Test if a directory is empty in Bash

Posted: 29th January 2015 by Tim in Bash, Linux
Tags: , , , , , ,

Using Bash, there are a number of ways to test if a directory is empty. One of those ways is to use ls -A to list all files, including those starting with . and see if anything is printed. This can be done like so: if [ ! “$(ls -A <path>)” ] then     echo “<path> […]

Formatting a usb drive in linux

Posted: 11th July 2012 by Tim in Linux
Tags: , , , , , , , ,

So 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 […]

In 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 […]