Linux / Unix basic commands for beginners - CloudMinister

Linux/Unix

Linux is a clone of Unix operating system, it is a multi-user operating system, which can be accessed by many users at a time.

Linux Server Management

Linux server management service is a cost-effective mixture for the application-based server. Essential applications deployed on Linux servers need the right management solutions or tools. Large enterprises and end-users require robust Linux servers to manage applications for their business.

In this tutorial, you will learn the very basic Linux commands that will help you to get more familiar with the Linux command line. This will also help you to sharpen the commands line in Linux as well as also help you in enhancing your capability of getting an expert in this field.

Commands

The commands in Linux have the following syntax:

$command options arguments

 

 Bash/shell: Program that provides text-only interface.

 Terminal: A terminal window

 Command-line   : Anything that takes input

 Console: Physical instrument panel

1) $ls                           :  Used to show the folders & web files

2) $ls -a                      : List all the files and folders.

3) $ls -l                        :Used to list folders with permissions

Linux / Unix basic commands for beginners

4) $ls Do*   : Listing all the folders starting with Do also print inside files

5) $ls .*       : Listing all the files starting with (.)

 Linux / Unix basic commands for beginners

6) $ls -a       : listing all the folders and files, including hidden files

7) $cd          : To jump in the folder

8) $cd ..       : To go back to the folder.

9) $cd ../..    : To jump back to the two directories.

10) $mkdir     : To make the directory/folder

11) $mkdir -p : To make the directory/folder one to one inside in it.

Example:

Linux / Unix basic commands for beginners

12) $mkdir -vp : to make the directory and it will print the dir. created.

              Example-

 Linux / Unix basic commands for beginners

13) $touch pop : to make the new file(pop) in folder

14) $touch grapes oranges : to make a recursive file(grapes,oranges) in a folder.

15) $mv : to move the file from source to destination.

16) $cp : to copy a file from one folder to another.

17) $rm : Delete the file or folder

18) $rm -r file name/ :  Remove the folder

19) $rm -r a b c : remove the files from the folder

20) $whereis (command name) : To find the actual path of the command.

21) $echo -e “paul nlikes necho”

Linux / Unix basic commands for beginners

  • It will print each char in next line

22) $ x=paul

23) $ echo  “ $x nlikes necho”

 Linux / Unix basic commands for beginners

  • It will also print the x value

Find command

Find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments. Find can be used in a variety of conditions like you can find files by permissions, users, groups, file type, date, size, and other possible criteria

 

Note: (.) is for the current directory

24.) $ find . -name file_name / dir._name

    Used to find the file/directory in the current directory

Linux / Unix basic commands for beginners

25.) $ find . -type f/d -empty

    To find the empty dir/ file     ** f for file & d for directory

Linux / Unix basic commands for beginners
Linux / Unix basic commands for beginners

26) $ find . -mtime  -1

   To find the file/directory which is made within one day

Linux / Unix basic commands for beginners

27) $ find . -mtime  +1

   To find the file/dir. which was made 1 day ago

28) $find . -mmin 1

   To find the file/dir. which was made 1 min ago/  To find the file/dir which is made within 1 min.

Linux / Unix basic commands for beginners

 

29) $ find ./ type d/f -name file/dir

   To find the directory / file

        ** f for file and d for directory

 

30) $ find . *.extension

   To find the all file which is with the assigned extension.

        ** here there is no .jpg file available

Linux / Unix basic commands for beginners

 

31) $ find dir.name

   To show all the files and directories

Linux / Unix basic commands for beginners

32) $ find -iname “char*”

   To find all the files and dir. starting with the f* and -i not including case sensitivity

Linux / Unix basic commands for beginners

33) $ find ./ -type f/d -iname “f*”

   To find file or directory with disable case sensitivity and listing files / dir with f*

Linux / Unix basic commands for beginners

34) $ find . -size +0

   This will show the file presented in the current directory which is more than 0 mega byte.

         ** G = GB

         ** K= KB

Linux / Unix basic commands for beginners

35) $ du -sh file/dir

    It will give the size of the file or directory in KB

Vi editor

Linux / Unix basic commands for beginners

After $ vi d1 write the text by pressing (I for Insert )click→ Esc→ shift + :→ wq → Enter

Linux / Unix basic commands for beginnersLinux / Unix basic commands for beginners

GREP – Global Regular Expression Print

“It allow us to search text within files in a system”

36) $ grep [binary digit] file_name

   It will search the binary number which are inserted in the square bracket.

Linux / Unix basic commands for beginners

37) $ grep -w “string” file_name

   It will only show the valid text inserted in the inverted commas.

Linux / Unix basic commands for beginners

38) $ grep -i “string” file_name

   It is non-case sensitive command (  -i )

Linux / Unix basic commands for beginners

39) $ grep “string” file_name

   Show all the matching text.

Linux / Unix basic commands for beginners

40) $grep -win “string” file_name

   Show at which line the text resides.

Linux / Unix basic commands for beginners

41) $ grep -win -B 4 “string” file_name

  Show the 4 line before the inserted text.

Linux / Unix basic commands for beginners

Show the 2 lines above and below the text.

Linux / Unix basic commands for beginners

Show the 2 lines after the text

42) $ grep -win -A2 ‘String” d1

Linux / Unix basic commands for beginners

43) $ grep -winr “string” ./*

   [centos@localhost ~]$ grep -winr “cat” ./*

   It will show all the files and folders with the string.

AWK command (Aho, Weinberger and Kernighan)

 

It is just a scripting language used to it doesn’t require compilation time and it generates reports by processing file. It is beneficial for pattern searching and processing files.

Various programming concepts offered by AWK are:

     1) Output formatting

     2) Inbuilt variables

     3) Pattern matching

     4) String operations

     5) Arithmetic operations

Basic syntax

# awk options ‘selection _criteria {action }’ input-file > output-file

Awk assign some variables for each field.

→ $0 denotes the whole file

→ $1 denotes the first field

→ $2 denotes the second field

     And $3,$4,$5…..so on for every field.

Commands related AWK

 

44) # awk ‘{print $variable}’ file_name

   This command will print the field according to the variable

Linux / Unix basic commands for beginners

Linux / Unix basic commands for beginners
Linux / Unix basic commands for beginners

45) # awk –version

   We can also check the version of the awk.

         # awk -F: ‘{print $variable}’ filename

This will print the file without the separator (i.e. [:])

Linux / Unix basic commands for beginners

Linux / Unix basic commands for beginners

46) # echo “string” | awk ‘{$variable=”string”; print  $variable}’

    This will replace the string manish to raghav  and print the whole string.

 

Linux / Unix basic commands for beginners

47) # cat file_name | awk ‘{$variable=”string”; print $variable}’

   This command  will replace the particular string which is in field 2 and  print the whole file content.

Linux / Unix basic commands for beginners

48) # awk ‘/string/’ file_name 

   This command will show each line that contains the following word i.e.( or )

Linux / Unix basic commands for beginners

49) # awk ‘$variable==”char” {print $variable}’ file_name

   T

his will print 5th field if the field 1 value matches the value 300 in the file.

Linux / Unix basic commands for beginners

CUT command

 

The cut command basically a Unix command line utility which extracts section from each line.

Basically the cut command slices a line and extracts the text.

50) # cat -b variable file_name

     This cut command will extract the following byte (-b) from the file.

Linux / Unix basic commands for beginners
Linux / Unix basic commands for beginners

51) # cut -d ‘delimiter’ -f field/ranges/sequence file_name

   This command will show the following fields/ranges from the file

   if -d option is not used then it prints whole line:

Linux / Unix basic commands for beginners

Linux / Unix basic commands for beginners

52) # cut -c variable file_name

   This command will print each character from the file starting from 1st field.

Linux / Unix basic commands for beginners

53) # cut –complement -d “  “ -f variable file_name

   This command will print each field except the 3rd field

Linux / Unix basic commands for beginners

54) # echo field >> file_name

   This command will permanently add on the field at last into the file

Linux / Unix basic commands for beginners

55) # cut -d “ “ -fvariable file_name

    This command will show only the 3rd field from the file

Linux / Unix basic commands for beginners

SED command

 

It is also called stream editor, it is a powerful linux/unix utility tool used for text manipulation, finding, deletion, saving permanently, etc.

s: means substitute

g: means globally

56) # sed ‘s/string1/string2/g’ file_name

   This command will change the string1 to string2

Linux / Unix basic commands for beginners

57) # sed /bstring1b/string2/g’ file_name

   This will replace the exact matching word list into raghav in the file.

Linux / Unix basic commands for beginners

58) # sed ‘s/^string1/string2/g’ file_name

   This command will change the value which ends with $ sign in the file.

Linux / Unix basic commands for beginners

Deletion 

 

59) # sed ‘/word/d’ file_name

  This command will delete the particular line which consists of the particular word.

   ‘d’ denotes the delete.

Linux / Unix basic commands for beginners

Saving permanently to the file

 

60) # sed -i ‘s/char1/char2/g’ file_name

Linux / Unix basic commands for beginners

-i → use this -i ,if you want to change or modify directly to the file

        This -i can be used at the above sed commands this will permanently save every modification in the file.

 

Conclusion: By following this tutorial you will get the basic understanding of Linux commands

Learn how to scale, manage, and optimize your applications with a SLB. Read our solution brief "Get More from Your Enterprise Network".

DOWNLOAD SOLUTION BRIEF

Get started with CloudMinister Today