Linux Commands Handbook
Linux Commands Handbook
Linux Commands Handbook
(LINUX HAND-BOOK)
_ _
| | (_)_ __ _ ___ __
| | | | '_ \| | | \ \/ /
| |___| | | | | |_| |> <
|_____|_|_| |_|\__,_/_/\_\
Chapter 1
Linux Basics.
OS family : Unix-like
Unix is also an operating system like Linux. It is a commercial OS. It consists of three
parts: Kernel, Shell and Programs. Most of the Unix and Linux commands are similar in
nature.
Our Linux tutorial includes all topics of Linux OS such as Linux commands, Directories,
Files, Man Pages, File Contents, File Permissions, shells, VI editor etc.
Chapter 2
Linux Commands.
Lecture Wise
Lecture - 1
Lecture - 2
13. cp => for copy $ cp source destination
14. mv => for moving contents $ source destination
15. cal => calendar
16. date => date
17. cat > filename then ctrl^c
18. cat >> filename
19. touch
20. vi
21. echo “message”
22. echo “message to file” > filename.txt
Lecture - 3
23. ping $ ping google.com
24. ps
25. kill -9 process_id
26. Chmod => rwx, ‘a’ll , ‘g’roup , ‘o’wner , ‘u’ser ,
27. grep “pattern_to_match” filename
28. sudo apt install <package_name>
29. sudo apt remove <package_name>
30. who
31. whoami
32. passwd
33. reboot
34. exit
--------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
-----------------------------------------------------------------------------
via cli
39. sudo su sgsits_username_cse000123
via gui
$ swtich user
*******************************************************************************************
A
$ cat /etc/shells
cd Change Directory
$ cd .. // go to previous directory
$ cd <to_specific_path>
$ export
http_proxy=http://address:port
¯_(ツ)_/¯
$ help
$ make
$ passwd <user_name>
$ split filename
$ split -n 2 filename
$ tail file_name
$ tail -n 2 file_name
vi Text Editor
$ vi
$ who
$ whoami
Chapter 3
USER AND GROUPS.
1. For adding group
Chapter 4
TEXT EDITORs.
Emacs Xemacs – a GUI-based version of Emacs.
A text editor, written by Bill Joy in 1976. Short for Visual Interface. It enables fast,
simple, and effective text editing mostly based on simple key bindings. It provides fast
and convenient moving around files and between files. One must learn a good number
of commands to be proficient in vi.
Command mode:
Allows you to do global operations like saving the file, searching for a string
$vi file_name
Save a file
$:w
$:q!
$:wq $:x
vi file_name
Save a file
:w
file) :wq :x
Chapter 5
GREP
search pattern
Search hello in any case (i.e. case insensitive search) flag = -i // for case insensitive
search $ grep -i 'hello' main.c
Search hello and world in any case flag = -i // for case insensitive search flag = -E // for
extended regular expression
GENERAL
2. REGEX
3. search for word which has any single character followed by ello
5. AND & OR
9. show only the matched string, not the entire line in which it is
x14.04/bash/*
11. print the name of the file(s) which matches the query
15. print 3 lines after the match (-B for before the match & -C for
Chapter 6
PERMISSIONs.
LINUX is a multi user os.
How to read this? Where is a letter put a 1 and where is a - put a 0. Examples:
UGO
rwxrwxrwx
111111111
So, user, group and others can read, write and excute the file or folder
UGO
r w - r -- r - x
110100101
So, user can read and write, group can only read, finally other can
000 0 - - -
001 1 - - x
010 2 - w -
011 3 - w x
100 4 r - -
101 5 r - x
110 6 r w -
111 7 r w x
So, if I run
$ chmod 777 file <=> rwx rwx rwx
Or I run
only user can read, write and execute, group and others
Chapter 7
SED, AWK
SED
sed:
The sed command is a stream editor that works on streams of characters. It’s a more
powerful tool than grep as it offers more options for text processing purposes, including the
substitute command, which sed is most commonly known for.
Replace the first occurrence of a string in a file, and print the result: sed
of find
AWK awk: The awk is a full-fledged programming language that is comparable to Perl. It
not only offers a multitude of built-in functions for string, arithmetic, and time manipulation
but also allows the user to define his own functions just like any regular scripting language.
Text processing,
Print the fifth column in a space separated file: awk '{print $5}' filename
Print the second column of the lines containing "something" in a space separated file:
awk '/something/ {print $2}' filename $ awk '/Hello/ {print $2}' main.c
Let us create a file marks.txt which contains the serial number, name of the student,
subject name, and number of marks obtained.
1. roll_number_1 os 80
2. roll_number_1 compiler 90
3. roll_number_1 ds 87
4. roll_number_1 linux 85
5. roll_number_1 coa 89
(OR)
$awk ‘BEGIN {print “Processing has begun”}; {print $2}; END {print “Processing has ended”}’
marks.txt
Chapter 8
Basic Shell Scripting
Exercise_1 - Write a shell script that prints “Hello World” on the screen
\#!/bin/bash
Exercise_2 - Modify the shell script from exercise 1 to include a variable. The variable will
hold the contents of the message “Hello World”
\#!/bin/bash
NAME=”Hello World”
echo $NAME
Exercise_3 - Store the output of the command “hostname” in a variable. Display “This
script is running on .” where “” is the output of the “hostname” command.
\#!/bin/bash
HOSTNAME=$(hostname)
echo “This script is running on $HOSTNAME”
#/bin/bash
read -p "Your name: " name
echo "Hello $name"
#/bin/bash
read -p "Webpage address: " webpage
#echo "Hello $webpage"
wget --no-check-certificate --content-disposition $webpage
Final summary
So, finally we worked with
3. Bash Scripting.
4. ...
Chapter 9
Gnu Coding Standards
Write Better Codes
C
Type 1
#include<stdio.h>
void main()
{
printf("Hello World\n");
}
Type 2
#include<stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
Type 3
#include<stdio.h>
int main(int argc, char *argv[])
{
printf("Hello World\n");
return 0;
}
Type 4
#include<stdio.h>
// Entry point function
int // return type
main(int argc, char *argv[]){
printf("Hello World\n"); // main
definition
return 0;
}
Type 5
#include<stdio.h>
// declaration
void print_message();
void
print_message(){
printf("Hello World\n");
}
int
main(int argc, char
*argv[])
{ print_message();
return 0;
}
Type 6
#include<stdio.h>
// declaration
void print_message(char *);
// def
void
print_message(char
*message){
printf("%s\n",
message);
}
int
main(int argc, char
*argv[])
{ print_message("Hello
World"); return 0;
}
Type 7
#include<stdio.h>
// declaration
void print_str(char *);
void print_int(int);
void print_float(float);
void
print_str(char
*message){
printf("%s\n",
message);
void
print_int(int i){
printf("%i\n", i);
}
void
print_float(float f){
printf("%f\n",f);
}
int
main(int argc, char
*argv[])
{ print_str("Hello
World"); print_int(50);
print_float(2.5);
return 0;
}
Chapter - 10
------------------------------------------------------
C Header file and
Make Header Files
Create your own Header
Files Make
Redirections :
Input redirect :
$ ls < $(pwd)
Output redirect
$ ls -l > ok.txt