Month: May 2012

13 examples to use curly braces in Linux

This is a small post on how to crate multiple files/folders, sequence generation with flower brackets in-order to save valuable time. Creating empty files can be done with touch command. We will see how to create multiple files using this command in one shot. Example 1: Create a file with name abc.txt touch abc.txt Example2: Create multiple files abc, cde, efg, hij, klm touch  abc cde efg hij klm Example 3: How about creating 1 to 20 files, ie creating multiple files with one command. Its bit tedious job for an admin. Don’t worry Linux provide us with some useful option with “Flower...

Read More

9 Linux read command examples for Shell scripting

As most of you know, we can define variables in our shell scripts to make our scripts more independent of hard coding. Below are they ways we can assign values to variables in a shell script Defining variables in the script: Assigning predefined constants to variables with the script. Before executing a script: Using positional parameters we can assign values to variables before actual execution of the script When running a script: We can assign values to variables when we are in middle of the script. All these solve different purposes on when to assign values to variables. The read command is useful for assigning variables at the time of executing a script, a kind of interactive script. Learn read command with examples The read command syntax read VARIABLE_NAME To access the above variable we use “$” or use echo if you want to print it. echo "My variable is $VARIABLE_NAME" Some frequently used read command examples Example1: Read a value from user input. To display this value, we have to use echo command as mention earlier. read VAR1 echo $VAR1 Output: surendra@sanne-taggle:~$ read VAR1 surendra surendra@sanne-taggle:~$ echo $VAR1 surendra Example2: The read command is an excellent command which can read two or more words/variable/values at a time. read VAR1 VAR2 Output: surendra@sanne-taggle:~$ read VAR1 VAR2 surendra kumar surendra@sanne-taggle:~$ echo $VAR1 surendra surendra@sanne-taggle:~$ echo $VAR2 kumar Example3: We can use read...

Read More

9 linux sort command examples to sort files

This is a small tutorial on how to use sort command to sort a file for some meaning full output. Sorting is very much useful when dealing with DB files, CSV, xls, log files in fact a text file to. By default sort command will sort according to alpha-bates. First sort tries to sort according to single character virtically in the file, if it finds a character is same in two lines, then it move on to sort second character. Suppose I have a following word list in a file cat filename.txt abc cde hij klm kle ble This will be sorted first with first char. When it finds both the char same in this example klm and kle start with same characters, so it tries to sort with third character which are different in those two lines. The output of sort  as below sort filename.txt abc ble cde hij kle klm Sort command syntax sort filename.txt Example1: Sort a given file according to alpha-bates sort filename.txt Example2: I have a file with host names in third column, how can I sort them according to this column(according to hostname)?. Use -k for sorting according to column(kolumn) sort -k3 filename.txt The above command will sort according to third column. Example3:I want to sort /etc/passwd file according to home directories but my sort is not working how can I sort them? By default sort will take space/tabs...

Read More

Over 16,000 readers, Get fresh content from “The Linux juggernaut”

Email Subscribe

ABOUT ME..!

My photo
My name is Surendra Kumar Anne. I hail from Vijayawada which is cultural capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. At present I work at Bank of America as Sr. Analyst Systems and Administration. You can contact me at surendra (@) linuxnix dot com.