Linux full Course

Linux root Directories:


Linux full Course



Linux File Systems: 


bin boot  dev  etc  home  lib  lib32  lib64  libx32  lost+found  media  mnt  opt  proc  root  run  sbin  snap  srv  sys  tmp  usr  var



/bin: Essential binary files and commands required for system boot and recovery.


/boot: Boot loader files, kernel images, and configuration for booting the system.


/dev: Device files representing hardware devices or pseudo-devices.


/etc: System-wide configuration files and scripts.


/home: Home directories for user accounts.


/lib, /lib32, /lib64, /libx32: Libraries required for running programs.


/lost+found: A directory where orphaned files go after a file system check.


/media: Mount points for removable media like USB drives and CDs.


/mnt: Mount points for temporarily mounted file systems.


/opt: Optional software packages and their associated files.


/proc: Virtual file system providing information about running processes.


/root: Home directory for the root user.


/run: System runtime data, including PID files and sockets.


/sbin: System binaries, usually used for system maintenance tasks.


/snap: Snap packages, a package format for application distribution.


/srv: Data for services provided by the system.


/sys: Virtual file system exposing kernel and hardware information.


/tmp: Temporary files and directories for system and user applications.


/usr: Secondary hierarchy containing user binaries, libraries, and data.


/var: Variable data, such as logs, spool files, and temporary data.



These directories collectively organize the file system in Linux, helping to maintain a structured and organized environment for system files and user data.





&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&




Linux Basic Commands:

-----------------------

Reference:

- https://www.hostinger.in/tutorials/linux-commands

- https://www.guru99.com/unix-linux-tutorial.html

- https://www.tutorialspoint.com/unix/index.htm



3. Shell



pwd


cd


ls


Shell/Terminal


cat


cp


mv


mkdir


rmdir


rm


touch



----

AWK

how do you print a particular line number using awk.

----



Pipe

apt-get

Process

push a process in background mode





$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$




Navigation: Linux Commands 


Basic Commands:

  • pwd:   Print the current working directory.
  • ls:        List files and directories in the current directory.
  • ls -l:    List in long format (with details).
  • ls -a:   List hidden files.
  • cd       Change directory.
  • cd :     Move up one directory.
  • cd.      Move to the home directory.
  • cd /     Move to the root directory.




File and Directory Operations:

  • mkdir     Create a new directory.
  • rmdir      Remove an empty directory.
  • touch      Create an empty file.
  • rm           Remove a file.
  • rm -r       Remove a directory and its contents (use with caution).
  • rm -rf      Remove a files directories and its contents forcefully.
  • cp           Copy files or directories.
  • mv          Move or rename files or directories.




Viewing and Editing Files or File and Text Manipulation:

  • cat          Display the contents of a file.
  • more       View a file one screen at a time.
  • less.        View a file one screen at a time.
  • head        Display the first few lines of a file.
  • tail           Display the last few lines of a file.
  • nan, vim Text editors.
  • vim          Open a text editor to edit a file.
  • grep         Search text using patterns.
  • find         Search for files and directories.
  • wc           Count words, lines, or characters in a file.
  • To save changes in vim, press Esc  and :wq



Redirection and Pipes:

  • >, >>.   Redirect output to a file.
  • <          Read input from a file.
  •           Pipe output of one command as input to another.




Process Management:

  • ps:                                  List currently running processes.
  • ps -ef                              List processes.
  • ps aux                             List all processes in detailed format.
  • kill.                                Terminate processes.
  • kill     [p_id]                  Terminate a process by its ID.
  • killall [process_name]: Terminate all processes with a given name.
  • top                                 Monitor system processes in real-time.
  • htop                               Monitor system processes in real-time.
  • jobs, fg/bg                     Manage background processes.




File System Information:

  • uname -a:       Display system information.
  • df -h:              Show disk space usage.
  • free -m:          Display memory usage.
  • df                    Disk space usage.
  • du                   Disk space usage.
  • free, top.        Memory usage.
  • lscpu              CPU information.
  • nproc              CPU information.
  • lsblk                List block devices and manage disk partitions.
  • fdisk:              List block devices and manage disk partitions.
  • mount             Mount file systems.
  • umount           Unmount file systems.
  • df and du        Disk space usage and folder size.




Users and File Permissions:

  • who:           Show who is logged in.
  • whoami      Display the current user.
  • useradd      Create a new user.
  • userdel:      Delete users.
  • passwd      Change a user's password.
  • chmod       Change file permissions.
  • chown        Change file ownership.
  • sudo, su.    Execute commands with superuser privileges.




Package Management (Ubuntu/Debian):

  • sudo apt update:        Update package lists.
  • sudo apt upgrade:      Upgrade installed packages.
  • sudo apt install           Install a package.
  • sudo apt remove         Remove a package.
  • dpkg -i                         [package.deb]: Install a .deb package.
  • apt-get and yum          Install, update, and remove packages.
  • apt (Debian/Ubuntu),    yum (Red Hat/CentOS): Package management.
  • dpkg (Debian/Ubuntu), rpm  (Red Hat/CentOS): Package management at a lower level.




Networking:

  • ifconfig, ip    Show network interfaces and their Network configuration.
  • ping               Send ICMP echo requests to a host.
  • traceroute      Network troubleshooting.
  • netstat            Display Network Connections and Routing tables.
  • ss, lsof           Network and socket information.
  • ssh                 Secure shell and secure copy for remote connections and file transfer.
  • scp                 Secure shell and secure copy for remote connections and file transfer.
  • nproc            To check the number of vCPU Core. 



Archives and Compression:

  • tar -czvf        Create a compressed tarball.
  • tar -xzvf        Extract files from a tarball.
  • zip                 Create a ZIP archive.
  • unzip             Extract files from a ZIP archive.
  • tar                  Archive and compression utility.
  • gzip               Compress files with Gzip.
  • gunzip           Decompress files with Gzip.


Remember to use man [command] to access the manual pages and learn more about each command's options and usage. Linux offers a vast array of commands and utilities, so this cheatsheet covers only the basics.



System Startup and Services:

  • systemctl.               Manage system services.
  • service (SysVinit): Control system services (older systems).
  • chkconfig               Configure system services (older systems), (Red Hat/CentOS).




Miscellaneous:

  • date       Display or set the system date.
  • time       Display the system time.
  • history   Command history.
  • alias       Create shortcuts for commands.




Shell Scripting:

  • #!/bin/bash:   Shebang line in shell scripts.
  • Variables, conditionals, loops, and functions in shell scripts.
  • chmod +x script.sh:   Make a script executable.




Linux Process Management with nohup, nice, bg, fg, jobs, kill Commands


$ jobs          Will show active jobs.

$ bg             Resume jobs to the background.          

$ fg              Resume jobs to the foreground.

$ nice          nice -n -10 process

$ nohup       It will run the tasks or jobs even after closed terminal


$ fg %job_id     Resume a specific jobs

$ bg %job_id    Resume a specific jobs



nice value    Niceness scale goes from -20 to 19. The lower the no. more priority that task gets.

Process priority = nice

eg.

$ nice - 10 process

$ Distros/echo.sh

$ ctrl + Z

$ ps -ef | grep echo

$ ps -l pid                    To check the nice value 

$ kill -9 pid

$ ps -ef | grep echo

$ jobs

$ nice -n -10 /Distros/echo.sh

$ Ctrl + Z

$ ps -ef | grep echo

$ ps -l pid                  Now again see the nice value is been changed from 0 to -10.


Open two terminal parallels:


$ nohup                      

Once you close the terminal jobs get closed automatically that’s why using which we can continue after terminal get closed.


$ nohup ./echo.sh &

$ ps -ef | grep echo   

Now close the terminal and open again you will see the jobs are still running 


$ ls -ltr                         nohup.out

$ less nohup.out.         See the logs or your task output.




$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$





Personal


pwd           — To check Present working directory

cd               — To change working directory

ls                — long list to see the files and directories.

ls  -l            — long list to see the all files and directory details.

ls | nl          — To check the files with number of lines.


cat > filename — to create file with data.

ctrl +D                — Exit from file

сp                        — To copy the file on directory

mv                       — to move files or directories and "rename also"

mkdir                  — to create directories.

mkdir -p             — to create multiple parent directories.

rmdir                  — to remove empty directory

reset                   — reset search history

rm -r                  — To delete only directory

rm -rf                  — to remove file or directory forcefully.

touch                   — to create single on multiple empty files

rm -f                    — remove file without warning.

rm -i file              — Before deleting the file it will ask your permission.

rm -f file              — Delete forcefully.

rm -r file              — Delete file & directory recursively.


mkdir -m <dir_name                    — To create directory with full permissions.

find . - name < filename>             — To find the file whether it is present or not.

find . -name dep*.log                    — Find the files present in directory.

find . -name “*.log"                       — To find all files ending with .log

grep "Error" build.log                  — To find the String in file.

grep - i "Error" build.log              — To see the all string which is starting from small or capital

grep - in "error" ‹filename›             — To see the string in line number.

man grep                                            — To check more commands of grep.

grep error -in build.log                        — to see string with line no.

grep error - A2 - in < file name»         — To see the 2 lines after string error.

grep error - A2 - B2 - in < filename>    to see the 2 lines before 4 after string.

grep error -inc ‹filenames                 — To see the count of string or files.

sudo su                                                   — switch user do as root user.

whoami

sudo su raghunath                            — to be an admin.

apt-get install git

apt-get update -y

lsb-release - a                                   — To cheek linux details.

sudo apt -get install tree - y

yum install or update                         — date (for CentoS, RHEL)

/                                                             — slash means root directory

su root                                            — switch user as root


df .                                  — it will show the current directory space in kb

df -h .                              — To see overall disk space in GB

df -h                                — To see the space of all file & directory

du <filenames>              — To see file uses details

du -h < filename>          — To see the space details in MB, single file or directory

du -sh <dir-name>         — see the details in MB


vim /etc/sudoers             — to change permission

:q!                                          Exit forcefully

head <f.name>               — To see top 10 lines if contents

head - 5 <filename>         — To see top 5 lines

tail <filename>               — To see bottom 10 lines file contents

tail - 2 < f.name>           see last 2 lines

head - 10 <filename> | tail - 2 < filename> To see top 10 and last 2 lines of file contents.



cat < filename>                —To see file content

cat -n < f.name>               — To see content in lines

cat >> filename               — To add content in same files

cat -n < filename> | grep error             — To see the string in line number.

cat file1 file2 > file.txt                            — To store or merge file1 file2’s data in file.txt

cat logs.yaml | grep -i hostname        — To check the exact words in files

cat logs.yaml | grep -i "hostname:"  — To check the exact words in files



grep -iv error <filename>                             — To see file contents without string like inverts

egrep -i "Error | Exception" < filename>     To see the multiple strings.

egrep "error | Error" <filename>                 To see the multiple strings.

grep - iw " Error Exception" < filename›      to see exact matching word or string


cat build.log | grep -i error | grep exception — to see both string together in all lines

clear                                                                  — clear the screen


diff <filename> < filename2>         — To cheek the diff. b/w two files

vimdiff <filename> < filename2>   — To see the file contents in two different windows

ctrl + ww                                           — to jump another window

diff -c

diff -u

diff -i


tar -xvf <filename>                              — to extract the tar file

tar -cvf filename.tar <filename>         — to create tar file


ls -l

ls -a 

ls -al

ls -latr  


chmod 777 build.log                      — To change file permission.

sudo chown sally <filename>        — It will change file ownership.   

chown Raghu:Raghu build.log     — To change the file ownership.

sudo chown A:A build.log             — To change the file ownership with group.


mkdir .                                    — To create hidden directory. 

touch .                                     — To create hidden empty file.

rm -rf *                                   — To remove everything in current directory.


ps -ef | grep firefox    — To see Firefox process and it’s details.

jobs                    — To check the process which is running in background mode.

ps -ef                  — In Linux, ps -ef is a command that displays information about running processes on the system.

kill 2124           — To stop forcefully.

kill -9 2124       — it will kill the process forcefully.


deploy.sh        

— it is a script which will run for 30 minutes, if wants to stop then press ctrl + c.


sleep 100 &       — To run script in background.

fg1                     — To see background mode.

sleep 1000 &  

fg3                      — To bring it back.

ctrl c or x           — Exit from it.


ping google.com       — To check the mission which is working in Linux.

wget <url>                — To downloads.


wget -P /home/user/directory <url>  — To download in a particular directory.


ssh 172.17.0.2             — To connect mission with ip address.

uname -a                     — To check user_name with linux details.

hostname                    

top                               — To see the Memory and CPU Utilization.

history

man —help                 — To see more commands related man.

echo hello


zip file_name.zip <file_name>     — To zip a file.

uzip <file_name>       

vim /etc/hosts                 — To copy ip address and paste as another hosts

:q!                                     Exit forcefully without any changes.

vim /etc/hostname         — To give another name then logout & login again.

echo $SHELL                — To see /bin/bash.


a = 10

echo $ a


sudo useradd -md /home/Raghu -s /bin/bash Raghu

id raghu

sudo passwd Raghu

sudo userdel Raghu

vim /etc/sudoers                    — To add permissions.       


$$$$ Search vimcheatsheet, gitcheatsheet, mavencheatsheet.

vim.vimrc                                — To set numbers.


vim - O <filename> <filename2>  

— it will open on two terminal with same screen.


evince filename.pdf                To open pdf files in linux terminal.


cd ..               — Back to previous directory.

ls -lt               — shorted last modified time.

ls -ltr             — To see reverse output.

ls -R              — Lists all the files in the subdirectories.

ls -lh              — Show the file size such as MB, GB, TB.

tac file.txt     — see the data in reverse order. 


Shell/Terminal

seq 10                — To print number from 1 to 10.

ls /etc/init.d       — it will bring up a list of currently running services.


sudo systemctl restart <service_name>        

— To restart running & stopped services.


cp build.txt pom.txt            

— To copy data from build.txt to pom.txt but the data is presented in pom.txt will be replaced from file.txt.


touch /home/Raghunath/Documents/web.xml    — Create file inside particular directory.


sudo apt-get install locate

locate -i <string_name>    — Locate string name using locate command.

grep -in “yes” hello.txt      — To check file that contain “Yes” words.

apt list —upgradable        — To check upgraded packages.

stat <filename>                  — To see time stamp like access time and modify time.


$ touch -a <file_name>                — To change access time.

$ touch -m <file_name>               — To change modify time.

$ nano file1                                    — To create file and write data into it. 

$ crtl + X, Y                                   — Exit from nano and save with $Y.

$ hostname -i                                 — Check ip address with machine details.

$ cat /etc/os-release

$ chmod u=r, g=rwx, o=x file_name

$ chmod 777 <dir_name-file_name>

$ chmod u+w, g-w, o+r

$ chgrp <g-name> <new-g_name>     — To change group name.


$ cd ~            — come to home directory directly.

$ sudo !!       — it will run previous command with sudo.

$ history

$ ! 220           — it will execute command automatically.




$$———————————————————————————$$

 

 


Thanks 🙏
















        






 
















Previous
Next Post »