#### commands info
man ls 			    # manual and all "ls" info
whatis ls 		    # quit description for what is ls 
apropos list        		# search what tool to do this function
whoami
sudo adduser mohamed 		# add user
usermod -aG sudo mohamed 	# add sudo user
shasum  file 				# see file hashing


### file mangement  1-ordinary files 2- special files 3-directories  

pwd 				# current directory
ls  				# list
ls -l  				#  with all informations
ll
ls -il
ls -a 				# with all hidden files
ls -i 				#  inode number of files (index of file)
find /home/boyka -inum 1150561 #find file with inode number

### creating files

cat>file_name 		# Create a file and enter data and ctrl+D to save the file 
cat file_name 		# display the file data 
touch file_name2    # create and save empty file

### move - rename - copy - delete

mv file_name file_name_new					   # rename a file or move the file
mv file_name /home/boyka/Desktop
mv * /home/boyka/Desktop 					   # use regex to selet more than file to move
mv f* /home/boyka/Desktop
mv /home/boyka/Desktop/file_name .             # . mean the final same location of the file 
cp file_name /home/boyka/Desktop 			   # copy 
cp file_name /home/boyka/Desktop/file_name_new # copy with new name
rm file_name file_name2 					   # delete specific files
rm * 										   # delete all files

### display files

cat file_name 		# dispay file data
wc file_name 		# display (n1 n2 n3 file_name) its count (line_num  words_num  char._num)
wc -l file_name 	# number of lines
wc -w file_name 	# number of words
wc -c file_name 	# number of char.

### standard linux streams (this built-in files work when we creating script or program)

stdin 				# (0) this file take the input
stdout 				# (1) giving the output
stderr 				# (2) work and detect errors

### directory mangement [hidden files get crated by defalult when create directory { (.)-the informations of current dir (..)-the information of level above dir }]

cd 					# change directory
cd .. 				# step back
mkdir 				# make directory
mkdir boyka\ tasks  # \ to make directory with space separate name (boyka tasks)
ls -la 				# show detail informations with hidden files/directories
mv -r 				
cp -r 

### permissions [ owner - group - other ] >>( read - write - execute )

# [file/dir|owner|group|other]
-rwxr-xr-x          # [-] file
drwxr-xr--  	    # [d] dir

# change with symbolic method [u: user / g: group / o:others]
chmod u+x file_name   		# add permission to user
chmod u-wx file_name		# remove permission from user
chmod u=rwx file_name		# set the permissions of user
chmod u+x,g-w,o=r file_name
chmod a=rwx file_name 		# set for all (u,g and o)

# with octal mehod [0:--- , 1:--x , 2:-w- , 3:2+1 , 4:r-- , 5:4+1 , 6:4+2 , 7:4+2+1]
chmod 775 file_name   		# 7 for user , 6 for group and 5 for other
umask 						# (0002) get the number that represent the default permissions for new files or dir created [7777-umask=permissions_num]
umask 027  					# change umask number [7777-7027=0750] umask_new=0750

### Environment Variables
env                         # show the default variables declars in the environment
env  boyka="kshckhdjoj"     # declare my own env. variable

.profile                    # the file that run automaticaly when you start .... if it contains nothing the system skiped it and go to home directory
.bash_history               # bash comands history
.bash_logout                # log out task


### Basic Utilities ( printing - sending a mail) 
#   mails in localhost >> var/spool/mail

pr option(s) file(s)        # ex: pr -2 file | more  >> this will make two colomns
lpr file                    # send to printer
 
$ mail -s “Enter the subject” user1@domain.com
$ mail -s “The Subject” user1@domain.com < /root/testemail.txt  # Send message from a file
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” user1@domain.com 
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” user1@domain.com,user2@domain.com  # Multiple recipients
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” -c user1@domain.com,user2@domain.com # CC and BCC
$ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” –r “Tom<tom@gmail.com>” user1@domain.com # Specify From name and address
#  Specify “Reply-To” address
    $ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” replyto= tom@gmail.com user1@domain.com

    $ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” replyto= “Tomtom@gmail.com” user1@domain.com
# Attachments

The option –a is used to add an attachment along with the email.

    $ echo “THIS IS A TEST EMAIL” | mail -s “Enter the subject” –r “Tom<tom@gmail.com>” –a /path/to/file user1@domain.com


### pipes and filters

# pipe >>>>   A pipe is a means by which the output from one process becomes the input to a second. In technical terms,
#             the standard output (stout) of one command is sent to the standard input (stdin) of a second command

command_1 | command_2 | command_3 | .... | command_N 
$ ls -l | more                          # list and get the --more-- option == {  ls -l > temp , more < temp , rm temp}
$ sort record.txt | uniq                # This will sort the given file and print the unique values only
$ cat sample2.txt | head -7 | tail -5   # select first 7 lines and last 5 lines from the file and print those lines which are common to both of them
$ ls -l | find ./ -type f -name "*.txt" -exec grep "program" {} \; # select files with .txt extension in the given directory 
                                                                   # and search for pattern like “program” in the above example and print those ine which have program in them
$ cat result.txt | grep "Rajat Dua" | tee file2.txt | wc -l     # select Rajat Dua and store them in file2.txt and print total number of lines matching Rajat Dua


# filter >>>> A pipe can pass the standard output of one operation to the standard input of another, 
#             but a filter can modify the stream. A filter takes the standard input, does something useful with it,
#             and then returns it as a standard output. Linux has a large number of filters. 
#             Some useful ones are the commands awk, grep, sed, spell, and wc. 

 head -n      # Show the first n lines.
 tail -n      # Show the last n lines.
 sort         # Sort lines in a given way [sort -n file , sort -r file , sort -nr , sort -f ].
 wc           # How many words, characters and lines.
 grep         # Search for a given pattern.

 ### File editors [ ex. : gedit - nano - vi,vim ]
 
 ifconfig  

#to check connectivity between my machine and any ip 
ping www.google.com  #or by ip 

# the resolution between every MAC and IP
arp   #Address Resolution Protocol

# to connect to file server (up and down files)
ftp  					  #File Transfer Protocol
	> open ftp.microsoft.com  # entry with usr name and password
	> bye					  # for exit

#for get IP address for any site
nslookup 
	> www.google.com
		Server:		192.168.1.1
		Address:	192.168.1.1#53

		Non-authoritative answer:
		Name:	www.google.com
		Address: 172.217.18.36
	> exit

#to recognize the routing table components of my device
route

# show all my device connections 
netstate

# to scan ports
nmap 127.0.0.1 
nmap -p 1-65535 127.0.0.1    	# -p to choose a range
nmap -p 1-65535 -m 10 127.0.0.1 # -m to issues several prob requests at the same time
# Scanning Multiple Hosts 
nmap host1 host2 host3          # by names or ip
nmap 192.168.1.*                # warning: never try to scan *.*.*.*  on any machine connected to the Internet
nmap 192.168.1.0/24				# by CIDR notation
# scanning ranges
nmap 192.168.1.10-35
nmap 192.168.1,2,3,4.10
nmap 192.168.1,2.3,4.10-35           
# nmap flags and options
-sT 				Perform a full open TCP scan 
-sS 				Perform a SYN (stealth) TCP scan 
-sU 				Perform a UDP scan 
-sR or -sV 			Perform an RPC service scan (should be used in conjunction with another scan type) 
-A 					aggressive scan for more info
-O 					Try remote OS detection 
-O --osscan-guess 	guess the OS if not detected
-P0 				Donít try to see if a host is up before scanning it 
-p 					<port range> Specify a range of ports to scan 
-M 					<max connections> The maximum number of parallel connection attempts to make at one time. For LANs, should be no more than 18. For slow links (WAN, Internet), this can be significantly higher. 

# to capture and analyze network traffic going through your system and for troubleshooting
tcpdump 
-x 							# display all packet in hex
-s 1500						# snap length ,1500 byte,if 0 means show all packet
-w file  					# to write in file
-r file