Skip to content

Instantly share code, notes, and snippets.

@estysdesu
Last active July 21, 2019 06:04
Show Gist options
  • Save estysdesu/5096717f57b18c6248e695b8982bdae0 to your computer and use it in GitHub Desktop.
Save estysdesu/5096717f57b18c6248e695b8982bdae0 to your computer and use it in GitHub Desktop.
[Shell: view and work with file contents] #more #less #cat #head #tail #wc #sh
##### cat (SHOW ALL FILE CONTENTS) #####
cat <file> # shows all file contents
cat <enter>...<ctrl+d> # echos whatever is typed after enter (useful for redirecting stdin)
##### less/more (PAGERS) #####
less <file> # more advanced version of `more`; allows vim navigation
##### head/tail (PARTIAL CONTENTS) #####
# Normal indexing (GNU/UNIX)
head -n 5 <file> # first 5 lines (defaults to 10) == `head -5 <file>`
tail -n 3 <file> # last " " " " " == `tail -3 <file>`
# Negative indexing (GNU only)
head -n -15 <file> # show all but the last 15 lines
# Positive indexing (GNU only)
tail -n +8 <file> # show all lines after line no. 8
tail -f <file> # follow/show file contents as it grows
#### wc (WORD, LINE, BYTE/CHAR COUNT) #####
wc <file-1> <file-2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment