Files Flashcards
Wildcards
A character or string used for pattern matching. Wildcards can be used with most commands. ○ ls ○ rm ○ cp \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ ● * - matches zero or more characters. ○ *.txt ○ a* ○ a*.txt ● ? - matches exactly one character. ○ ?.txt ○ a? ○ a?.txt
Input / Output Types
I/O Name I/O File Descriptor
Stand. Inp. stdin 0
Stand. Outp. stdout 1
Stand. Err. stderr 2
Redirection Symbols
>
»
<
&
>
Redirects standard output to a file. Overwrites (truncating) existing contents.
> >
Redirects standard output to a file. Appends to any existing contents.
< Redirects input from a file to a command
& Used with redirection to signal that a
file descriptor is being used.
Redirection Example
2>&1 Combine stderr and standard output.
2>file Redirect standard error to a file.
Searching Files Syntax
and Options
Display lines matching a pattern.
grep [pattern] [file]
_______________________
-i Perform a search, ignoring case.
-c Count the number of occurrences in a file.
-n Precede output with line numbers.
-v Invert Match. Print lines that don’t match.
Searching for Text in Binary Files
Display printable strings.
> strings
Pipes Syntax
command-output | command-input
Viewing Files with Nano Editor
Open file
>nano [file directory]
Help/ man pages: Ctrl+G
Exit man pages: Ctrl+X
Quit Nano: Ctrl+X > It will ask you if you want to save
Viewing Files in Real Time - e.g for Logs
tail -f [file]
Viewing / Editing files with VI Editor
dd
Viewing / Editing files with VI Editor
vi [file] Edit file. vim [file] Same as vi, but more features. view [file] Starts vim in read-only mode. \_\_\_\_\_ i Insert at the cursor position. I Insert at the beginning of the line. a Append after the cursor position. A Append at the end of the line. \_\_\_\_\_\_\_\_\_\_\_ \:w Writes (saves) the file. \:w! Forces the file to be saved. \:q Quit. \:q! Quit without saving changes. \:wq! Write and quit. \:x Same as :wq.
vi Editor switches for navigation
k Up one line. j Down one line. h Left one character. l Right one character. w Right one word. b Left one word. ^ Go to the beginning of the line. $ Go to the end of the line.