Chapter 1: Exploring Linux Command Line Flashcards
GNU Born Again Shell
This is <b>bash</b>. It’s the most common shell, and was built upon the Bourne shell.
Bourne
This is <b>sh</b>. <b>sh</b> is now usually a pointer for another shell.
<b>tcsh</b>
Based on C shell, no major distributions default to it, but it’s fairly popular to a dedicated croud. It’s pretty similar to <b>bash</b>.
<b>csh</b>
C shell. It’s not used much anymore.
<b>ksh</b>
Korn shell. It was designed to combine the best elements of <b>sh</b> and <b>csh</b>. It has a small, dedicated following.
<b>zsh</b>
Z shell. It’s an evolution of <b>ksh</b>.
Default interactive shell
This is the shell that the user makes use of to interact with Linux.
Default system shell
This is the shell used by Linux to run system shell scripts, usually at startup.
<b>uname</b>
This displays your operating system. <b>uname -a</b> will give you a more verbose display.
Internal vs. External commands
You can determine whether a command is a built-in with <b>type</b>
<b>$type cd
cd is a shell builtin
$</b>
How do you run an external command when you have an internal command of the same name installed?
You have to type the whole directory path to it, because internal commands take precedence.
<b>$/bin/pwd
/root
$</b>
<b>chmod</b>
This command is used to change the executable status of a file.
Command Completion
If you’re lazy, you can hit tab while you’re typing in the command line and it will go through auto complete options that it thinks you may want
Command history
You can up arrow to go through the commands you’ve typed, or you can ctrl+R to search for commands you’ve typed.
Invoke a text editor
Type ctrl+x followed by ctrl+E. This launches the editor defined by <b>$FCEDIT</b> or <b>$EDITOR</b>.
- It will launch Emacs as a last resort.
- If you prefer vi to Emacs, type <b>set -o vi</b>
How do I retrieve and run the last command I ran?
With <b>!!</b> <b>$!! type -a pwd pwd is a shell builtin pwd is /bin/pwd $</b>
How do I clear my command history?
<b>history -c</b>
Where is my bash history contained?
in <b>/home/.bash_history</b>
<b>touch</b>
This is used to create an empty file.
<b>man</b>
<b>man</b> is how you access the user manual for damn near any program you could possibly want to run. You may use <b>info</b> as well, which produces about the same result, but displays it in hypertext format.
File Desctriptors
STDIN-0
STDOUT-1
STDERR-2
Common redirection operators
> creates a new file containing standard output
> Appends standard output to an existing file
2> Creates a new file containing standard error
2» Appends standard error to an existing file
&> Creates a new file containing STDOUT, STDERR
Causes a file to be used for STDIN, STDOUT
When you’re getting a bunch of useless error messages, what should you do?
<b>whine 2> /dev/null</b>
<b>/null</b> is a ghost directory that isn’t attached to anything, so all the files you send there go to Limbo.
Piping
<b>$first | second</b>
this sends the output of <b>first</b> to be the input of <b>second</b>.
<b>tee</b>
You can use this to see the STDOUT as well as create a file for output.
<b>$echo $PATH | tee path.txt</b>
<b>xargs</b>
This builds a command from its standard input.
Basic syntax:
<b>xargs [options] [command[initial-arguments]]</b>
<b>find /-user Christine | xargs -d “\n” rm</b>
That just found all the files and directories owned by Christine and removed them.
<b>cat</b>
<b>$cat first.txt second.txt > combined.txt</b>
This just combined the first and second files together.
<b>join</b>
Used to join data together based on common fields
<b>paste</b>
used to join data together with tab-separated columns.
<b>expand</b>
Turns tabs into spaces. The default amount of spaces is eight.
<b>od</b>
This stands for octal dump. It shows a file in an unambiguous format (octal by default, displays in hex, decimal, and ASCII with escaped control characters)
-this helps you view files that don’t play well with ASCII
<b>sort</b>
Used to sort output files. IT gets very in depth
<b>split</b>
This splits a file into certain sizes, you can determine by bytes, by maximum byte size with no line cutoffs, or by line.
<b>tr</b>
This translates characters. There are a lot of modifiers you can use.
<b>unexpand</b>
Converts spaces to tabs. This can compress the size of some files.
<b>uniq</b>
Removes duplicate lines.
<b>fmt</b>
REformats a file whose lines might be too long for your display
<b>nl</b>
Numbers lines in a file. Default numbers blank lines, too.
<b>pr</b>
Formats documents in a way that’s suitable for printing.
<b>head</b>
Echoes the first 10 lines of one or more files. You can change how many lines get echoed.
<b>tail</b>
Echoes the last 10 lines of one or more files. You may choose to keep it opened and view lines as they are added. This is useful with logs.
<b>less</b>
A robust file viewer that lets you read one page at a time.
<b>cut</b>
This extracts portions of input lines and displays them as standard output. You can cut specified lists of bytes or cut specified lists of characters. You can also cut specified lists of fields, which will produce different results
<b>list</b>
You can write lists in a few ways. one value <b>4</b> a range of values <b>2-4</b> all values leading up to something <b>-4</b> all values following something <b>4-</b>
<b>wc</b>
Displays a word count. <b>$wc file.txt 308 2343 15534 file.txt $</b> This shows us that the file has 308 lines, 2343 words, and 15534 bytes
Regular Expressions
Bracket Expressions -b[aeiou]g matches bag, beg, big, bog, bug Range expressions -a[2-4]z matches a2z, a3z, a4z Any Single Character -a.z matches abz, a8z, aUz....
<b>grep</b>
Searches for files that contain a specified string and return the name of the file and the line of context for that string.
<b>grep [options] pregexp] [files]</b>
<b>sed</b>
Directly modifies a file’s contents and sends it to STDOUT.
<b>sed [options] -f [script file] [input file]
sed [options] [script text] [input file]</b>