Linux Shell commands

Another TOP 10 Linux Shell Commands for beginner

There is no doubt that you will not be able to work on Linux if you do not know the command lines. You do not have to have Linux beards to work on the software. You will have to be familiar with the most common Linux commands in order to kick start with Linux. This is why we have compiled the set of Linux shell commands that you need to know as a beginner in this article. With these few basic and most commonly used commands, you will get the knowledge about which commands to use where in order to work on Linux.

  1. sed

The short form of stream editor is the sed command. If you are looking to write a program to make changes in a certain file, then sed tool will be very helpful. It is a special Linux command editor tool to make changes to the files automatically. You should know more about sed as it is a very useful tool for beginners. There are many commands that sed offers. But, most of the people only learn and make use of the s command, which is the substitute command. Sed will help in filtering and transforming text.

  • Syntax

sed OPTIONS… [SCRIPT] [INPUTFILE…]

  • Ex: sed s/day/night/ old >new

This command will change the day in the previous file to night in the new file.

  1. awk

awk is the short form of  “Aho, Weinberger, and Kernighan,” which is a programming language that will help you  to process text. This programming language is commonly used to scan patens and for text processing. It will carry out searches for many files to see if the files have lines that match certain patterns. Once he files are located, it will perform the actions as per instructions. The awk language has loops, variables and conditionals like you find in other common languages. It can also perform arithmetic and string operations.

  • Syntax

awk ‘/search pattern1/ {Actions}

/search pattern2/ {Actions}’ file

Here, the search pattern is the regular expression; Actions – statements to be performed; file – Input file.

  • Ex: awk ‘length($0) > 72’ text.txt

The lines of the file text.txt that are longer than 72 characters will only be printed. 

  1. tr

tr means translate. This tr command is used in Linux and Unix to delete, translate or squeeze repeated characters. It is used to translate or delete characters in the standard input and to write it on to the standard output.

  • Syntax

$ tr [OPTION] SET1 [SET2]

This means that the tr command will replace all the characters in SET1 with the characters in SET2 and each character in SET1 will be replaced in the same position in SET2.

  • Ex: tr “[:lower:]” “[:upper:]” < file1

All the content in file1 will be translated into uppercase using the tr command.

  1. cat

The cat command is one of the most commonly used commands in Unix/Linux operating systems. It is the short form of the concatenate command. You can create single or multiple files using the cat command. The data is read from the file and the contents of the files are outputted. You can use the cat command to copy text files and place it in a new document and to view the contents of the file.

  • Syntax

cat [OPTION]… [FILE]…

  • Ex: cat file1.txt file2.txt

This command means that the contents in file1.txt and file2.txt will be read and displayed in order on the screen.

  1. echo

Echo is a built-in and widely used command for Linux C shells, ksh, csh and bash. It is used to display the lines of a text. It is widely used in batch files and scripts. It can also be used as an individual command whenever you want to insert a text.

  • Syntax

echo [option(s)] [string(s)]

  • Ex: echo -e ‘Here\ti\tam\tfeeling\tvery\tlonely.’

The output will be: Here  I  am  feeling   lonely. 

  1. join

As the name suggests, the ‘join’ command is used to combine two files. This command can be used to combine two files that share the same field of data. Basically, it is used to join two files on to the first field.

  • Syntax

join [OPTION]… FILE1 FILE2

  • Ex: join myfile1.txt myfile2.txt > myjoinedfile.txt

This command will direct the output to a new file called myjoinedfile.txt.

  1. sort

Sort command is one of the very useful Linux shell commands that is used to sort the lines in a text file. The data in a text file can be sorted out with this line command and the output can be displayed on the screen. The lines in a text file can be sorted numerically as well as alphabetically using this command.

  • Syntax

sort [OPTION]… [FILE]…

  • Ex: This is a text file, data.txt that contains:

Bananas

Oranges

Kiwis

Apples

To sort the lines in alphabetical order, you need to key in sort data.txt and you  will get output as:

Apples

Bananas

Kiwis

Oranges

  1. merge

If you have multiple files that need to be merged into a single file, then you can make use of the merge Linux shell commands. The merge command will carry out line by line checking of three files, the original file and two modified versions of this file. The differences in the lines between the two modified lines will be corrected to create a single file.

Syntax:

merge [options] file1 file2 file3

Ex: If you have ‘Apples are red’ as orig.txt and ‘apples are really red’ as mod1.txt, and ‘Apples are really red’ in mod2.txt, then the command merge mod1.txt orig.txt mod2.txt will run the mod1.txt output as merge: warning: conflicts during merge.

  1. grep

grep is the short form of ‘global regular expression print’. It will search the input FILEs for any lines that matches with the given PATTERN and prints the matching lines.

  • Syntax

grep [OPTIONS] PATTERN [FILE…]

  1. wc

wc is the short form of the world count command in Linux/Unix OS. The program will read the details in the list of files or the input file and will show out the following details like: byte count, word count and newline count.

  • Syntax

wc [OPTION]… [FILE]…

  • Ex: wc myfile.txt

Here the output will be 3 12 28 myfile.txt, where 3 will be a number of lines, 12 the words and 57 will be the number of characters.

Cheap Linux VPS