Bash Shell Programming HowTos

Tutorials, howtos and programming tips about GNU Bourne-Again SHell (BASH) for Apple OS X, Linux, *BSD and Unix like operating systems. ( rss feed )

I am using awk to grep ‘foo’ from a text file and cacluate sum of field # 7. But, result is rounded to an integer. I need exact result such as 385858.66 and not 385858 using the following command:

grep ‘foo’ 2012-2013.txt | awk ‘BEGIN{ sum=0.0}{ sub(“,”,””,$7); sum +=$7}END{ print “$” sum}’
$682444

I want $682444.57 as output. How can I force “awk” to do floating point math?

{ 1 comment }

I am a desktop support professional with experience working in a corporate call center environment. Recently, I started to admin RHEL based IBM Linux server. How do I determine how much disk space left in my Linux server? How do I find out how much disk space I have in Linux for each partition?

{ 10 comments }

I am a new Linux user. How do I find out size of a directory on Linux operating systems using command line options?

{ 11 comments }

I have a text file as follows:

foo
bar
foobar

How can I delete all leading and/or trailing blank spaces, tab from each line using sed command?

{ 5 comments }

I am a new Unix / Linux user. I am using whatis command to find man pages. But, I noticed that some man pages have a common names. For example, when I run whatis printf:

Outputs:

printf (1) - format and print data
printf (1p) - write formatted output
printf (3) - formatted output conversion
printf (3p) - print formatted output
printf [builtins] (1) - bash built-in commands, see bash(1)

How do I access overlapping man pages and what is the meaning of (1), (1p), (3), and so on?

{ 1 comment }

I am a new Linux user. I use scp to upload files to net-storage provided CDN company. I do not want to overwrite the existing files. How can I prevent overwriting of files when using scp command under Linux, Mac OS X or Unix like operating systems?

{ 2 comments }

I need to clean up my backups stored on the nas server. I need to free up the disk space. How do I find out all hidden dot directories such as /nas01/backups/home/user/.gnome/, /nas01/backups/home/user/.gnome/ and so on and delete then in a single pass using Linux or Unix command line option? Please note that I do not want to delete nested hidden directories such as /nas01/backups/home/user/data/.xml, /nas01/backups/home/user/foo/bar/.level/.levle2/ and so on.

{ 4 comments }