Saturday 21 November 2015







runlevel is one of the modes that a Unix -based operating system will run in. Each runlevel has a certain number of services stopped or started, giving the user control over the behavior of the machine. Conventionally, seven runlevels exist, numbered from zero to six.
After the Linux kernel has booted, the init program reads the /etc/inittab file to determine the behavior for each runlevel. Unless the user specifies another value as a kernel boot parameter, the system will attempt to enter (start) the default runlevel.



Standard run levels for Red Hat based distributions
Run Level
Mode
Action
0HaltShuts down system
1Single-User ModeDoes not configure network interfaces, start daemons, or allow non-root logins
2Multi-User ModeDoes not configure network interfaces or start daemons.
3Multi-User Mode with NetworkingStarts the system normally.
4UndefinedNot used/User-definable
5X11As runlevel 3 + display manager(X)
6RebootReboots the system
Most Linux servers lack a graphical user interface and therefore start in runlevel 3. Servers with a GUI and desktop Unix systems start runlevel 5. When a server is issued a reboot command, it enters runlevel 6.

Init scripts

Init (short for initialization) is the program on Unix and Unix-like systemsThe Init is the parent of all processes with PID # 1.
The /etc/inittab file is used to set the default run level for the system. This is the runlevel that a system will start up on upon reboot. The applications that are started by init are located in the /etc/rc.d folder. Within this directory there is a separate folder for each run level, eg rc0.drc1.d, and so on.


Linux Find Out Current Run Level Command

Type the following command:
$ who -r

Linux Change Run Level Command

Use the init command to change rune levels:
# init 1On most Linux server system default run level is 3 and on most Linux Desktop system default run level is 5. The default run level is defined by the initdefault line at the top of /etc/inittab file under CentOS / Fedora / Redhat / RHEL / Debian Linux. To change the default run level, edit /etc/inittab file, and edit entry initdefault:
# vi /etc/inittab
Set initdefault to 5, so that you can boot to X next time when Linux comes up:
id:5:initdefault:
Save and close the file. Reboot the system to see changes:
# reboot

Identifying Services that Start at Each Runlevel

There are number of ways to identify which services get started without having to delve into the /etc/rc.d sub-directories. The command line tool chkconfig (usually located in the /sbin directory) can be used to list which services get started at boot time. To list all service settings run the following command:
/sbin/chkconfig --list



First we Need To Know About Inodes   
Hard links and soft link is an important concept in the Linux file system, which relates to the index node in the file system (inode). Inode is one of the four basic concepts in Linux virtual file system (VFS). Through the analysis of the relation and the difference between hard links and soft links, we can better understand Linux VFS.
We know that the file has file name and data, which is divided into two parts: user data and metadata. The user data, namely the file data blocks (data block), data block is a place that store the real content. metadata is additional properties of file, such as: file size, created time of file, owner information of file. In Linux, the inode in the metadata, (inode is a part of the file metadata but which do not contain a file name, inode, namely the inode number) is uniquely identifies of the file rather than the file name. The file name is only for memory and is convenient for people to use. through the inode number, system can find the correct file data block. The below figure shows how the program obtain the contents of the file by file name.
open file
In order to solve the problem of file sharing, Linux system introduce two links: hard link (hard link) and soft link (also called a symbolic link). A link will resolve file sharing for the Linux system. If a inode is correspond to multiple file name, said these files as hard links. In other words, a hard link is the same file with multiple aliases. Hard links can be created by the command link or ln.
Soft link is a common file, there is only a little special for the content of data block. A soft link has its own inode number and the user data block , pls see the below figure. So soft link is created without many restrictions similar with hard links:
  • A soft link has its own file attributes and authority
  • You can create a soft link to the file or directory does not exist
  • A soft link can cross file system
  • Soft links can be created to the file or directory
  • Create a soft link, link count i_nlink does not increase
  • Removing the soft link does not affect the pointed file, but the original file if it is to be deleted, then the soft links is called the dead link
hard_soft_link





Q. What is the one line answer to the question “What is the main difference between hard links & soft links” ?
A. A softlink will have a different Inode number than the source file, which will be having a pointer to the source file but hardlink will be using the same Inode number as the source file.
Q. How can I find all the Soft Links in my system ?
A. Use this command for the same “find /etc -type l -exec ls -li {} \;”
Q. How can I find all the files having Hard Links in my system ?
A. Use this command for the same “find / -links +2 -type f -exec ls -li {} \;”
Q. How to find whether a file is a softlink ?
A. Simply using this command “ls -l” will tell you whether a file is pointing to some other file or not.
Q. How to check whether a file have any softlink pointing to it ?
A. Till now, I am not aware of any way to do that. If I will find any, I will surely update my post.
Q. How can I find out the source file of a hard link ?
A. No, you can’t find out the source file of a hard link. Once hard link is created, there is no way to tell which was the first file created.
Q. Can I make a Soft link to a Hard link and Vice Versa ?
A. Yes, both soft links and hard links acts as normal files of the file system, so you can do both.

How file is deleted having hard links:

So, as it’s pretty clear from the above article that hard links are just the reference to the main file location, and even if you delete one link, the data will still be intact. So, to remove a hard link, you need to remove all the links, which are referring to the file. Once the “link count” goes to “0”, then the inode is removed by the filesystem, and file is deleted.

When to use Soft Link:

  1. Link across filesystems: If you want to link files across the filesystems, you can only use symlinks/soft links.
  2. Links to directory: If you want to link directories, then you must be using Soft links, as you can’t create a hard link to a directory.

When to use Hard Link:

  1. Storage Space: Hard links takes very negligible amount of space, as there are no new inodes created while creating hard links. In soft links we create a file which consumes space (usually 4KB, depending upon the filesystem)
  2. Performance: Performance will be slightly better while accessing a hard link, as you are directly accessing the disk pointer instead of going through another file.
  3. Moving file location: If you move the source file to some other location on the same filesystem, the hard link will still work, but soft link will fail.
  4. Redundancy: If you want to make sure safety of your data, you should be using hard link, as in hard link, the data is safe, until all the links to the files are deleted, instead of that in soft link, you will lose the data if the master instance of the file is deleted.

Hard Links in Linux

Soft Links on Linux


PRACTICAL:


Symbolic links are created with the “ln” command in linux. The syntax of the command is:
$ ln -s
-s = This flag tells to create a symlink (if you don’t use this it will create a hard link, which we will talk about soon).
For Example, if you want to create a soft link of one fo your favorite application, like gedit, on your desktop, use the command like this:
$ ln -s /usr/bin/gedit ~/Desktop/gedit
I hope now the concept of Soft Links should be clear.

You can create a hard link with the same command “ln” like this
# ln
So, to create a hard link of gedit program on your desktop, you will use the command like this:
# ln /usr/bin/gedit ~/Desktop/gedit
Now, the bigger question is, who will decide what is better and when to use soft link or hard link
NOTE: The only information not included in an inode, is the file name and directory. These are stored in the special directory files.

Wednesday 4 November 2015

 How to Manage Users and Groups in RHEL 

We will start this article with an overall and brief revision of what happens since the moment you press the Power button to turn on your RHEL 7 server until you are presented with the login screen in a command line interface.
RHEL 7 Boot Process
Linux Boot Process
Please note that:
1. the same basic principles apply, with perhaps minor modifications, to other Linux distributions as well, and
2. the following description is not intended to represent an exhaustive explanation of the boot process, but only the fundamentals.

Linux Boot Process

1. The POST (Power On Self Test) initializes and performs hardware checks.
2. When the POST finishes, the system control is passed to the first stage boot loader, which is stored on either the boot sector of one of the hard disks (for older systems using BIOS and MBR), or a dedicated (U)EFI partition.
3. The first stage boot loader then loads the second stage boot loader, most usually GRUB (GRand Unified Boot Loader), which resides inside /boot, which in turn loads the kernel and the initial RAM–based file system (also known as initramfs, which contains programs and binary files that perform the necessary actions needed to ultimately mount the actual root filesystem).
4. We are presented with a splash screen that allows us to choose an operating system and kernel to boot:


RHEL 7 Boot Screen

Boot Menu Screen

5. The kernel sets up the hardware attached to the system and once the root filesystem has been mounted, launches process with PID 1, which in turn will initialize other processes and present us with a login prompt.
Note: That if we wish to do so at a later time, we can examine the specifics of this process using the dmesg command and filtering its output using the tools that we have explained in previous articles of this series.
Login Screen and Process PID
Login Screen and Process PID
In the example above, we used the well-known ps command to display a list of current processes whose parent process (or in other words, the process that started them) is systemd (the system and service manager that most modern Linux distributions have switched to) during system startup:
# ps -o ppid,pid,uname,comm --ppid=1
Remember that the -o flag (short for –format) allows you to present the output of ps in a customized format to suit your needs using the keywords specified in the STANDARD FORMAT SPECIFIERS section in man ps.
Another case in which you will want to define the output of ps instead of going with the default is when you need to find processes that are causing a significant CPU and / or memory load, and sort them accordingly:
# ps aux --sort=+pcpu              # Sort by %CPU (ascending)
# ps aux --sort=-pcpu              # Sort by %CPU (descending)
# ps aux --sort=+pmem              # Sort by %MEM (ascending)
# ps aux --sort=-pmem              # Sort by %MEM (descending)
# ps aux --sort=+pcpu,-pmem        # Combine sort by %CPU (ascending) and %MEM (descending)
Customize ps Command Output
Customize ps Command Output

 

An Introduction to SystemD

Few decisions in the Linux world have caused more controversies than the adoption of systemd by major Linux distributions. Systemd’s advocates name as its main advantages the following facts:
Read Also: The Story Behind ‘init’ and ‘systemd’
1. Systemd allows more processing to be done in parallel during system startup (as opposed to older SysVinit, which always tends to be slower because it starts processes one by one, checks if one depends on another, and then waits for daemons to launch so more services can start), and
2. It works as a dynamic resource management in a running system. Thus, services are started when needed (to avoid consuming system resources if they are not being used) instead of being launched without a valid reason during boot.
3. Backwards compatibility with SysVinit scripts.
Systemd is controlled by the systemctl utility. If you come from a SysVinit background, chances are you will be familiar with:
  1. the service tool, which -in those older systems- was used to manage SysVinit scripts, and
  2. the chkconfig utility, which served the purpose of updating and querying runlevel information for system services.
  3. shutdown, which you must have used several times to either restart or halt a running system.
The following table shows the similarities between the use of these legacy tools and systemctl:
Legacy tool Systemctl equivalent Description
service name start systemctl start name Start name (where name is a service)
service name stop systemctl stop name Stop name
service name condrestart systemctl try-restart name Restarts name (if it’s already running)
service name restart systemctl restart name Restarts name
service name reload systemctl reload name Reloads the configuration for name
service name status systemctl status name Displays the current status of name
service –status-all systemctl Displays the status of all current services
chkconfig name on systemctl enable name Enable name to run on startup as specified in the unit file (the file to which the symlink points). The process of enabling or disabling a service to start automatically on boot consists in adding or removing symbolic links inside the /etc/systemd/system directory.
chkconfig name off systemctl disable name Disables name to run on startup as specified in the unit file (the file to which the symlink points)
chkconfig –list name systemctl is-enabled name Verify whether name (a specific service) is currently enabled
chkconfig –list systemctl –type=service Displays all services and tells whether they are enabled or disabled
shutdown -h now systemctl poweroff Power-off the machine (halt)
shutdown -r now systemctl reboot Reboot the system
Systemd also introduced the concepts of units (which can be either a service, a mount point, a device, or a network socket) and targets (which is how systemd manages to start several related process at the same time, and can be considered -though not equal- as the equivalent of runlevels in SysVinit-based systems.

Summing Up

Other tasks related with process management include, but may not be limited to, the ability to:
1. Adjust the execution priority as far as the use of system resources is concerned of a process:
This is accomplished through the renice utility, which alters the scheduling priority of one or more running processes. In simple terms, the scheduling priority is a feature that allows the kernel (present in versions => 2.6) to allocate system resources as per the assigned execution priority (aka niceness, in a range from -20 through 19) of a given process.
The basic syntax of renice is as follows:
# renice [-n] priority [-gpu] identifier
In the generic command above, the first argument is the priority value to be used, whereas the other argument can be interpreted as process IDs (which is the default setting), process group IDs, user IDs, or user names. A normal user (other than root) can only modify the scheduling priority of a process he or she owns, and only increase the niceness level (which means taking up less system resources).
Renice Process  in Linux
Process Scheduling Priority
2. Kill (or interrupt the normal execution) of a process as needed:
In more precise terms, killing a process entitles sending it a signal to either finish its execution gracefully (SIGTERM=15) or immediately (SIGKILL=9) through the kill or pkill commands.
The difference between these two tools is that the former is used to terminate a specific process or a process group altogether, while the latter allows you to do the same based on name and other attributes.
In addition, pkill comes bundled with pgrep, which shows you the PIDs that will be affected should pkill be used. For example, before running:
# pkill -u gacanepa
It may be useful to view at a glance which are the PIDs owned by gacanepa:
# pgrep -l -u gacanepa
Find PIDs of User
Find PIDs of User
By default, both kill and pkill send the SIGTERM signal to the process. As we mentioned above, this signal can be ignored (while the process finishes its execution or for good), so when you seriously need to stop a running process with a valid reason, you will need to specify the SIGKILL signal on the command line:
# kill -9 identifier               # Kill a process or a process group
# kill -s SIGNAL identifier        # Idem
# pkill -s SIGNAL identifier       # Kill a process by name or other attributes 

Conclusion

In this article we have explained the basics of the boot process in a RHEL 7 system, and analyzed some of the tools that are available to help you with managing processes using common utilities and systemd-specific commands.
Note that this list is not intended to cover all the bells and whistles of this topic, so feel free to add your own preferred tools and commands to this article using the comment form below. Questions and other comments are also welcome.
Share
 
 

Installation of Red Hat Enterprise Linux 6.0:

Boot the system with RHEL 6.0 DVD. At the boot prompt, hit enter to begin installation:

Skip the media testing process:
Click Next: Select your preferred Language and hit Enter:

Select your keyboard layout:

Select Basic storage Devices. If you install this in SAN environment select Specialized Storage Devices and hit Enter:

A warning message will appear that denotes the existing data’s in the hdd will be deleted. Make sure the hdd doesn’t has any important data’s and hit Yes:

Enter the hostname for your server:

Enter the IP address for your server by clicking the “configure Network”, Select your Network interface and enter the IP, Subnet details and Apply the changes.:


Select your Time Zone and click Next:

Enter the Root Password and click Next:

Select the Mode of Partition and click Next:

The partition changes will be applied now:


Now select the type of install for this server depends upon the role of the server such as Desktop, Basic Server, Web server, Database server or whatever you need for your current environment. Here let us install the Minimal Server. You can customize the server here or you can do it later:

Now the installation will begin. It will take a while depends upon your hardware configuration:

At the end of installation, hit Reboot and you will get the login screen as shown below:

Thats it. Configure the server as per your needs for your environmen

Monday 2 November 2015

6 Stages of Linux Boot Process (Startup Sequence)



Press the power button on your system, and after few moments you see the Linux login prompt.
Have you ever wondered what happens behind the scenes from the time you press the power button until the Linux login prompt appears?
The following are the 6 high level stages of a typical Linux boot process.

1. BIOS

  • BIOS stands for Basic Input/Output System
  • Performs some system integrity checks like POST
  • Searches, loads, and executes the initial boot loader (IPL initial program loader)program.
  • Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
  • So, in simple terms BIOS search,loads and executes the MBR boot loader.

2. MBR

 

 

  • MBR stands for Master Boot Record.
  • It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
  • MBR is less than 512 bytes in size. This has three components 
  1.  primary boot loader info in 1st 446 bytes 
  2.  partition table info in next 64 bytes 
  3.  mbr validation check in last 2 bytes.
  • It contains information about GRUB (or LILO in old systems).
  • So, in simple terms MBR loads and executes the GRUB boot loader.

3. GRUB

  • GRUB stands for Grand Unified Bootloader.
  • If you have multiple kernel images installed on your system, you can choose which one to be executed.
  • GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
  • GRUB has the knowledge of the filesystem (the older Linux loader LILO didn’t understand filesystem).
  • Grub configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample grub.conf of CentOS.
  • #boot=/dev/sda
    default=0
    timeout=5
    splashimage=(hd0,0)/boot/grub/splash.xpm.gz
    hiddenmenu
    title CentOS (2.6.18-194.el5PAE)
              root (hd0,0)
              kernel /boot/vmlinuz-2.6.18-194.el5PAE ro root=LABEL=/
              initrd /boot/initrd-2.6.18-194.el5PAE.img
  • As you notice from the above info, it contains kernel and initrd image.
  • So, in simple terms GRUB just loads and executes Kernel and initrd images.

4. Kernel

  • Mounts the root file system as specified in the “root=” in grub.conf
  • Kernel executes the /sbin/init program
  • Since init was the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1.
  • initrd stands for Initial RAM Disk.
  • initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers compiled inside, which helps it to access the hard drive partitions, and other hardware .initrd help to kernel for load only necessary modules by detecting the hardwares.

5. Init

  • Looks at the /etc/inittab file to decide the Linux run level.
  • Following are the available run levels
    • 0 – halt
    • 1 – Single user mode
    • 2 – Multiuser, without NFS
    • 3 – Full multiuser mode
    • 4 – unused
    • 5 – X11
    • 6 – reboot
  • Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
  • Execute ‘grep initdefault /etc/inittab’ on your system to identify the default run level
  • If you want to get into trouble, you can set the default run level to 0 or 6. Since you know what 0 and 6 means, probably you might not do that.
  • Typically you would set the default run level to either 3 or 5.

6. Runlevel programs

  • When the Linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail …. OK”. Those are the runlevel programs, executed from the run level directory as defined by your run level.
  • Depending on your default init level setting, the system will execute the programs from one of the following directories.
    • Run level 0 – /etc/rc.d/rc0.d/
    • Run level 1 – /etc/rc.d/rc1.d/
    • Run level 2 – /etc/rc.d/rc2.d/
    • Run level 3 – /etc/rc.d/rc3.d/
    • Run level 4 – /etc/rc.d/rc4.d/
    • Run level 5 – /etc/rc.d/rc5.d/
    • Run level 6 – /etc/rc.d/rc6.d/
  • Please note that there are also symbolic links available for these directory under /etc directly. So, /etc/rc0.d is linked to /etc/rc.d/rc0.d.
  • Under the /etc/rc.d/rc*.d/ directories, you would see programs that start with S and K.
  • Programs starts with S are used during startup. S for startup.
  • Programs starts with K are used during shutdown. K for kill.
  • There are numbers right next to S and K in the program names. Those are the sequence number in which the programs should be started or killed.
  • For example, S12syslog is to start the syslog deamon, which has the sequence number of 12. S80sendmail is to start the sendmail daemon, which has the sequence number of 80. So, syslog program will be started before sendmail.
There you have it. That is what happens during the Linux boot process.



Notes:

1> Advantages of GRUB over LILO
     Grub can understand file system but LILO cant
     LILO does not support booting from a network, whereas GRUB does.

Linux system administration commands


halt

This command shuts down the operating system, but can only be run by the root user.
#halt

reboot

This command shuts down and restarts the operating system. It also can only be run by root.
#reboot           [will perform simple reboot]
#reboot -f        [will perform fast reboot ]

init 0

This command also shuts down the operating system, and can only be run by root.
#init 0

init 6

This command restart the operating system. It also can only be run by root.
#init 6

man

This command opens the manual page for the command or utility specified. The man utility is a very useful tool. If you are unsure how to use any command, use man to access its manual page. For example, you could enter man ls at the shell prompt to learn how to use the ls utility.
#man ls

info

The info utility also displays a help page for the indicated command or utility. The information displayed with info command will be in-depth than that displayed in the man page for the same command.
info ls

su

This command switches the current user to a new user account. For example, if you’re logged in as vickey and need to change to user account to vinita, you can enter su vinita at the shell prompt. This command is most frequently used to switch to the superuser root account.
In fact, if you don’t supply a username, this utility assumes that you want to change to the root account. If you enter su -, then you will switch to the root user account and have all of root’s environment variables applied.
This command require password of the user you want switch.
Looking for Files
There are two basic commands used for file searches: find and locate

find

The find command searches through directories and subdirectories for a desired file. For example, if you wanted to find the directory with thegrub.conf linux boot loader file, you could use the following command, which would start the search in the top-level root (/) directory:
# find / -name grub.conf
But this search took several minutes to get it task done. Alternatively, if you know that this file is located in the /etc subdirectory tree, or /boot/grub/grub.conf you could start in that directory with the following command:
# find /etc -name grub.conf

locate

If this is all too time-consuming, RHEL 5 includes a default database of all files and directories. Searches with the locate command are almost instantaneous. And locate searches don't require the full file name. The drawback is that the locate command database is normally updated only once each day, as documented in the /etc/cron.daily/mlocate.cron script.

Getting into the Files

Now that you see how to find and get around different files, it's time to start reading, copying, and moving the files around. Most Linux configuration files are text files. Linux editors are text editors. Linux commands are designed to read text files. If in doubt, you can check the file types in the current directory with the 
file * command.

cat

The most basic command for reading files is cat. The cat filename command scrolls the text within the filename file. It also works with multiple file names; it concatenates the file names that you might list as one continuous output to your screen. You can redirect the output to the file name of your choice.

more and less

Larger files demand a command that can help you scroll through the file text at your leisure. Linux has two of these commands: 
more and less.
With the more filename command, you can scroll through the text of a file, from start to finish, one screen at a time. With the less filename command, you can scroll in both directions through the same text with the PAGE UP and PAGE DOWN keys. Both commands support vi-style searches.

head and tail

The head and tail commands are separate commands that work in essentially the same way. By default, the head filename command looks at the first 10 lines of a file; the tail filename command looks at the last 10 lines of a file. You can specify the number of lines shown with the -nx switch. Just remember to avoid the space when specifying the number of lines; for example, the
# tail -n15 /etc/passwd
command lists the last 15 lines of the /etc/passwd file.

cp

The cp (copy) command allows you to take the contents of one file and place a copy with the same or different name in the directory of your choice. For example, the cp file1 file2 command takes the contents of file1 and saves the contents in file2. One of the dangers of cp is that it can easily overwrite files in different directories, without prompting you to make sure that's what you really wanted to do.

mv

While you can't rename a file in Linux, you can move it. The mv command essentially puts a different label on a file. For example, the mv file1 file2 command changes the name of file1 to file2. Unless you're moving the file to a different partition, everything about the file, including the inode number, remains the same.

ln

You can create a linked file. 
linked files are common with device files such as /dev/dvdwriter and /dev/par0. They're also useful for making sure that multiple users have a copy of the same file in their directories. Hard links include a copy of the file. As long as the hard link is made within the same partition, the inode numbers are identical. You could delete a hard-linked file in one directory, and it would still exist in the other directory. For example, the following command creates a hard link from the actual Samba configuration file to smb.conf in the local directory:
# ln smb.conf /etc/samba/smb.conf
On the other hand, a soft link serves as a redirect; when you open up a file created with a soft link, you're directed to the original file. If you delete the original file, the file is lost. While the soft link is still there, it has nowhere to go. The following command is an example of how you can create a soft link:
# ln -s smb.conf /etc/samba/smb.conf

sort

You can sort the contents of a file in a number of ways. By default, the sort command sorts the contents in alphabetical order depending on the first letter in each line. For example, the sort /etc/passwd command would sort all users (including those associated with specific services and such) by username.

grep and egrep

The grep command uses a search term to look through a file. It returns the full line that contains the search term. For example, grep 'vickey' /etc/passwd looks for my name in the /etc/passwd file.
The egrep command is more forgiving; it allows you to use some unusual characters in your search, including +, ?, |, (, and). While it's possible to set up grep to search for these characters with the help of the backslash, the command can be awkward to use.

wc

The wc command, short for word count, can return the number of lines, words, and characters in a file. The wc options are straightforward: for example, wc -w filename returns the number of words in that file.

sed

The sed command, short for stream editor, allows you to search for and change specified words or even text streams in a file. For example, the following command changes the first instance of the word Windows to the word Linux in each line of the file data, and writes the result to the file newdata:
# sed 's/Windows/Linux/' data > newdata
However, this may not be enough. If a line contains more than one instance of Windows, the above sed command does not change the second instance of that word. But you can make it change every appearance of Windows by adding a "global" suffix:
# sed 's/Windows/Linux/g' data > newdata

awk

The awk command, named for its developers (Aho, Weinberger, and Kernighan), is more of a database manipulation utility. It can identify lines with a keyword and read out the text from a specified column in that line. Again, using the /etc/passwd file, for example, the following command will read out the username of every user with a vickey in the comment column:
# awk '/vickey/ {print $1}' /etc/passwd

ps

It's important to know what's running on your Linux computer. The ps command has a number of critical switches. When trying to diagnose a problem, it's common to get the fullest possible list of running processes, and then look for a specific program. For example, if the Firefox Web browser were to suddenly crash, you'd want to kill any associated processes. The ps aux | grep firefox command could then help you identify the process(es) that you need to kill.

who and w

If you want to know what users are currently logged into your system, use the who command or the w command. This can help you identify the usernames of those who are logged in, their terminal connections, their times of login, and the processes that they are running.

Wildcards

Sometimes you may not know the exact name of the file or the exact search term. This is when a wildcard is handy. The basic wildcards are shown
WildcardDescription
*Any number of alphanumeric characters (or no characters at all). For example, the ls ab* command would return the following file names, assuming they exist in the current directory: ab, abc, abcd.
?One single alphanumeric character. For example, the ls ab? command would return the following file names, assuming they exist in the current directory: abc, abd, abe
[ ]A range of options. For example, the ls ab[123] command would return the following file names, assuming they exist in the current directory: ab1, ab2, ab3. Alternatively, the ls ab[X-Z] command would return the following file names, assuming they exist in the current directory: abX, abY, abZ.

env

This command displays the environment variables for the currently logged-in user.

echo

This command is used to echo a line of text on the screen. It’s frequently used to display environment variables. For example, if you wanted to see the current value of the PATH variable, you could enter 
echo $PATH

top

This command is a very useful command that displays a list of all applications and processes currently running on the system. You can sort them by CPU usage, memory usage, process ID number, and which user owns them

which

This command is used to display the full path to a shell command or utility. For example, if you wanted to know the full path to the ls command, you would enter
which ls

whoami

This command displays the username of the currently logged-in user.

netstat

This command displays the status of the network, including current connections, routing tables, etc

route

This command is used to view or manipulate the system’s routing table.

ifconfig

This command is used to manage network boards installed in the system. It can be used to display or modify your network board configuration parameters. This command can only be run by the root user.
Do practice and practice until you feel comfortable with these commands

Popular Posts

Recent Posts

Unordered List

Categories

Text Widget

Powered by Blogger.

Home - PageNavi (show/hide)

Ads

Pages