≡ Menu

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 )

Linux / Unix: Sort ls Command Output By Last Modified Date and Time

I download lots of files in ~/Downloads/ folder in Ubuntu Linux and OS X desktop. How do I show last downloaded file first using the ls command?
[click to continue…]

Linux / Unix: Shell Script Find Out In Which Directory Script File Resides

I need to find out in which directory my bash script resides so that I can read config file called .backup .ignore .target. For example, if my script resides in >/home/foo/script.sh, I need to read /home/foo/.{backup,ignore,target} files. How do I find out the current directory location and shell script directory location in Bash running on Linux or Unix like operating systems?
[click to continue…]

Bash: Display Web Page Content In Terminal

How can I fetch HTML web page content from bash and display on screen using shell utilities?
[click to continue…]

Awk Floating Point Number Addition Results Are Unexpected

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}'

I want $682444.57 as output. How can I force "awk" to do floating point math?
[click to continue…]

Linux: Find Out How Much Disk Space Left On Hard Drive

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?
[click to continue…]

Linux: Find Out Directory Size Command

I am a new Linux user. How do I find out size of a directory on Linux operating systems using command line options?
[click to continue…]

sed Tip: Delete All Blank White Spaces

I have a text file as follows:


How can I delete all leading and/or trailing blank spaces, tab from each line using sed command?
[click to continue…]

Unix and Linux: Redirect Error Output To null Command

I'm a new Linux system user. How can I redirect command error output /dev/null on a Linux or Unix-like system using Bash shell?
[click to continue…]

Linux / Unix: View Overlapping Man Page With Same Names

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:


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?
[click to continue…]

scp: Do not Overwrite Existing File On Linux or Unix System

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?
[click to continue…]