Linux Fundamentals + Servers Basics : Udemy


Sat Jul 24 2021 13:41:12 GMT+0000 (Coordinated Universal Time)

Saved by @jpannu #linux #server

           /* Common Commands */

man //It is the 'manual' for all the commands in the linux system. 
> man ls //It will provide manual for 'ls'
> man touch //It will provide manual for 'touch'
> man man (All the manual will be displayed)
> man -k search //It will provide all the keywords related to 'search'.
> man -k jaskara //It will provide all the keywords related to 'jaskara'

which //It will provide the location from where shell is using the command.
> which touch //It will return the location of 'touch' cmd.
> which ls //It will return the location of 'ls' cmd.

 uname // This cmd will provide the system OS basic information.
uname -a | uname -i | uname -m

sudo parted // "Hard drive" details
parted -l //Provide partition of the HDD

sudo shutdown -h now //It will immediately shutdown the system
sudo shutdown -h +10 //It will shutdown the system in 10minutes.   
sudo shutdown -h +10 "System Will shutdown in 10minutes, Please Save your Work"//It will shutdown the system in 10minutes with the Prompted information.   
sudo shutdown -r now //It will Reboot the system.
sudo shutdown -c // To cancel the scheduled shutdown. 

pwd //Print Working Directory. ( It will provide the current directory)

cd //Change directory.
> cd /  //This will take to the parent directory.
> cd /childFolder/ChildsChildFolder/ // This will take the folder. But we should be in the current node to get to the child.   
> cd ~/desiredFolder //It will directly take to the desired folder. We don't have to worry about the current node.
> cd ..   //It will take to the previous directory
> cd ../..  /* Will take two directories back*/
> cd ../../..  /* Will take three directories back*/
> cd ~ //It will take to home directory

ls // It will Provide all the list items/files in the relative directory
> ls -l // It will provide detailed information.
> ls -alh  
> ll
// It will provide easier format to read.
> ls test* //It will only look for folders starting with string 'test'.
> ls *est //It will only look for folders ending with string 'est'.

> find / -name fileName* //it will find evrything starting          with 'fileName'.( might have to add sudo )
mkdir //It is used to create new folders. 
> mkdir folderName1
> mkdir test{1..5} //It will create 5 folders with pattern test1...test5.
> mkdir test{a..d}
touch // It will create new File(blank) in the directory.
> touch index.html
> touch script.js
> touch index.html style.css script.js //It will create all three files.

mrdir //It is usded to delete folders.

rm //It is used to remove files/Folders.
> rm index.html
> rm index.html style.css script.js //It will remove all three files.
rm -r folderName //Will delete all child data ( 'r' is recursive )
> rm -r test{1..5} //It will remove all the files with provided pattern

cat //Concatenate FILE(s) to standard output.
    //It can also be used to view files/data
    //It can only view text files.
> cat text.txt // It will print the 'text.txt'
> head text.txt //It will display the first 10 lines of the 'text.txt'
> head -2 text.txt //It will display first 2 lines.
> tail text.txt //It will display the last 10 lines of the 'text.txt'
> tail -2 text.txt //It will display last 2 lines.

> cat fileName (press double 'Tab') //It will return all the files starting with 'fileName'(s)

 grep //...
     //This can be used to filter data.
> sudo grep opened /var/log/auth.log //It will provide all the 'opened' in 'auth.log' file.

date //It will return date information.


                 /*General Theory */
- Linux is case sentitive
- Relative : Present location ( Current directory)
- Absolute : Location from Root.
- Sudo group : A group of superusers that can access the root account and be receive unlimited privileges.


              /* Ubuntu Server */

> sudo updateddb //It will update the database.

> locate fileName 
> locate test* //It will return all files starting with 'test'  

              /*  Managing User */
//ONLY super user can add user on the system.
 //To Add User.  
> sudo useradd -d /home/dUserFolder -m dUserName
//It will add 'dUserName' as a new user name on the system
> sudo passwd dUserName
//It will create the password for 'dUserName'.

//2nd way to Add User. ( better way )
adduser //It is a script to 'add user',(not a command)  
> sudo adduser dUserName
//It will automatically create user and it's respestive folder and will ask to create password for it.

> cat /etc/group
 //It will return all the groups on the system. 
> cat /etc/group | grep dUserName
//It returns the 'group'(s) of user name 'dUserName'


              //Modify Users

//Add Group to user.
sudo usermod -aG groupName UserName
> sudo usermod -aG sudo dUserName
// We are adding 'sudo' group to user 'dUserName'.

> su UserName1
//It will change the terminal to 'UserName1'

//Lock User
> sudo usermod -L dUserName

//unlock User
> sudo usermode -U dUserName

//   /etc/passwd
> cat /etc/passwd
 //It will provide all the user's on the system ( including system groups ).

> sudo vipw
//It will display all the User's in a nano editabled list.
// Remove the need groups by using CTRL+K(To remove the line/group ) > CTRL+O (over write) > CTRL+X (exit).
//Removed groups will not show in the '> cat /etc/passwd'

//2nd way to remove group
> groupdel [options] GROUPNAME

//  /etc/shadow
//It will return all the user's and there respective password and password data ( encryption used + Password expiration information ) . 

//Remove User
> deluser [--remove-all-files] [--backup] [--back-to DIR] dUserName
//It will remove the user and also the create the back for it.


            /*   Managing Groups  */

> sudo addgroup groupName1
//It will add 'groupName1' to the user.

> grep groupName1 /etc/group
//It will return the information about 'groupName1' 

> groups
//It will return all the groups for the user.

> ll text.txt  
> ls -alh text.txt
 //It will provide the basic information about the file, inclduing permissions it has. 

-1 - 2- 3 -4
//Here Numbers are different groups. 
rw : read and write
r : Read.
x : executable file

To change Groups:
> sudo usermod -g newPrimaryGroup dUserName
//'newPrimaryGroup' Will be the primary group.

//Where can we keep the files to share data between different users. 
/srv - for files that may be shared using a service externally.

//To modify the permission for user on the group.

//It will make new folder,
> sudo mkdir /home/newFolder

 //Adding new group
> sudo addgroup grpName1

// Group 'groupName1' will have access to 'newFolder' folder.
> sudo chgrp grpName1 /home/newFolder


           /*  Managing Text Files  */

vim | nano
//Two popular linux terminal's IDE.

// VIM

> sudo app install vim
//In case if VIM is not installed by default.

> vim filesName.text


     /* Linux Structure */

- man hier
//It will return the structure of the Linux system and basic idea about all the files.


         /*  Remote Access    */

- SSH works on TCP.