Reading Files Flashcards
[cmd] echo $SSH_CONNECTION
returns the ip address and port of the the client ssh and then shows the IP and port on the current server.
[cmd] $
expands a variable. So anything after the $ is a bash variable. So ie: echo $SSH_CONNECTION, the SSH_CONNECTION is the variable and the $ expands it to see its value
[cmd] cat /etc/hosts
cat stands for concatenate and will print the contents of a file or multiple files provided in the arguments as one single output
[cmd] wc -l /etc/server
wc stands for word count and the -l option counts the number of lines in the file provided in the argument
[cmd] !$
!$ is the variable that stores the last argument
[cmd] less
can use this cmd to print a files contents like you can with cat, but it allows you to page up and down for really long files. You can also search for s
[less] /text
the / search for whatever you text you type after the / in the open document. it is a forward search.
[less] ?text
Same as / but it searches backwards in the file
[less] n
When you search using / or ? you can use the n button to go the next found item
[less] q
closes the file and returns you to the normal bash cmd line
[cmd] head /etc/services
works the same way as cat but only shows you the first few lines (10 lines is the default)
[cmd] head -n 3
the -n 3 option specifies the number of lines you want head to return, so in this case it would return the top 3 lines.
[cmd] tail
the same as head but shows the last x lines. (the options work the same way too so -n 3 shows the last 3)
[cmd] yum list installed
lists all the installed packages on the system
[cmd] | (pipe)
the | (pipe) sends the output of the first cmd before the | to the second command after the |