Main Menu

Search

Showing posts with label UNIX. Show all posts
Showing posts with label UNIX. Show all posts

VI EDIT COMMANDS CHEAT SHEET

VI Editor Key / Command Options


 

  ZZ      Exit, saving changes           t<x>   Up to <x> forward

  Q       Enter ex mode                  T<x>   Back up to <x>

  <ESC>   End of insert                  <x>|   Go to column <x>

  :<cmd>  Execute ex command             w,W    Forward one word

  :!<cmd> Shell command                  b,B    Back one word

  ^g      Show filename/size             e,E    End of word

  ^f      Forward one screen             ^h     Erase last character

  ^b      Back one screen                ^w     Erase last word

  ^d      Forward half screen            ^?     Interrupt

  ^u      Backward half screen           ~      Toggle character case

  <x>G    Go to line <x>                 a      Append after

  /<x>    Search forward for <x>         i,I    Insert before

  ?<x>    Search backward for <x>        A      Append at end of line

  n       Repeat last search             o      Open line below

  N       Reverse last search            O      Open line above

  ]]      Next section/function          r      Replace character

  [[      Previous section/function      R      Replace characters

  %       Find matching () { or }        d      Delete

  ^l      Redraw screen                  dd     Delete line

  ^r      Refresh screen                 c      Change             

  z<CR>   Current line at top            y      Yank lines to buffer

  z-      Current line at bottom         C      Change rest of line

  ^e      Scroll down one line           D      Delete rest of line

  ^y      Scroll up one line             s      Substitute character

  ``      Previous context               S      Substitute lines   

  H       Home window line               J      Join lines         

  L       Last window line               x      Delete after       

  M       Middle window line             X      Delete before      

  +       Next line                      Y      Yank current line  

  hjkl    Cursor movement:               p      Put back lines     

          left/down/up/right             P      Put before         

  0       Beginning of line              <<     Shift line left    

  $       End of line                    >>     Shift line right   

  f<x>    Find <x> forward               u      Undo last change   

  F<x>    Find <x> backward              U      Restore current line

 

 

Exit Mode Key / Command Options


 

  q       Quit                        set <x>   Enable option

  q!      Quit, discard changes       set no<v> Disable option

  r <f>   Read in file <f>            set all   Show all options

  sh      Invoke shell

  vi      Vi mode

  wq      Write and quit

  w <f>   Write file <f>

  w! <f>  Overwrite file <f>

 

 

Replacing Command options


 

:s/ptrn/strg/flag - Replace pattern with string

Following are flag options

g   -   Replace all occurences of pattern

c   -   Confirm replaces

&   -   Repeat last :s command

 

Check Special Characters


 

:set list   -   command in VI mode will list special hidden characters in white spaces in file.

 

 
 
 

Products to which Article Applies

All UNIX Operating Systems

Search Keywords:  cheatsheet cheet cheat cheetsheet command commands option options reference guide editor editing

Article Author: Tarun Boyella

LINUX: Take Backup of Files Using DateTimeStamps In Backup Filename (How To Doc)

Below is the command to take backup of file so that backup file has datetimestamps (Date / Timestamps) in name when the file was backed up.
cp -rp testfile.out testfile.out__$(date +%F'-'%T)

In above command example we are backing up testfile.out. Change this filename to the filename you want to backup. Below is example snippet which shows the backup file created with datetimestamps (highlighted in bold).

-rw-r--r-- 1 root root   0 Sep 28 14:39 testfile.out__2019-09-28-14:39:16
-rw-r--r-- 1 root root   0 Sep 28 14:39 testfile.out

Products to which Article Applies

All UNIX Operating Systems

LINUX: How To Capture STRACE Output Into A File? (Troubleshooting Doc)

Below strace command can be used to capture the strace command output into a file.
strace -o /tmp/outfile.out ls

In above command we are capturing strace on "ls" command. We can replace "ls" command with the command or proess against which we are running strace. In above example strace output is being redirected to /tmp/output.out file. The output filename can be changed accordingly.


Products to which Article Applies


All Linux and UNIX environments

Additional References




LINUX: "find" Command To File Large Files Only in Local Root File Systems Excluding NFS Shares (How To Doc)

In Linux and UNIX Environments often times there may be need to clean up local filesystem space as it is full. In environment with NFS shares mounted it can get tricky to just identify the large files inside local file system. Below find command can be used to find the large files only in local file system.


find / -xdev -type f -size +500k -exec ls -lh {} \; | sort -n -r

Above command will search for all files inside only the local non NFS file systems which are over 50kb in size and then sort them by size and display.


Products to which Article Applies

All Linux and UNIX Environments.

LINUX: "find" Command To Find Large Files

In Linux and UNIX Environments often times there may be need to clean up filesystem space as it is full. So you will have to identify the files which are huge in size which needs to be checked and them cleaned. For finding the large files which in the file system below command can be used.


find /tmp -type f -size +50k -exec ls -lh {} \; | sort -n -r

Above command will search for all files inside /tmp which are over 50kb in size and then sort them by size and display.

You can change the /tmp to any directory where you want to search for the large files. In case you want to search inside all the directories / filesystems you can specify /. For e.g. as shown below.


find /-type f -size +50k -exec ls -lh {} \; | sort -n -r


Products to which Article Applies

All Linux and UNIX Environments.


LINUX: Command To Manually Mount NFSv3 Share On Linux Hosts (mount command)

Below is the command to manually mount NFS share on Linux hosts. In this example we are mounting NFSv3 share.

mount -t nfs -o vers=3 <Storage IP>:<ShareName> <Local NFS Share Name>

For e.g. if Storage IP is 10.10.10.10 and Share name is /export/testshare and your local directory which you are trying to mount as NFSv3 share is app-share, your mount command will look as follows:

mount -t nfs -o vers=3 10.10.10.10:/export/testshare/app-share

Products to which Article Applies

This Note applies to all Linux and UNIX hosts.