Command Line Flashcards
What do the following keystrokes do when used in the terminal emulator?
Ctrl+Alt+(F2, F3, F4, etc)
Opens TTY2, TTY3, TTY4, etc.
Prints the user name associated with the current effective user ID. It is equivalent to the command ‘id -un’.
whoami
Prints the name of the current working directory.
pwd
Prints information about the machine and operating system it is run on.
uname
Print all of the information available about the system, except omit the processor type and the hardware platform name if they are unknown.
uname -a
Prints the kernel release
uname -r
Prints the kernel version
uname -v
Print the saved bash history file to screen (usually saved at logout unless done manually)
cat .bash_history (when executed from user’s home folder)
Lists all files (including hidden ones) in the directory specified.
ls -a
Lists files in the specified directory and adds the following classification indicators:
/=directory
*=executable file
@=symbolic link
ls -F
Produces a long listing of file information
ls -l
Displays all the lines of a text file. Also used to concatenate files together.
cat
What does the following command do?
cat -n 10 [filename]
Displays the first 10 lines of text from [filename]
Similar to cat command, but shows the last (10 lines by default) of a specified file
tail
What does the following command do?
tail -f [filename]
Displays text lines as they are added to a file
By default, displays the following counts of a text file:
1- lines
2- words
3- bytes
wc
By default, shows only unique lines of a text file; not duplicates:
Lines are considered duplicate, if:
- They have the exact same content
- Are on two lines, one after the other, in the file
The following options can be used with this command:
- Display a count number of times duplicate line occurs (-c)
- Print only duplicate lines, and show only one occurrence (-d)
- Print only duplicate lines, but show all occurrences (-D)
uniq
- By default, provides a line number for each file text line
- Lines numbers are not added to file; only displayed
- By default, blank lines are not numbered
nl
- By default, sorts a designated text file alphanumerically
- Use the -n option to sort a text file numerically
- Does not modify the original file
sort
- Displays designated files’ data in a side-by-side column format
- Output may be sloppy in appearance
- Does not modify the original files
paste
- Splits up a text file
- Does not modify original file; creates new files with data
- By default, new file names are xaa, xab, xac, and so on
split
- Displays a designated field from all the text file’s records
- Use delimiter (-d) option to designate file record character that separate the fields
- Use field number (-f) option to designate field to display
- Use cut (-c )option to designate character(s) location to display
cut
- Translates one character in a file to another
- Needs the < symbol prior to the text file name
- Does not modify the original file
tr
- By default, displays a files’ data in octal
- Can display a files’ data in hexadecimal
- Useful for analyzing binary files in hexadecimal
od
- Stream editor utility
- Searches for string in text file and replaces first occurrence
- Searches for string in text file and replaces all occurrences
- Does not modify the original file
sed
To Replace First Occurrence:
sed ‘s/string/replacement-string/’
To Replace All Occurrences:
sed ‘s/string/replacement-string/g’
Simple Text Search Command
grep
- Simple text search: grep string file
- Case insensitive text search: grep -i string file
- Search for string at line’s beginning: grep ^string file
- Search for string at line’s end: grep string$ file
- Sends STDOUT to two different locations
- Location 1: designated file
- Location 2:
STDOUT or
STDIN to next pipeline command
tee
File Descriptor: 0
stdin
File Descriptor: 1
stdout
File Descriptor:2
stderr
What file is knows as the “black hole?”
/dev/null
Finds the following files for a command:
- Binary
- Source
- Manual pages
whereis
Find a file by its name
locate
Manually update mlocate.db
updatedb
More configurable way to search for a file
find
Common ‘find’ search options
Determine a file’s type with _______.
file
Update all the file’s timestamps
touch [file]
Update only the modification timestamp
touch -m [file]
Update only the access timestamp
touch -a [file]
tar -c
Creates a tar archive by placing copies of the designated files in the designated archive.
Also: tar –create
tar -u
Add files that were changed since an archive was created to pre-existing tar archive.
Also: tar –update
tar -v
Displays a file’s name as it is added to the archive.
Also tar –verbose
tar -d
Compare files in a tar archive with the same files that exist outside of the archive, and display any differences.
Also: tar –compare, tar –diff
tar -t
Show the files in a tar archive file.
Also: tar –list
tar -W
As a file is added or removed from the archive, verify it (not available when creating tarballs).
Also: tar –verify
tar -x
Extract copies of the files from an archive file and places them in the current working directory.
Also: tar –extract, tar –get
tar -O
Extract copies of the files from an archive file and send them to standard outpost (STDOUT).
Also: tar –to-stdout
tar -v
Displays a file’s name as it is copied from the archive.
Also: tar –verbose