Monday, April 07, 2025


Shell Programming Blog Shell Programming Blog

Wednesday, 31 October 2012

Linux Bash Scripting: How to combine two lines by removing newline character using sed

Unknown | 08:57 | | Be the first to comment!

In this post we will see how to remove the newline character and combine two lines in a text file using "sed". In sed, we have single line version and multi-line version of few commands. One...

Tuesday, 30 October 2012

Linux Bash Scripting: How to create directories for each day of the current month

Unknown | 09:59 | | 3 Comments so far

 In this post I have written a script that creates an empty directory for each day of the current month. I used cal command to get the date and month instead of using date command. The reason...

Sunday, 28 October 2012

Linux Bash Scripting: How to remove a blank line after a particular line using sed

Unknown | 07:35 | | Be the first to comment!

Removing a blank line after a particular line can be achieved using the single-line next command (n) of the sed editor. The lowercase n command tells the sed editor to move to the next line of...

Tuesday, 23 October 2012

Linux Bash Scripting: How to modify the ls command output using pr command

Unknown | 11:29 | | Be the first to comment!

I have received the below question in our "Ask a question" section of this blog. Q: Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each...

Sunday, 21 October 2012

Linux Bash Scripting: Standard file descriptors STDIN, STDOUT and STDERR and input/ouput redirection

Unknown | 08:52 | | Be the first to comment!

  Linux system handles every object as a file. This includes input and output processes also. The linux identifies each file using a file descriptor. What is a file descriptor? A file descriptor...

Wednesday, 17 October 2012

Linux Bash Scripting: how to rename or delete a file which has special characters in its filename

Unknown | 19:46 | | Be the first to comment!

Suppose if you have created a file with a special character in its name because of a typo, you may not be able to access it. You may not even be able to delete the file. For example, see the below...

Monday, 15 October 2012

Linux Bash Scripting: Perform floating point calculation/arithmetic/operation using BC

Unknown | 03:07 | | Be the first to comment!

  As we have discussed on performing Arithmetic operations on our previous post, now we will look at the floating point operations in the shell script in this post. You might want to look at...

Sunday, 14 October 2012

Linux Bash Scripting: How to ignore specific commands from being stored in the history in Linux

Unknown | 19:39 | | 3 Comments so far

If you see the history of your commands using the "history" command, you can see all the commands that you executed in the command line. If you don't want certain basic commands to be stored in...

Linux bash scripting: How to repeat the previous command quickly in the Linux command line

Unknown | 11:32 | | Be the first to comment!

There are four different ways by which we can repeat the previous commands that we executed in the command line. 1) use the "UP arrow" to view the previous command and press Enter to execute it. 2)...

Saturday, 13 October 2012

Linux bash scripting: How to search the command history (previously executed commands)

Unknown | 10:47 | | Be the first to comment!

We often need to type long commands in the command line which we typed earlier. Instead of typing it again we can search the command history for the command we executed and execute it again. This...

linux Bash Scripting: how to display the history of commands along with the timestamp

Unknown | 10:35 | | Be the first to comment!

Usually the history command will display the command number and the command when you execute the command from the command line. Suppose if you want to add the timestamp along with the command history...

Friday, 12 October 2012

Linux Bash Scripting: How to rename multiple files in a single go

Unknown | 10:39 | 1 Comment so far

You might come across a situation where you need to rename lot of files with similar file names either by editing the file name or by truncating the last part of the file name. There are two ways...

Windows tips and Tricks

Unknown | 10:16 | Be the first to comment!

I have personally tried and tested most of the tweaks discussed in this guide. However, I request fellow readers to be cautious while trying it out with your system. Always take a backup copy of...

Thursday, 11 October 2012

Linux Bash Scripting: how to print a big chess board anywhere on the screen

Unknown | 11:12 | Be the first to comment!

In this post, we will see how to create a big chess board that can be displayed anywhere on the screen rather than being displayed left aligned. Below is the script which displays the Chess...

Friday, 5 October 2012

Have questions?? Need Clarifications???

Unknown | 08:34 | 6 Comments so far

Hi All, I know that lot of us would get stuck while doing programming in Shell scripting or doing something in Linux. If you are badly in help and need to find an answer, you can make use of this...

Thursday, 4 October 2012

how to change the default size of the terminal window in Solaris

Unknown | 09:13 | | Be the first to comment!

To change the default size of the terminal window in Solaris, you need to do the following. 1) Go to the directory /usr/share/vte/termcap/ and edit the file xterm      i.e., $ vi...

Tuesday, 2 October 2012

Linux Shell Scripting: how to list the files alone in a directory

Unknown | 09:21 | Be the first to comment!

 Often we tend to look into the directories to check what files are present in the directory. When we try to list the files using ls command, all files along with the directories will be displayed....

Monday, 1 October 2012

Perform Arithmetic operations or mathematical calculations in Shell scripting - expr command

Unknown | 09:54 | Be the first to comment!

   The command which is used to perform mathematical or Arithmetic calculations is "expr" command. Syntax: expr <operand 1> operator <operand 2> Examples: $ expr 2 + 3 $...

How to print the last field in a file in Linux/Unix Shell scripting

Unknown | 08:32 | Be the first to comment!

Let us see how to print the last field alone from a file which contains several fields. Let's say that the input is the below file. $ cat priority.txt Bash:P:Sun:7 NW:F:Mon:4 DB:P:Tue:8 SE:P:Fri:8 Now...

How to find the latest file in a directory

Unknown | 07:21 | Be the first to comment!

Suppose if you hava a directory with a huge set of files(more than 500) in a log directory, you would want to find the latest file in the directory. Now we can see few ways to that. for example,...

Linux/Unix Shell Scripting topics explained on requests

Unknown | 02:11 | Be the first to comment!

Are you new to Shell scripting?  Are you learning Shell Scripting either in Linux or Unix? Is it tough for you to understand?  Do you feel confused while trying to learn a topic? Is there...

Sunday, 30 September 2012

Linux terminal freezing problem [resolved] :-)

Unknown | 03:48 | Be the first to comment!

I often wonder why my Linux terminal freezes when I press certain key combinations unknowingly. Finally when I found the key combination, I found that I pressed Ctrl+s key. Which is used for...

How to display the text in Bold and Underline in Linux

Unknown | 03:42 | 3 Comments so far

   To display the test in "BOLD" and "UNDERLINE", the following ANSI Escape Sequences can be used. To display the text in BOLD$ echo -e "\033[1mThis is a BOLD line\033[0m"This is a BOLD...

Saturday, 29 September 2012

How to sort the files and directories based on their size

Unknown | 23:25 | | | Be the first to comment!

Let us see how to sort the files and directories. In my current directory, I have the following files and sub-directories:$ file *config: directoryval.dat: ASCII textsample.txt: ASCII textlog: directoryi.e.,...

How to list the empty directories in Linux

Unknown | 22:37 | Be the first to comment!

  The find command in Linux has an option called 'empty'. This option can be used to list empty regular files or empty directories. e.g.To list all the empty directories$ find . -type d -emp...

How to find the past and future dates using date command

Unknown | 11:53 | Be the first to comment!

    The "date" command in Linux is used to display the current date and time. But, we can also make the date command to display past and future dates based on the inputs/parameters that...

Friday, 28 September 2012

How to calculate the size of a directory in Linux

Unknown | 12:09 | Be the first to comment!

  Let us see how to calculate the size of a directory including its sub directory. To calculate the total folder size of folder "bin"$ du -sh bin/280K bin/-s, --summarize (display only a total...

How to find largest files in a directory and its sub directories

Unknown | 11:15 | Be the first to comment!

A situation may occur in your office that you might have to clear the space in the server by deleting the largest files in the log directory. If you want to find and print the top 10 largest...

How to remove duplicate entries from a file without sorting

Unknown | 10:58 | Be the first to comment!

  Usually whenever we want to remove duplicate entries or lines from a file, we need to sort the entries and then eliminate the duplicates using "uniq" command. But if we want to remove...

How to exclude or skip a directory while searching for a file using FIND command

Unknown | 10:33 | Be the first to comment!

Find command is used to search the files in the Linux environment. This find command will search all the directories and the sub directories in the path which we give in the find command....

Wednesday, 26 September 2012

Sorting the file leaving the first line and writing in a file

Unknown | 10:43 | 1 Comment so far

Now we can see how to sort a file by leaving the first line as it is. For example, we take a file sample.txt which contains the below data. chrom:index:forward:reverse chr01:13:1:2 chr13:23432:4:7 chr01:3445:1:6 chr02:2311:3:1 chr01:212:5:2 chr03:12:1:4 chr02:345:12:6 chr01:45:45:0 If...

 

Shell Programming Copyright © 2012 Shell Programming theme is Designed by Abusittik, Shell Programming