Linux
Linux
0 onward you cannot login with root user by default only login with limited user. But if you still want
to login with root user then you have to modify some changes in atc pam file.
How to open Terminal or Console : Click on Application-> System Tools-> Konsole /Terminal
Terminal is Genome feature where as Konsole is KDE feature.
Redhat Linux by default follow Genome so that is way we will use Terminal
[User1@server1 ~]$ < this is called Command Shell and also known as bash <Bourne-again SHell> Stephen
Bourne, author of the Bourne shell. You can add more tab, open another terminal, change color, font, size,
background color, etc. of the Shell
[User1@server1 ~]$ here is shows user1 is username and server1 is server name and $ sign shows limited user
1. /etc/profile : when user open login Shell first /etc/profile is launched and can be opened in vi or vim editor, and it
set all environment variable, paths, history size of Linux.
2. After running /etc/profile it run rest of the script in /etc/profile.d
3. Then it run .bash_profile in User Home Directory, can be opened like vi .bash_profile , it run in Current login
user home directory and can modify some environment variable those was set in /etc/profile, you can set Custom
Variable here also. User specify environment and startup programs.
4. Then run .bashrc is also in user Home Dir, Set local variable and command, Modify Command Prompt look and
feel.
5. Then run /etc/bashrc when bashrc will run user specific script will run from profile.d whereas /etc/profile run
system specific script.
Login as root < su - : it will ask you root password to login >
Useradd sam < will create user but inactive because password is not set >
Delete user
Userdel < user name > will delete only user but user profile will not delete
Userdel -r < user name > this will delete user as well as all user profile, home dir, email box etc.
Useradd -C “Syed Asghar” Asgar < will will user Asger and full name also >
Useradd -s /bin/tcsh shama < by default when user login it login in bash shell if you want to change login shell you can ,
like I did when shame login it open in cshell >
Useradd -C “Syed Mohammed” -d /home/alluser/mohd mohd < mkdir /home/alluser , now -d is for home directory>
Usermod -C “Sam zaidi” sam < modify the Caption of user sam >
If you want to change password of other user login as root using su – or sudo -i
passwd sam <will ask to change the password >
sudo passwd sam < another way to change the password >
System-config-users < this command will open GUI for user creation >
First either connect to yum Server or create local Yum Server Repository it required Linux ios image
Why we need Yum Repository Server: Whatever we are installing package in Redhat we called RPM ( Redhat Package
Manager) to install rpm package we use rpm command, when you install rpm package using rpm command and that
package has no dependency then it will install without any problem, but if that package has dependency or sub
dependency then you need to install all the dependency before installing rpm package. to overcome this problem, we are
creating YUM Server either Local or On Some Other Linux Server it Required IOS image of Redhat Linux.
1. Local YUM Repository will work for local Linux Server only
2. But Yum Repository Server can be used for all Linux server in your company that want to connect your yum
server and install package using either Web Server or Ftp Server.
Attach USB with Linux Redhat iso Image. Use below command to check
lsblk < check all connected Disk Space, USB, DVD, IOS Map etc >
cat /etc/redhat-release < this will tell you the Release of Redhat and version of Redhat >
blkid < will tell you the GUID , Label etc. og your usb, dvd etc. >
cd /mnt/
ls -l
mkdir /cdiso
now either move redhat.repo, rhelrepo.repo file somewhere else or delete these files
rm -rf redhat.repo rhelrepo.repo < delete both file move redhat.repo, rhelrepo.repo >
vim rhelrepo.repo < open the editor and write this >
[BaseOS]
Name= BaseOS
baseurl=file:///cdiso/BaseOS < if files are local on this linux use file if on other Server use protocol like ftp or http >
enable=1 < to make Active if apps are old use 0 to make De active >
gpgcheck=0 < do not check >
[AppStream]
Name= AppStream
baseurl=file:///cdiso/AppStream < if files are local on this linux use file if on other Server use protocol like ftp or http >
enable=1
gpgcheck=0 < do not check >
Yum install httpd < test to install httpd package that your repository are working properly or not >
lsblk < check all connected Disk Space, USB, DVD, IOS Map etc>
ethtool eth4
cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto bond0
iface bond0 inet static
address 10.1.1.18
netmask 255.255.255.0
slaves eth0 eth1 eth3 eth4
bond_mode 0
bond_miimon 100
du -sh /backup/migration/Backup/Level1 < tell you the Size of the Folder Level1 >
2.3 G /backup/migration/Backup/Level1
df -h
ls -lrt /data
ip d
find—This command is a part of findutils and allows for custom search commands. For example, if you
wanted to find directories that matched a specific name, you could use something like this:
xargs allows you to run additional commands against the output of a given command. A super basic example
of this can be seen when pairing with the ls command. For instance, if you wanted to cat all of the files listed
by ls, you could use something like this:
$ ls | xargs cat
$ cat file.txt
cat /etc/resolv.conf
less /etc/resolv.conf
grep "nameserver" /etc/resolv.conf
$ resolvectl status
$ ifconfig
$ resolvectl status eth0
$ resolvectl status eth0
Server: 192.168.7.1
rm Deletes a file
uname Prints information about your machine’s kernel, name, and hardware
netstat Shows the system’s network information, like routing and sockets
alias and unalias Sets and removes an alias for a file or command
1. ls command
The ls command lists files and directories in your system. Here’s the syntax:
ls [/directory/folder/path]
If you remove the path, the ls command will show the current working
directory’s content. You can modify the command using these options:
-lh – converts sizes to readable formats, such as MB, GB, and TB.
2. pwd command
The pwd command prints your current working directory’s path,
like /home/directory/path. Here’s the command syntax:
pwd [option]
Depending on your current location, it requires either the full path or the
directory name. For example,
omit /username from /username/directory/folder if you are already within it.
Omitting the arguments will take you to the home folder. Here are some
navigation shortcuts:
4. mkdir command
Use the mkdir command to create one or multiple directories and set their
permissions. Ensure you are authorized to make a new folder in the parent
directory. Here’s the basic syntax:
mkdir [option] [directory_name]
To create a folder within a directory, use the path as the command parameter.
For example, mkdir music/songs will create a songs folder inside music.
Here are several common mkdir command options:
5. rmdir command
Use the rmdir command to delete an empty directory in Linux . The user
must have sudo privileges in the parent directory. Here’s the syntax:
rmdir [option] directory_name
If the folder contains a subdirectory, the command will return an error. To force
delete a non-empty directory, use the -p option.
6. rm command
Use the rm command to permanently delete files within a directory. Here’s the
general syntax:
rm [filename1] [filename2] [filename3]
Adjust the number of files in the command according to your needs. If you
encounter an error, ensure you have the write permission in the directory.
To modify the command, add the following options:
7. cp command
Use the cp command to copy files or directories, including their content, from
your current location to another. It has various use cases, such as:
Copying one file from the current directory to another folder. Specify the
file name and target path:
cp filename.txt /home/username/Documents
Duplicating multiple files to a directory. Enter the file names and the
destination path:
cp filename1.txt filename2.txt filename3.txt /home/username/Documents
Copying a file’s content to another within the same directory. Enter the
source and the destination file:
cp filename1.txt filename2.txt
8. mv command
Use the mv command to move or rename files and directories. To move items,
enter the file name followed by the destination directory:
mv filename.txt /home/username/Documents
9. touch command
The touch command lets you create an empty file in a specific directory path.
Here’s the syntax:
touch [option] /home/directory/path/file.txt
If you omit the path, the command will create the item in the current folder. You
can also use touch to generate and modify a timestamp in the Linux command
line.
To bulk-check multiple files, list them individually or use their path if they are in
the same directory. Add the -k option to display more detailed information
and -i to show the file’s MIME type.
Use the unzip command to extract the compressed file . Here’s the syntax:
unzip [option] file_name.zip
If the target file doesn’t exist, these editors will create one. We
recommend nano if you want to quickly edit text files. Meanwhile,
use vi or jed for scripting and programming.
cat file1.txt file2.txt > file3.txt – merges file1.txt with file2.txt and
stores the output in filename3.txt.
The script contains the searched regular expression pattern, the replacement
string, and subcommands. Use the s subcommand to replace matching
patterns or d to delete them.
At the end, specify the file containing the pattern to modify. Here’s an example
of a command that replaces red in colors.txt and hue.txt with blue:
sed 's/red/blue' colors.txt hue.txt
For instance, to view the first ten lines of note.txt in the current directory,
enter:
head note.txt
For example, enter the following to show the last ten lines of the colors.txt file:
tail -n colors.txt
By default, this command will sort the lines in alphabetical order, from A to Z.
To modify the sorting, use these options:
-o – redirects the command outputs to another file.
Instead of a file, you can use data from standard input . To determine how the
command sections the line, use the following options:
You can combine these options, use a range, and specify multiple values. For
example, this command extracts the third to fifth field from a comma-separated
list:
cut -d',' -f3-5 list.txt
For example, the following pings Google and prints the output in
Terminal, ping_result.txt, and the 19092024.txt file:
ping google.com | tee ping_result.txt 19092024.txt
For example, to find a file called file1.txt within the directory folder and its
subdirectories, use this command:
find /home -name file1.txt
If you omit the path, the command will search the current working directory.
You can also find directories using the following:
find ./ -type d -name directoryname
When you run a sudo command, Terminal will request the root password. For
example, this snippet runs useradd with the superuser privilege:
sudo useradd username
27. su command
The su command lets you run a program in the Linux shell as a different user.
It is useful to connect via SSH while the root user is disabled. Here’s the
syntax:
su [options] [username [argument]]
Without any option or argument, this command runs through root and prompts
you to use the sudo privileges temporarily. Some options are:
-l – runs a login script to switch users. It requires you to enter the user’s
password.
To check the current shell’s user account, run the whoami command:
In Linux, each file is associated with three user classes – owner, group
member, and others. It also has three permissions – read, write,
and execute. If an owner wants to grant all permissions to every user, the
command looks like this:
chmod -rwxrwxrwx note.txt
Both the useradd and passwd commands require sudo privileges. To delete a
user, use the userdel command:
userdel username
31. df command
Use the df command to check a Linux system’s disk space usage in
percentage and kilobyte (KB). Here’s the syntax:
df [options] [file]
If you don’t specify the item, this command will display information about every
mounted file system. These are some acceptable options:
32. du command
Use du to check a file or directory’s storage consumption. Remember to
specify the directory path when using this command, for example:
du /home/user/Documents
While you can use it without an option, add the following to modify the
command:
To use the command, the user must have root privilege. It has several use
cases, including starting, restarting, and terminating a service. You can also
check a service’s status and dependencies.
The systemctl command is only available in Linux distributions with
the Systemd init system. Check our article on listing and managing Linux
services to learn more about other systems’ commands.
To check the status of jobs in the current shell, enter jobs without any
arguments in Terminal. The command will return an empty output if your
system doesn’t have running jobs. You can also add the following options:
-n – shows jobs whose statuses have changed since the last notification.
You can use an absolute time in a 24-hour format or a relative one like +5 to
schedule it in five minutes. The message is a notification sent to logged-in
users about the system shutdown.
Instead of shutting down, restart the system using the -r option. To cancel a
scheduled reboot, run the command with the -c option.
Linux Commands for Network Management and Troubleshooting
Here are commonly used Linux commands for managing and troubleshooting
network connections.
For example, run the following to check the connection and response time
to Google:
ping google.com
45. wget command
Use the wget command to download files from the internet
using HTTP, HTTPS, or FTP protocols. Here’s the syntax:
wget [option] [url]
However, you can add various options to modify the curl command behavior
for other tasks. Some of the most popular ones include:
For a local machine, omit the hostname and IP address. Use the following
options to modify the copying behavior:
inet and inet6 – assigns an IPv4 and IPv6 address to a network interface.
Use various options to modify the displayed information. Some common ones
are:
You can use a domain, hostname, or IP address as the destination. Add the
following options for more detailed packet monitoring:
-m – sets each packet’s maximum hops.
If you don’t specify the DNS server to use, nslookup will use the default
resolver from your system or internet service provider. This command supports
various options, with some commonly used ones being:
-port= – sets the DNS server’s port number for the query.
-debug – enables the debug mode to provide more information about the
query.
53. dig command
The dig or domain information groper command gathers DNS data from a
domain. Unlike nslookup, it is more detailed and versatile. Here’s the syntax:
dig [option] target [query_type]
System calls
Library calls
Games
Special files
Kernel routines
Miscellaneous
If you only use the command name as the parameter, Terminal displays the full
user manual. Here’s an example command to query section 1 of
the ls command manual:
man 1 ls
57. ln command
The ln command lets you create links between files or directories to simplify
system management. Here’s the syntax:
ln [option] [source] [destination]
The command will create the target file or directory and link it to the source. By
default, it creates a hard link, meaning the new item connects to the same data
block as the source.
For example, enter the following to make k the alias for the kill command:
alias k='kill'
This command doesn’t give any output. To check the alias associated with a
command, run the following:
alias command_name
To delete an existing alias, use the unalias command with the following
syntax:
unalias [alias_name]
-A and -B – displays the specified number of months after and before the
current one.
Example output:
NAME UUID TYPE DEVICE
Bondconn1 6a5605dc-49ad-4f8d-8e10-7c130b95aba7 bond bond0
System ens3 21d47e65-8523-1a06-af22-6f121086f085 ethernet ens3
View the bond configuration file to see detailed information for the new bond
interface.
example output:
connection.id: Bondconn1
connection.uuid: e8092374-4397-4452-bc55-
2f64c506b518
connection.stable-id: --
connection.type: bond
connection.interface-name: bond0
connection.autoconnect: yes
connection.autoconnect-priority: 0
connection.autoconnect-retries: -1 (default)
connection.multi-connect: 0 (default)
...
...
bond.options: mode=balance-rr
proxy.method: none
proxy.browser-only: no
proxy.pac-url: --
proxy.pac-script: --
GENERAL.NAME: Bondconn1
GENERAL.UUID: 37845378-f29a-4b10-8107-
49b9f5a0f564
GENERAL.DEVICES: bond0
GENERAL.IP-IFACE: --
GENERAL.STATE: activating
...
connection.master: --
connection.slave-type: --
connection.autoconnect-slaves: -1 (default)
connection.secondaries: --
connection.gateway-ping-timeout: 0
connection.metered: unknown
connection.lldp: default
connection.mdns: -1 (default)
connection.llmnr: -1 (default)
connection.wait-device-timeout: -1
ipv4.method: auto
lines 1-25
Use the command sudo nmcli connection delete and add the bond link interface name. Begin
by removing the bond0-if3 connection and then repeat the action for the remaining bond
interfaces.
Set the IP address method to manual. This configures the IP address and mask for the
bond interface
sudo nmcli connection modify "Bondconn1" ipv4.method manual
Use the command sudo nmcli connection delete along with the bond interface name to
delete the bond interface.
lsblk or fdisk -l
mount -t ntfs-3g /dev/sdb1 /mnt/win
umount /mnt/win
To mount the NTFS partition permanently, add the following line to the /etc/fstab file.
nano /etc/fstab
df -h or mount
history | grep subscription
subscription-manager register
subscription-manager register -release
subscription-manager register –auto
subscription-manager clean
sudo subscription-manager refresh
subscription-manager repos --enable
subscription-manager register attach –auto
yum install *ntfs* --enablerepo epel
[root@yoursystem] # vi /etc/yum.repos.d/local.repo
[localyum]
name=localyum
baseurl=file:///localyum/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release