- Introduction with Red Hat Linux Command Prompt
- User Type in Red Hat Linux
- Structure of a Red Hat Linux Command
- 11 Essential and Frequently Used Commands in Red Hat Linux
- CMD 1: man
- CMD 2: help
- CMD 3: pwd
- CMD 4: cd
- CMD 5: ls
- CMD 6: mkdir
- CMD 7: touch
- CMD 8: cp
- CMD 9: rm
- CMD 10: vi
- CMD 11: shutdown
- Useful Tips about Linux Command Prompt
Red Hat Linux is an open source server operating system. Although open source Red Hat is a commercial Linux distribution. So, most of the Linux administrators use CentOS because CentOS is a free and open source, enterprise-class and community-supported server platform as well as it is functionally compatible with Red Hat Enterprise Linux. In my previous article, I showed how to install CentOS 7 core packages in your server machine. Today I will introduce you with Red Hat Linux’s command prompt as well as 11 important commands that are always used for Linux administration. If you are new in this article as well as Red Hat Linux operating system, install CentOS 7 according to my previous article and then continue the rest of this article.
Introduction with Red Hat Linux Command Prompt
If you do not install CentOS yet, please complete CentOS 7 core (minimal packages) installation according to my previous article. I always suggest you to install CentOS core installation because Red Hat Linux is mainly used for server platform. So, if you use CentOS Desktop, your server will be bulky as well as server overhead will increase. It may impact of your server performance. On the other hand, Linux Administrators like me always like to play with command rather than Graphical User Interface (GUI).
If you boot your CentOS 7 core system, you will find a command prompt which will ask you to login to your Linux system. Login to your system with root user and password. You will find a command prompt like be image.
In this command prompt, you can write any command to operate your Linux system. The last line of this command prompt contains four messages.
- root: Here root is the user who have logged in to the system. If you login with another username, it will change according to your user name.
- localhost: Hostname of your system. If you have not changed while installing operating system, it will be localhost by default. It can be changed later by using command and I will show later how to change hostname with command.
- Location (~): User’s current location will be shown here. As I have logged in as a root user, it is showing (~) means /rootcd commend is mainly used to change the current location.
- User type (# or $): This part shows the type of user. For normal user it will be ($) and for the root user it will be (#).
User Type in Red Hat Linux
There are three types of user in Red Hat Linux system.
- Root user: root user is the administrator or super user of Red Hat Linux system. root user can do any task in Red Hat Linux.
- System user: System users are those users who cannot login the system but necessary for running various service such mail, ftp, apache etc.
- Regular user: Regular user can login to the system and can do some tasks with limitation but cannot do administrative task. Root user can assign administrative task to any regular user if he wants.
Structure of a Red Hat Linux Command
A command run from the command prompt will generally have below structure.
command -option or argument
In Red Hat Linux system, both –option and are optional. A command can perform its task without option and filename or it can take either -option or filename to perform its task.
For example, if you want to show available directories and files in your current location, you can type ls command which will show files and directories in short format. But if you want to show in long format, you can type ls -l which will show files and directories in long format. Again if wish to show files and directories in long format within a specific directory, you can type ls –l such as /var/log which will show all the files and directories within the specific directory with long format.
11 Essential and Frequently Used Commands in Red Hat Linux
Now I will show you 11 essential commands which are frequently used to perform administrative task in Red Hat Linux.
CMD 1: man
The man command is used to show the manual page of any Red Hat Linux built-in command. It is one of the most useful commands to any Linux system administrator because it helps to find available options and usage of any command with example so easily. For example, if you want to know details about cd command, just use man command like below.
You will find detail manual page of cd command now. Press UP and Down arrow key to scroll this manual page or type ’q’ to quit this manual page.
CMD 2: help
The help command is another useful command which returns quick summery of any built-in command. For example, if you want to know usage of cd command quickly, use this help command like below.
The help command will now show you a quick summery of cd command.
CMD 3: pwd
The pwd command prints the full file name of the current working directory. If you need to know your present working directory, just use pwd command like below.
Now you will be able to show your current working directory as output. For more details about this command, please use man pwd command.
CMD 4: cd
The cd command is used to switch directory path. It takes directory path as its argument. For example, if you want to go /var/log directory, just use cd command like below.
Now your current directory or working directory will be log directory. To know more about cd command, please use man cd command in your shell prompt.
In Red Hat Linux system, there are two ways to define directory path.
- Absolute path: If directory path starts with root directory (/), it is called absolute path. For example, /var/log/maillog this directory path starts with root directory, so this path notation will be called absolute path.
- Relative path: If path notation does not start with root directory, it is defined as relative path. Say your current directory is root directory and you want to go log directory. In this case, you can use cd command like below.
Here relative path notation is used because directory path does not start with root directory.
CMD 5: ls
The ls command shows all the contents in a directory. According to the content color, you can identify the type of any content. A list of content color is given below.
Content Type | Color |
---|---|
Directory | Blue |
File | Black and White |
Compress File (zip/rar/rpm) | Red |
Executable File | Green |
Device (terminal/cd/dvd/usb/hdd) | Yellow |
Picture/image/media | Magenta |
Link File | Cyan |
A lot of options are available for ls command. Say, if you want to see long listing file format, you can use ls –l command. To know more about ls command options, please use man ls command. You will find details about ls command there.
CMD 6: mkdir
The mkdir command is to create a directory in any location in your system. Say, you want to create a directory/folder named class in your current directory. Then use mkdir commend like below.
So, you will find a folder named class has been created in your current directory. Use man command to know more about mkdir command.
CMD 7: touch
The touch command is used to create a file your desired directory. Say, you want to create a text file named lecture1 in your current directory. Then use touch command like below.
So, you will find a file named lecture1 has been created in your current directory. You will find more details about touch command using man command.
CMD 8: cp
The cp command is used to copy any file or directory. Format of cp command is given below.
cp [–option] source file name and path destination file name and path
[–option] is optional. Say, if you want to copy your lecture1 file in /var directory with another name, use cp command like below.
So, you will get a copy of lecture1 file in /var directory and its name will be lecture1.bak. For more details about cp command, please use man command.
CMD 9: rm
The rm command is used to remove any file or directory. It takes file or directory name with path as its argument. Say, you want to delete the lecture1.bak file that you have copied in /var directory with cp command. Then use rm command like below.
Your lecture1.bak file will be removed as soon as you execute this command. Here –f is an option which stands for force. If you don’t use this option, you will be asked to confirm for file or directory removal. A lot of options are also available for rm command. Please run man rm command to get details.
CMD 10: vi
Like windows notepad, vi is a text editor. Any kind of plain text can be edit with vi shell editor. Say, you want to write some text in your lecture file. Then open lecture file with vi editor like below.
By default vi editor will be opened as read mode. Now press ‘i’ to enable write mode and write your text that you want to write. Press ‘Esc’ key to go back in read mode. Generally :q keys are used to quit any opened file. But as you have edited this file, you have to save this file. So, use :wq keys to save and quit this file. If you want not to save this file but quit, use :q! keys combination.
CMD 11: shutdown
The shutdown command is used to halt, power-off or reboot your Linux system. Say, you want to down your system immediately, use shutdown command like below.
Now your system will go power-off state. If you want to reboot your system, you can use shutdown command with an extra option like below.
So, your system will reboot now. A lot of arguments and options are also available for shutdown command. Please see man shutdown command for more details.
Useful Tips about Linux Command Prompt
As you are a newbie in Red Hat Linux command prompt, below tips and tricks will be helpful for you.
- Tab Completion: Tab completion is a wonderful feature in Red Hat Linux system. It will help you to find any command or directory contents so easily. For example, you want to type mkdir command in your command shell. Then just type m or mk and press Tab key once or twice, you will find all the available commands or directory contents that are starts with m or mk characters. If there are only one command or directory content available, it will be completed automatically.
- Command History: Red Hat Linux automatically saved all the commands that you have executed in your command shell. So, if you need to repeat your previous command, just press Up or Down arrow to navigate your previous command from history and then hit enter key to execute your command.
The basic concepts that are necessary to get started with Red Hat Linux has been discussed in this article. Also some important command that are frequently used by the system administrators has been shown here. I hope you are now able to start your Red Hat Linux operating system from very beginning. However, if you get any difficulty about basic command in Red Hat Linux, feel free discuss in comment to contact with me from Contact page. I will try my best to stay with you.
Why not a Cup of COFFEE if the solution?