Skip to main content

Linux Commands

 

Linux Commands

1. OS-Release

-cat /etc/os-release
-cat /etc/redhat-release

show os //kernal information
-uname 

show kernal middleware
It is intermediator between hardware and software.
-uname  -r
what is process architect.
-uname -p
To show all information
-uname -a

2. Date-CAL

-date
-cal

3. Booting in Linux (Run-Levels)

Shutdown/Close pc
-init 0 
Single user mode
-init 1
Multiple user mode
-init 2
Multiple user mode with network plus full support
Not use
-init 4
Graphical mode
init 5
Reboot the system
-init 6

4. Target command in Linux (systemctl)

With the help of target we can manage system specific as well as user specific task.
Target command is system Control (systemctl). Basically it is utility, which build to replace 'init' command.
What systemctl can do ? 
We can find its all commands with the help of single command.
write systemctl enter twice TAB button.
//it will list all its commands.
Show current system mode
- systemctl  get-default
Change  current system mode to multi-user mode.
-systemctl isolate multi-user.target
To set permanent mode
systemctl set-default multiuser.target
Note: systemctl only work on redhat + CentOS operating system.

5. systemctl mask

When you don't want to start again the stopped service.
exp: You might have two conflicting services in your system and you don't want to start both at once than you have to restrict one service with masking.

Masking service
-systemctl mask <servicename>
Show list of masked services
-systemctl list-unit-files --type=service | grep mask
To unmask service
systemctl unmask <servicename>

6. Disk and partitioning in OS

Show list disk allocation information
-fdisk -l
Show list RAM storage with swap
-free
-free -m
-free -g

7. File types in OS

Normal(-), Directory(d),
Link a) soft link(l) b) hard link(No symbolic symbol)
Device file 
a) block file(b)
b) character file(c)
Pip file(p)
Socket file(s)
Show list file with their types
-ls -asl
-ll
-ls -l

8. ls commands in linux

Show hidden files and diretories
-ls -a
Show present directory
-ls .
Show parent directroy
-ls ..
Show list in recursive order
-ls -r
Show list according to timestamps
-ls -t
Show list with disk size
-ls -s
Show all ls commands
-man ls or ls --help
show i node value on files and directory
-ls -i
What is i node value ?
These are memory addresses. It means every file placed on specific memory address in disk storage.  
Show list of specific directory
-ls -dl
find speacific directory
-ls -d nginx
show name is  file or direction. If it is file than display its type. If it is directory than diosplay all file with their types
-ls -f nginx

9. Softlinks in linux

Soft links are shortcuts for specific file path (program/service path).
exp: In window we create shoert cust and place on desktop.Instead go long inside directories to run that program, we run from desktop.
Soft links basically shoert name for long paths,
How to create softlink?
1) Go to directory where you want to create that link.
2) Make directory -mkdir mysoftlinks
3) -cd mysoftlinks
4) -ln -s /mywork/file1

10. Editors in linux

1) vi 2) vim 3) gedit 4)cat
Create file in writeable mode.
-cat > filename
//Hello world
ctrl+d // save and close
Open and view file
-cat filename
Concatenate to file content
-cat >> filename
Find specific keyword in file
-cat filename | grep adnan
Create directory
mkdir <directoryname>
Create nested directories (directory inside another directory)
mk dir -p a/b/c/
//a,b,c are directories
show heirarchy of directories.
-ls -R 

11. cp commands in linux

How to copy files?
cp command use for copy the files.
There many options we use cp command are mentioned below ?
1) -v // viewable form 
2) -r recursively // everything includes in particular file or directory
3) -f forcely
4) -p assign same permission to file in particular directory where you are pasting that file.
Copy file
-cp -v file1 /root/desktop
Copy directory (nested recursively)
Here we are coping test directory to/root/desktop destination
cp -vr test/ /root/desktop/
Copy every thing in one command
-cp * /root/desktop/
Copy recusrsiverly.forcely with same permissions
-cp -vrfp test/ /root/desktop

12. Delete files and directories commands in linux

Delete file
-rm -rf test/
Delete directory
rmdir test/
Delete all files and directories
-rm -rf *

13. Rename files and directories commands in linux

-mv file1 myfile //rename
mv command is use for renaming and moving files.

14. Find commands in linux (Searching)

Find particular file/directory with name.
-find /root -name adnan
Find file with permission
-find / -perm 0000
Find file with size
-find / -size 200
Display information of file
- wc file1
output
3 6 27 file1
3 are lines in file
6 are character
27 are single characters 
file1 is filename
Find specific keyword in file
-cat output.error | grep adnan
Find and store result in particular file
-find / -name file1 > file2
e.g store the calendar result in file
cal > file1

15. Standard outputs

Find and store result in particular file
-find / -name passwd > myresult
If you want to append the result to existing result file
-find / -name passwd >> myresult
Note outputs will be store/append in files and errors will be displayed.
If you want to store error in file
-find / -nmame passwd 2> errorfile
to append
-find / -nmame passwd 2>> errorfile
Store both result and error in sigle file
-find . -name &> output.error
-find / -name &>> output.error
cat output.error

16. vi editor

View file in command mode
-vi fle1
When file open type i to insert mode to write or edit text in file.
ESC button use to finish writing (Not save).
There many option or command in vi editor.
1) :w save mode
2) :q close file
3) :q! close forcely
4) :w! save forcely
5) :wq! save and forcely quit
Create and open file
vi <filename>
Find / searching in file using vi
:/aws
:/linux
:/adnan
Set line into numeric line
:set nu
Set numeric lines into normal line
:set nonu
In Command Mode other options
 type
Go to top of file
:gg
Go to bottom
sift+g
Delete single char
x
undo changes
u
delete particular string
dw
Delete files string at the same time
5dw
Delete single line
dd
Delete multiple lines
2dd
Copy line
y
Pase line
p
Copy two char
2y
Copy words
yw
Copy two lines
yy
Copy single letter
yl
Copy single three letters
y3l

More on Groups references
https://www.javatpoint.com/linux-groups

Root Password reset reference

https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html/configuring_basic_system_settings/changing-and-resetting-the-root-password-from-the-command-line_configuring-basic-system-settings#changing-or-resetting-the-forgotten-root-password-as-a-non-root-user_changing-and-resetting-the-root-password-from-the-command-line


User-group-other files and directories permissions reference

https://www.javatpoint.com/linux-file-permissions

17. Listening ports on services

Show ip information of machine in redhat

# ifconfig -a

Check which process listening which ports

netstat -tulpn

we can also filter results

# netstat -tulpn | grep :80

useful link
https://www.cyberciti.biz/faq/what-process-has-open-linux-port/

18. firewall


  • How to check open ports on RHEL 8.
  • How to check services on RHEL 8.
  • How to check open ports remotely using nmap.
  • How to list open ports and service with firewall-cmd.

List open ports
List firewall allowed ports

firewall-cmd --list-ports
Important useful links
https://linuxconfig.org/redhat-8-check-open-ports
All configuration of firewallD (installation and configuration)
https://oracle-base.com/articles/linux/linux-firewall-firewalld















Comments

Popular posts from this blog

Install MariaDB Latest Version 11.4 in Red Hat Version 9

 This this post i will show you step by step the installation process of mariaDB in red hat version 9. Step1 Run the command to pull the latest updated packages on applications installed in your system. -dnf update If you get Kernal update than reboot the system -reboot Step2 Go to official mariaDB site Make mariadb repository in /etc/yum.repos.d Place the configuration in this file # MariaDB 11.4 RedHatEnterpriseLinux repository list - created 2024-09-24 11:12 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/11.4/rhel/$releasever/$basearch baseurl = https://mirrors.aliyun.com/mariadb/yum/11.4/rhel/$releasever/$basearch # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB gpgkey = https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1 Now install the mariaDB with its dependencies package...