Advance System administrations commands
1 . Step by Step Guide of vi Editor how to use switches options descriptions | ||||||||||||||||||
2 . Vi Editor Guide how to use command Reference switch and description | ||||||||||||||||||
3 . Basic RHCE commands using help for commands | ||||||||||||||||||
4 . RHEL Linux basic commands cat bzip gzip pwd cd mkdir | ||||||||||||||||||
5 . Linux system administrations commands Example and description 1 . Step by Step Guide of vi Editor how to use switches options descriptions
In our last assignment your learnt about cat command. cat is a very basic command you cannot depend on cat command in exam to create files as cat is a very essential command. In cat you can neither see the matter of file nor modify the material. In this assignment we are going to use world's most powerful editor vi.
Before we go further just learn how to create a hidden file in linux and see it.
$cat > [.name of file]
A single dot in front of the file will make it hidden. For example to make a file named secret to hidden use this command
$cat > .secret This is a secret file
Now normal ls command will not list this file. Do a ls form current directory
$ls
2 . Vi Editor Guide how to use command Reference switch and description
Critical to a Linux administrator is knowledge of one or more text editors to manage the many configuration files on a Linux system. The Linux file system hierarchy organizes hardware, drivers, directories, and of course, files. You need to master a number of basic commands to manage Linux. Printer configuration can be a complex topic. Shell scripts enable you to automate many everyday processes. Security is now a huge issue that Linux can handle better than other operating systems; locally, and on larger networks such as the Internet.
The VIsual Editor
Linux and Unix are managed through a series of text files. Linux administrators do not normally use graphical editors to manage these configuration files. Editors such as WordPerfect, starOffice, and yes, even Microsoft Word normally save files in a binary format that Linux can't read. Popular text editors for Linux configuration files include emacs, pico, joe, and vi.
While emacs may be the most popular text editor in the world of Linux, every administrator needs at least a basic knowledge of vi. While emacs may be more popular and flexible, vi may help you save a broken system. If you ever have to restore a critical configuration file using an emergency boot floppy, vi is probably the only editor that you'll have available. You need to know how to restore your system from a rescue floppy, which does not have enough room to carry any editor other than vi.So should know how to use vi editor.
$ vi /tmp/test
If this is a new file, you should see something similar to the following: ~ ~ ~ ~ ~ “/tmp/test” [New File]
The box at the top represents where your cursor is. The bottom line keeps you informed about what is going on with your editing (here you just opened a new file). In between, there are tildes (~) as filler because there is no text in the file yet. Now here's the intimidating part: There are no hints, menus, or icons to tell you what to do. On top of that, you can't just start typing. If you do, the computer is likely to beep at you. And some people complain that Linux isn't friendly.
The first things you need to know are the different operating modes: command and input. The vi editor always starts in command mode. Before you can add or change text in the file, you have to type a command (one or two letters and an optional number) to tell vi what you want to do. Case is important, so use uppercase and lowercase exactly as shown in the examples! To get into input mode, type an input command. To start out, type either of the following:
Type a few words and then press Enter. Repeat that a few times until you have a few lines of text. When you're finished typing, press Esc to return to command mode. Now that you have a file with some text in it, try moving around in your text with the following keys or letters: Remember the Esc key! It always places you back into command mode.
Arrow keys-Move the cursor up, down, left, or right in the file one character at a time. To move left and right you can also use Backspace and the space bar, respectively. If you prefer to keep your fingers on the keyboard, move the cursor with h (left), l (right), j (down), or k (up).
The only other editing you need to know is how to delete text. Here are few vi commands for deleting text:
To wrap things up, use the following keystrokes for saving and quitting the file:
If you've really trashed the file by mistake, the :q! command is the best way to exit and abandon your changes.
The file reverts to the most recently changed version. So, if you just did a :w, you are stuck with the changes up to that point. If you just want to undo a few bad edits, press u to back out of changes.
You have learned a few vi editing commands. I describe more commands in the following sections. First, however,
here are a few tips to smooth out your first trials with vi:
Moving Around the File
Besides the few movement commands described earlier, there are other ways of moving around a vi file. To try these out, open a large file that you can't do much damage to. (Try copying /var/log/ messages to /tmp and opening it in vi.) Here are some movement commands you can use:
Searching for Text
To search for the next occurrence of text in the file, use either the slash (/) or the question mark (?) character. Follow the slash or question mark with a pattern (string of text) to search forward or backward, respectively, for that pattern. Within the search, you can also use metacharacters. Here are some examples:
The vi editor was originally based on the ex editor, which didn't let you work in full-screen mode. However, it did enable you to run commands that let you find and change text on one or more lines at a time. When you type a colon and the cursor goes to the bottom of the screen, you are essentially in ex mode. Here is an example of some of those ex commands for searching for and changing text. (I chose the words Local and Remote to search for, but you can use any appropriate words.)
Using Numbers with Commands
You can precede most vi commands with numbers to have the command repeated that number of times. This is a handy way to deal with several lines, words, or characters at a time. Here are some examples:
Putting a number in front of most commands just repeats those commands. At this point, you should be fairly proficient at using the vi command. Once you get used to using vi, you will probably find other text editors less efficient to use.
In this article I will show some basic system administration related task which a normal user can perform. To complete this assignment login from normal user which we created in our first assignment.
How to count line word and character form a file$wc [file name]
This command is used to count line words and character of file. Out will first show the line number word and in the end characters.
$wc test 2 4 23 test
In this example there are 2 lines 4 words and 23 character in test file.
how to display top and bottom line form files$head –n [number] [file name]
head command is used to display specific number of line from top for given file.
$head –n 4 test
For example this command will show the 4 top most line of file test.
$tail –n [number] [file name]
tail command will display the specific number of line form bottom for given file.
$tail –n 3 test
This command will display the 3 line from bottom of file test
how to find wrong spelling and correct them$spell [file name]
spell command will display the wrong spelling of files.
$spell test
This command will display the wrong spelling of test file. If there is no spelling mistake no out will show.
$aspell check [file]
This command is used to correct the spelling related mistake in any given files.
$aspell check test
This command will show the all wrong spelling from test file and there possible corrections. To use correction just press the number shown in front of words.
how display logged in user information and terminal number$who am i
This command is use to display the username of currently logged.
$who
This command will display all the user currently logged in all terminals.
$ttyThis command is used to display the terminal number of currently logged in terminals. how to display date time and calendar$cal
This command will display the calendar of current month. You can see the calendar of any specific year also.
$cal 2010 |more
This will display the calendar of year 2010. As output will be more than a page so use more switch with commands.
$date
This will the current system times and date.
how to use calculator$bc how to get help about commands$info [command]
info command is used to get help about any commands.
$info cat
This will display the help about cat commands. Generally output of info commands is more a then a page. You can quit form this out by just pressing q.
$command - - help
This help options is really very useful when do not want to be read full manual page for help. This will provide very basic help like which switch will work with this command.
$cat - - help
This will show the available switch cat command and a very brief descriptions about these switches.
$man [command]
If want to read the detail about any command use this command. This will give you the complete detail about commands.
$man cat
This command will give the complete details about the cat commands including switches and their usages. Use q to quit from the output of this commands.
$less [file]
When you have a file more than one pages use less command to read the output of file despite of using cat command with more switch. As with more switch you cannot scroll the text in both directions.
$cat [file] |moreIf you have a file more than one page than use |more switch with cat to read the output. Without this switch matter of file will scroll too fast that you will see only texts of last pages 4 . RHEL Linux basic commands cat bzip gzip pwd cd mkdir
In our last assignment you perform some basic task related to system administration from normal user. In this assignment we will extend this further. To complete this assignment login form our normal user Vinita.
How to redirect the matter of files in a new file
Create two file and write some text in them.
$cat > one This is first file $cat > second This is second file
Now we will combine these two files in a single file. In standard linux its call redirection of output.
$cat one second > new $cat new This is first file This is second files How to execute multiple commands in a single row$[command] ; [command] ; [command] ;[command]……..
To execute multiple commands from single row use a ; between them form example
$cat new ; mkdir xyz ; mkdir rat ; ls This is first file This is second files new xyz rat
this command will first execute the first command which is cat new so it will display the matter of new file, further is mkdir xyz so it will create a xyz directory , further is mkdir rat so will create a rat directory and in the end we use ls command so it will list the contain of current directory.
How to create multiple sub directory form single command
To create multiple sub directory from a single command use –p switch with mkdir command for example
$mkdir –p a/b/c/d/f/g/h/i/j
In this example we created 9 subdirectories form a single mkdir command. Now verify it by listing.
$ls new xyz rat a
now change the directory to verify the depth of directories.
$cd a/b/c/d/f/g/h/i/j $pwd /home/vinita/a/b/c/d/f/g/h/i/j
Come back to home directory. Simple cd command without passing any argument will do this.
$cd How to move multiple file in directory with a single commands?
Give all files name one by one with a single space between them and in the end give the destination directory name for example
$mv new first second xyz
This command will move three files new, one, second to the xyz directory.
$cd xyz $ls New one second $cd .. how to take back-up and restore files and directories.
tar command is used to take the back up with –cvf switches and the same tar command is used to restore the matter with –xvf switches. For example
$tar –cvf backup.tar xyz $ls $rm –rf xyz
In linux you cannot restore the data once deleted unless you have backup. Now restore these files and directory.
$tar –xvf backup.tar $ls $cd xyz $ls new first second$cd .. How to compress files to save disk space?
Create a large file and check how much disk space is consumed by this file
$man ls > manoj $du –h manoj 12k manoj
File manoj is using 12k space on hard disk. For exam prospective you should familiar with two compress utilities.
$bzip2 [file name] {command syntax} $bzip2 manoj $ls $du -h manoj.bz2 4k manoj.bz2
To decompress file
$bzip2 –d manoj.bz2
$ls manoj
as you can show file has been decompressed. Now use other utility to compress the file.
$gzip manoj $ls manoj.gz $du –h manoj.gz 4k manoj.gz $gzip –d manoj.gz $ls manoj 5 . Linux system administrations commands Example and description
In our last few assignments you learnt system administration related task which a normal user can perform. In this assignment I will direct you some handy task for root user. To accomplish this assignment login form root account.
Know how much space is consumed#du
This command will show the usages of disk by files and folder. Output of this command show in bytes. To show it in KB use –h switch.
#du -h [file name]
To know that how much space is consumed by any specific file. For example
#du –h test 12 Kb test
Command is showing that size of test file is 12 kb.
Know how much space is available#df [partition]
df command is used to know the available space on any given partitions. For example to know available space on / partition use this command
#df / How to find any files#find [where to find] – name [what to find]
find command is used to find any object in linux. For searching object you can also use locate command but locate command is based on mlocate database. For example to find vinita directory on entire linux use
#find / -name vinita
Or to find only in /home partition use
#find /home –name vinita
|
No comments:
Post a Comment