Essential GNU/Linux commands (initial draft)
This is a quick reference for some commonly used GNU/Linux commands. This document will be updated over the time to include more commands.
Image is captured on Linux Mint 19.2 Xfce Edition with cmatrix command running
1. Finding a file
There are multiple ways to search for a file. The easiest way is to use find command.
$ find [directory] -name "file name pattern"
$ find [directory] -iregex "pattern"
There are some additional parameters that can be used with find
command.
P
- Never follow symoblic links (default behavior)L
- Follow symbolic linksH
- Never follow symbolic links, except for files/folders mentioned with command.
2. Searching for a text in files
The grep
command can be used find a particular text in a set of files. By default, grep
prints the matching line.
$ grep "text" "file name pattern"
If you want to search recursively inside directories, you can use -r
with grep command.
$ grep -r "text" "directory name"
Following options can be used with grep command.
G
- basic regular expressioni
- ignore casev
- invert match, lines not matching with given pattern or textc
- number of lines matching with given patternH
- print output with file namen
- show line number
3. VI editor commands
VI is a command line text editor. It is the most commonly used editor in servers. Some important shortcuts in vi
editor are listed below. All these commands should be provided in non-interactive mode, ie, after pressing escape and there by leaving edit mode.
a
- append text after cursori
- insert text before cursorcw
- delete from current character to end of word and enable editingcc
- delete current line and enable editingdd
- delete current line:w
- save:q
- exit:q!
- exit without save:wq
- save and exit/string
- search for string?string
- search for string backwardn
- next match for search queryN
- previous match for search queryG
- Goto last linenG
- Goto nth linej
- cursor move downk
- cursor move up^
- beginning of line$
- end of linew
- one word forwardb
- one word backwardx
- delete characteru
- undo last changeyy
- copy to bufferp
- paste buffer after cursor:s/old_text/new_text
- find and replace
This is an incomplete list. It will be updated over time to include more commands used in regular life.
If you use a command regualrly and it is not listed here, please comment below so that we can update it here.