RHCE vi editor switches options descriptions
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 fileNow normal ls command will not list this file. Do a ls form current directory
$lsAs you can see in output .secret file is not shown here. But can see hidden file with –a switch.
$ls –a .secretNow rename and make it unhidden. Use mv command to rename the file
$mv .secret test $ls test
$vi testThis will open a window with bilking cursor. vi editor work in three different mode.
Esc Command mode [press Esc key before giving any command] Insert Insert mode [ to start editing use press Insert key ] Exit Exit mode [ Exit mode can be access via press Ecs key and :]Beside it there are various command which can be used to control the behavior of vi editor, some of them most command are there to remember
Esc +:+w+q save and exit form file Esc+:+q+! exit without saving Esc+:+set nu to show hidden line Esc+:+/test to find test word in forward directions Esc+:+21 to move cursor in line number 21 Esc+:+2+yy to copy 2 line form cursor Esc+:+p to paste the copied line below the crusor Esc+:+dd to remove the entire line Esc+:+4+dd to remove 4 line below of cursor Esc+:+x to remove single character Esc+:+e to go to end of the word Esc+:+h to go one character backWe have written a complete article about Vi editor. You can read it for more information about vi editor.
Vi editor guide how to use command reference
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.If this is a new file, you should see something similar to the following:
~
~
~
~
~
“/tmp/test” [New File]
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:
- a-The add command. After it, you can input text that starts to the right of the cursor.
- i-The insert command. After it, you can input text that starts to the left of the cursor.
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).
- w-Moves the cursor to the beginning of the next word.
- b-Moves the cursor to the beginning of the previous word.
- 0 (zero)-Moves the cursor to the beginning of the current line.
- $-Moves the cursor to the end of the current line.
- H-Moves the cursor to the upper-left corner of the screen (first line on the screen).
- M-Moves the cursor to the first character of the middle line on the screen.
- L-Moves the cursor to the lower-left corner of the screen (last line on the screen).
The only other editing you need to know is how to delete text. Here are few vi commands for deleting text:
- x-Deletes the character under the cursor.
- X-Deletes the character directly before the cursor.
- dw-Deletes from the current character to the end of the current word.
- d$-Deletes from the current character to the end of the current line.
- d0-Deletes from the previous character to the beginning of the current line.
To wrap things up, use the following keystrokes for saving and quitting the file:
- ZZ-Save the current changes to the file and exit from vi.
- :w-Save the current file but continue editing.
- :wq-Same as ZZ.
- :q-Quit the current file. This works only if you don’t have any unsaved changes.
- :q!-Quit the current file and don’t save the changes you just made to 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:
- Esc-Remember that Esc gets you back to command mode. (I’ve watched people press every key on the keyboard trying to get out of a file.) Esc followed by ZZ gets you out of command mode, saves the file, and exits.
- u-Press u to undo the previous change you made. Continue to press u to undo the change before that, and the one before that.
- Ctrl+R-If you decide you didn’t want to undo the previous command, use Ctrl+R for Redo. Essentially, this command undoes your undo.
- Caps Lock-Beware of hitting Caps Lock by mistake. Everything you type in vi has a different meaning when the letters are capitalized. You don’t get a warning that you are typing capitals-things just start acting weird.
- :! command-You can run a command while you are in vi using :! followed by a command name. For example,
- type :!date to see the current date and time,
- type :!pwd to see what your current directory is,
- type :!jobs to see if you have any jobs running in the background.
- INSERT-When you are in insert mode, the word INSERT appears at the bottom of the screen.
- Ctrl+G-If you forget what you are editing, pressing these keys displays the name of the file that you are editing and the current line that you are on at the bottom of the screen. It also displays the total number of lines in the file, the percentage of how far you are through the file, and the column number the cursor is on.
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:- Ctrl+F-Page ahead, one page at a time.
- Ctrl+B-Page back, one page at a time.
- Ctrl+D-Page ahead one-half page at a time.
- Ctrl+U-Page back one-half page at a time.
- G-Goto the last line of the file.
- 1G-Go to the first line of the file. (Use any number to go to that line in the file.)
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:- /hello-Searches forward for the word hello.
- ?goodbye-Searches backward for the word goodbye.
- /The.*foot-Searches forward for a line that has the word The in it and also, after that at some point, the word foot.
- ?[pP]rint-Searches backward for either print or Print. Remember that case matters in Linux, so make use of brackets to search for words that could have different capitalization.
- :g/Local-Searches for the word Local and prints every occurrence of that line from the file. (If there is more than a screenful, the output is piped to the more command.)
- :s/Local/Remote-Substitutes Remote for the word Local on the current line.
- :g/Local/s//Remote-Substitutes the first occurrence of the word Local on every line of the file with the word Remote.
- :g/Local/s//Remote/g-Substitutes every occurrence of the word Local with the word Remote in the entire file.
- :g/Local/s//Remote/gp-Substitutes every occurrence of the word Local with the word Remote in the entire file, and then prints each line so that you can see the changes (piping it through more if output fills more than one page).
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:- 3dw-Deletes the next three words.
- 5cl-Changes the next five letters (that is, removes the letters and enters input mode).
- 12j-Moves down 12 lines.
Basic RHCE commands using help for commands
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
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 testFor 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 testThis command will display the 3 line from bottom of file test
spell command will display the wrong spelling of files.how to find wrong spelling and correct them
$spell [file name]
$spell testThis 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 testThis 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 iThis command is use to display the username of currently logged.
$whoThis 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
$calThis command will display the calendar of current month. You can see the calendar of any specific year also.
$cal 2010 |more
$dateThis 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 catThis 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 - - helpThis 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 - - helpThis 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 catThis 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.
RHEL Linux basic commands cat bzip gzip pwd cd mkdir
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 fileNow 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
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/jIn this example we created 9 subdirectories form a single mkdir command. Now verify it by listing.
$ls new xyz rat anow 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/jCome 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
$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
| |
$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 manojFile 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
$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
Linux system administrations commands
Know how much space is consumed
#duThis 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 testCommand 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
#find /home –name vinita
How to abort any command
Some time you need to abort any command sequences. For example output of ping will not stop by default. Or some type you miss typed any command and press entered now command prompt is hanged in such a situation use CTRL+C key combination to abort the command in mid.How to locate any command path
#which [command]shows the full path of (shell) commands.Which command will tell you that which command are you using. By default a user use command form the path set in his profile. Its very handy tool specially in shell scripting.
#whereis [command]locate the binary, source, and manual page files for a command
How to use history and clear it
history utility keeps a record of the most recent commands you have executed. The commands are numbered starting at 1, and a limit exists to the number of commands remembered—the default is 500. To see the set of your most recent commands, type history on the command line and press ENTER. A list of your most recent commands is then displayed, preceded by a number.#history #history –cUse –c switch with history command to clear the history.
Check running process and terminate
#psThe ps ( process status) command is used to provide information about the currently running processes, including their process identification numbers (PIDs). A process, also referred to as a task, is an running instance of a program. Every process is assigned a unique PID by the system
#ps –efThe -e option generates a list of information about every process currently running. The -f option generates a listing that contains fewer items of information for each process than the -l option. Among the columns displayed by ps -ef, UID contains the username of the account that owns the process (which is usually the same user that started the process) and STIME displays the time the process started, or the starting date if it started more than 24 hours ago.
#kill [ps number]The kill command is used on Linux to terminate processes without having to log out or reboot the computer. Thus, it is particularly important to the stability of such systems. Each process is automatically assigned a unique process identification number (PID) when it is created for use by the system to reference the process.
The only argument that is required is a PID, and as many PIDs as desired can be used in a single command. Typically no signal or option is used. Thus, if it is desired to terminate a process with a PID of 485, the following will usually be sufficient:
kill 485
#pstreepstree command displays the processes on the system in the form of a tree diagram. It differs from the much more commonly used (and more complex) ps program in a number of respects, including that the latter shows the processes in a list rather than a tree diagram but provides more detailed information about them.
how check user set environment
#envenv command will display the environment set for user. A brief description about this output is
| EDITOR | Name of editor used. |
| HOME | The directory that you are first logged into |
| SHELL | The program you run as your command-line interpreter. |
| TERM | The type of terminal emulation used |
| PATH | Listing of directories searched when logging on |
| Location of where the mail is stored | |
| MANPATH | Location of your Manuals. |
| LOGNAME | The login name |
| TZ | Time zone of computer |
how to check CPU run time status
#topWhen you need to see the running processes on your Linux in real time, you have top as your tool for that. top also displays other info besides the running processes, like free memory both physical and swap. use q to quit from the output of top commands.
how to set alias for commands
#alias san=clearalias command is used to set alias with any command. Mostly alias is used in shell scripting. In our example we set an alias for clear command. Now whenever you need to clear the screen type san instead of clear command. This will work till only you are logged in if want to set alias permanently then do editing in user profile files.
#uname –auname command is used to gather the system information’s. you can use several switches with commands. Few of them are.
-a, --all
print all information, in the following order:
-s, --kernel-name
print the kernel name
-n, --nodename
print the network node hostname
-r, --kernel-release
print the kernel release
-v, --kernel-version
print the kernel version
-m, --machine
print the machine hardware name
-p, --processor
print the processor type
-i, --hardware-platform
print the hardware platform
-o, --operating-system
print the operating system
--help
display this help and exit
--version
output version information and exit
how to send message to all logged in user
#wallwall sends a message to everybody logged in . The message can be given as an argument to wall, or it can be sent to wall's standard input. When using the standard input from a terminal, the message should be terminated with the EOF key (usually Control-D). The length of the message is limited to 20 lines.
To shutdown the system
#halt –p #init 0
To reboot system
#reboot –f #init 6 #reboot
No comments:
Post a Comment