All-Linux-Commmands
All-Linux-Commmands
[root@localhost ~]# or $
root @ localhost ~ # or $
Username Separater Machine_Name Working_Directory Symbol of
SuperUser
(RootUser)
Symbol of
RegularUser
Commands
#mkdir \ \ backlash used to write command in multiple lines but work as one.
D1 \
D2 \
D3
#mkdir d1 d2 d3 Creating multiple folder in one line of command.
#touch file1.txt file2 file.doc file.dox This command used to create empty file without any content inside it and
its also known as Zero-beta file and also use to change timestamp of
#touch file{1..100} existing file
#touch .hiddenfile.txt This command help you to create files like file1,file2..file100
1 -> if you want to create soft_link on other location like /tmp you need to
#ln –s testfile soft_testfile use absolute path like(ln –s /root/testfile /tmp/soft2_testfile).
2 -> one delete the other will be effected.
3 -> soft-link can create both file and folder.
# ls a*
alfa
# ls b*
beta
#ls [cd]*
Cat dog
#ls ????
Alfa beta
Variables=values It is used to save variables in a.
a=variables COUNT=10, count=10, first_name=harish, _Id=10
1count = not ok it is not accepted.
echo $a -> to call variable value
-variables
echo ${a}linux echo command used to print anything.
-variableslinux
echo $(hostname)
-harish
echo $(date +%A) echo$() this command used to print only commands.
-Monday
To stop expanding commands. This command used to stop expanding the commands.
echo \$date
echo \$home
To change time and date. Before-change time and date.
[MMDDhhmm[[CC]YY][.ss]] Fri May 5 22:42:50 EDT 2023
Another way
#timedatectl set-time 9:00:00
Helping command to check everything
of anycmd.
q= Quit
To save error,output or both and null > file 2>&1 = &>
the error in file.
0 = Input, 1=Output, 2=Error >> file 2>&1 = &>>
$find /etc/ -name passwd > output.txt (>) this sign used to save output in the file and print error in a terminal.
= error (output save in output.txt)
$cat output.txt
= Output
$wc output.txt
=2
$find /etc/ -name group >> output.txt (>>) this sign used to append output in the file or same file.
=error (output append in output.txt)
$wc output.txt
=2+2
$cat output.txt
/etc/pam.d/passwd
/etc/passwd
/etc/group
/etc/iproute2/group
$find /etc/ -name group 2> error.txt (2>) this sign used to save error in the file and print output in a terminal.
= Output (error save in error.txt)
$cat error.txt
$wc error.txt
$find /etc/ -name passwd 2>> error.txt (2>>) this sign used to append error in the file and print output.
= Output
$cat error.txt
$wc error.txt
$find /etc/ -name shadow 2> /dev/null (2> /dev/null) this sign used to discard or delete errors and print Output.
= Output (error discard or delete in
/dev/null)
$find /etc/ -name shadow &> (&>) this sign used to save both Error & Output in a file.
erroroutput.txt
$cat erroroutput (&>>) this sign used to append both Error & Output in a file.
= Output,Error
$find /etc/ -name passwd &>>
erroroutput.txt
$cat erroroutput.txt
#ls –l |tee lsOutput.txt | head (tee) this cmd used to save output in a file and then passed on Output to
Terminal.
#ls –l |tee lsOutput.txt
= Output with save output in
lsOutput.txt
:w save
:q quit
:! forcefully
U Undo
(Cmd_mode)
P Paste
:set nonumber :se nonu To remove line number from the file
(Cmd_mode)
N Move forward
(Cmd_mode)
N Move reverse
(Cmd_mode)
Username:password:UID:GID:Comment:home-directory:shell
USER -> user information save in those
/sbin/nologin => cannot_Login
directory.
Group:- /etc/group
/etc/passwd => User information
group01: x: 10000: user01,user02,user03
/etc/group => group Information
1 2 3 4
/etc/shadow => Group_password
/etc/shadow => User_password
Sudo -> It is known as SuperUserDo. Sudo This cmd help us to normal user to work as a
$sudo useradd user11 (it can not work because it is Root_User or Super_User.
not in /etc/sudoers file)
admin is not in the sudoers file
Step1:-
#vim /etc/sudoers
:100 Allow root to run any commands anywhere
Press[i] = Insert_mode root ALL=(ALL) ALL
Add username in the sudoers file and ALL-ALL -> admin ALL=(ALL) ALL
Press[ESC] = Cmd_mode (Uname) (Every_cmd) (Every_Location)
:wq! = save,quit,forcefully
$mkdir folder
$ll
drwxrwxr-x. 2 admin admin 6 Apr 6 18:05 folder
$sudo mkdir folder
$ll
drwxr-xr-x. 2 root root 6 Apr 6 18:05 newfolder
Alternative way.
# tail -n 1 /etc/group
superusergroup:x:10001:ravi,user011,testuser,user22
#groupadd groupname To create group.
#groupadd sales
#groupadd accounts
#useradd salesuser1
#useradd salesuser2
#useradd accountuser1
#useradd accountuser2
To add User in any Group.
#usermod –G sales salesuser1
#usermod –G accounts accountuser1
#id accountuser1
uid=1002(accountuser1) gid=1001(accounts)
groups=1001(accounts)
Alternative
To change password configuration
#vim /etc/login.defs
Permissions:- Read(r),Write(w),Execute(x).
#mkdir /folder d -> Directory or folder.
#ls –ld folder 9 (characters) -> --- --- ---
drwxr-xr-x. 2 root root rwx rwx rwx
(User-group-others) -> Permissions. (user) (group) (Other)
-= normal_file or regular_file.
#touch /file
#ll file -(minus) = to remove permissions.
-rw-r--r--. 1 root root +(plus) = to add permissions.
=(exact or equal) => to override the permissions
a= All (User,Group,Others)
u = user
g = group
o = other
#chmod o-rx /folder(to remove read Chmod -> this cmd used to change permissions of file
permissionofothers) or folder.
#ll file
-rw-r-----
$cd /folder Read => reading file or folder like ls,cat,vim.
Permission denied Write => creating file or folder, deleting file or folder
Execute => get Inside the file or folder (cd)
#chmod o+r /folder (Others == Read)
$ls /folder
#useradd specialuser2
#passwd specialuser2 = 123
#useradd specialuser3
#passwd specialuser3 = 123
#groupadd specialgroups
specialuser2
$cd /specialdata
$touch specialfileuser2 Now Only they can delete only their own files or
folder not each others.
#chmod o+t /specialdata
Using o+t
specialuser1
$rm –vf specialfileuser2
rm: cannot remove 'specialfileuser2': Operation not
permitted To make specialgroups Group-Owner of all files
inside the /specialdata.
#chgrp –R specialgroups /specialdata But it is temporary and only for saved file not a
#cd specialdata new files created.
specialdata# ll
-rw-rw-r--. 1 specialuser1 specialgroups specialfileuser1
-rw-rw-r--. 1 specialuser2 specialgroups specialfileuser2
Specialuser1
$cat /etc/shadow
cat: /etc/shadow: Permission denied
To any user to work as root_user.
#chmod u+s /usr/sbin/fdisk
To See Processes:-
#ps
#ps aux
#top
To run cmd in a bg(&)
#firefox &
#jobs To see running program process
[1]+ Running firefox &
#fg %1 <processid> To run background cmd in foreground
Ctrl+c (to stop program running)
#sleep 100 (seconds)
Ctrl+z (to stop program)
To Run process in background.
#jobs
#bg 3 <processid>
To see all kill cmd to kill programs and processes.
#kill –l
Operator1
$vim testfile
#systemctl list-unit-files –type service To see all services are disabled or enabled
#systemctl restart sshd.service To restart the service whenever you change some
-thing in configuration file so that change will
work. But it change Process-id of service
#systemctl reload sshd.service
It work same as restart but in this Process-id will
not change. But do not work on everyfile.
#systemctl mask chronyd
To stop the service.
#systemctl unmask chronyd
To start the service again.
Machine1 Machine2
#nmcli connection add type ethernet #nmcli connection add type ethernet To create device name and
ifname ens160 con-name mycon01 ifname ens160 con-name mycon02 ethernet connection.
#nmcli connection modify mycon01 #nmcli connection modify mycon02 To give ip-addresses to
ipv4.addresses 192.168.10.20/24 ipv4.addresses 192.168.10.30/24 machine.
ipv4.method manual ipv4.method manual
#nmcli connection [2*TAB] #nmcli connection [2*TAB] To check more option like
down the connection or delete
and manymore.
#nmcli connection show #nmcli connection show To show the machine or device
we created
#cd /etc/sysconfig/network-scripts/
Go to the file
/etc/sysconfig/network-scripts/
#ls
ifcfg-con0011 ifcfg-ens160 ifcfg-mycon01
#vim ifcfg-con0011
BOOTPROTO=none
IPADDR=200.200.200.100
PREFIX=24
GATEWAY=200.200.200.1
DNS1=202.56.215.54
DNS2=202.56.215.55
#rsync [email protected]:/root/file1 .
#ls
To receiving folder from
#rsync -r [email protected]:/root/folder1 . machine2
Install packages and more details :-
#find / -name file1 find cmd used to find file or folder in the
/root/file1 specific location like ( / , /etc/ ). It gives
/root/syncfolder/file1 more options than locate like search by ->
/root/folder1/file1 -name, -group, -user, -uid, -gid, -perm 000,
/salesdata/joker/file1 -size 20M
/folder/file1
Finding the file or folder which start with
#find / -name ‘*pass*’ *pass* or have.
#rpm –q cockpit
#systemctl status cockpit.socket
#firewall-cmd –reload
#firewall-cmd –list-all
#firewall-cmd –add-service=cockpit –
permanent
#firewall-cmd –reload
#firewall-cmd –list-all
#ip a
#firefox
Copy ip address
192.168.10.20
Paste it on firefox browser.
https://192.168.10.20:9090
Using
Username :- root
Password :- 123