Exam 2 Flashcards
Absolute pathname
Absolute pathname: refers to the complete path of a directory or file starting from the root directory (/). It
specifies the exact location of the directory or file in the filesystem hierarchy.
For example, /home/user/documents/file.txt is an absolute pathname. It starts from the root directory
(/) and specifies the complete path to the file file.txt
Relative pathname
specifies the location of a directory or file relative to the current working directory.
. (dot) represents the current directory.
.. (dot-dot) represents the parent directory.
~ (the tilde character) is a shorthand representation of the current user’s home directory.
!
not
$
Following string is a variable (should be all CAPS)
;
chains commands together
&
if one command errors. The next command will not run
`` backquote
substitutes whatever command is on the inside with its output
‘ ’ single quote
protects everything
“ ” double quotes
protects most things except \ = protects everything
*
represents unknown 0-255 char
?
represents only 1 char
[]
represents only 1 char and can contain numbers and a range of numbers and char and a range of char
[! ]
represents only 1 char and searches for anything not including the range/char/number indicated
apropos
search with a keyword
same as man -k command
cal
display current month’s calendar
option for calendar year
-y
cal -3
calendar for 3 months: previous, current, next
cd
change directory with an absolute or relative pathname
clear
clear the screen
date
display/change the system date and time
echo
display or echo output to the terminal screen
echo -e
utilize escape sequence
echo -n
newline
file
determine file type and display the detail information
How do you format the date time to show…
Today is dayName, monthName DAY YEAR
date +“Today is %A, %B %d %Y”
ls
list contents of a directory
ls -l
use long listing format
ls -a
shows all files including hidden files
ls -F
shows files with type indicator
ls -R
lists subdirectories recursively
ls -r
reverse order when sorting
ls -d
lists directory names instead of contents
ls -S
sort by file size
ls -i
prints the index number of each file
man
display online manual pages
man -k
search for keyword
mkdir
create the new directory
mkdir -p
create a hierarchy directory
mv
move files or rename files
mv -i
prompt if file move/rename will overwrite a file
pwd
display the working directory with the
absolute pathname
rm
remove files or “non-empty” directory
rmdir
remove the “empty” directory
touch
create a new file or multiple files as well
as change time stamp
whatis
searches the what is database for
complete words
who
display the number and Status of Users
Logged In?
whoami
displays who you are.
rm –r
remove the directories with files
rm -f
enforce
Redirect operator “<”
”<” input redirection.
redirect the standard input of a command to come from a file instead of the keyboard.
Redirect operator “>”
redirect the standard output of a command to a file.
If the file does not exist, it will be created. If the file already exists, its contents will be overwritten.
Redirect operator “»”
append the standard output of a command to a file.
If the file does not exist, it will be created. If the file already exists, the output will be added to the end of the file.
Redirect operator “|”
”|” pipe symbol, is used to connect the output of one command to the input of another. It allows you to chain multiple commands together, forming a pipeline.
For example, you can use command1 | command2 to pass the output of “command1” as the input to “command2”.
cat
concatenate and display the contents of files. It’s often used to read files sequentially, display their content, combine multiple files, create new files, and append contents to existing files.
Options -b -n -T
cat file1
display the contents of the file1
cat > newfile
create a new file and manual entry the contents for the ‘newfile’
cat file1 > file2
copy the contents of file1 to create a file2
cat file1 file2
combine file1 and file2 one after the other on the screen
cat file1 file2 > file3
combine file1 and file2 one after the other and save the result to the file3 instead of displaying on the screen
cat file1 >> file2
append contents of file1 to file2
cmp
compare two files byte by byte. It’s often used to check if two files are identical or to find differences between them
cmp [option] file1 file2
comm
compare two sorted files line by line. Outputs three columns.
1. lines unique to file1 (suppress with -1)
2. lines unique to file2 (suppress with -2)
3. files common to both (suppress with -3)
comm [options] file1 file2;
cp
copy Files or directories
-i
-r or –R recursive
-f
cut
extract sections from a file or input. Useful for selecting columns from text files like CSV files
cut -f 2 -d ':' file1 > file2
-f: Specifies the field(s) to extract ( -f1,3
extracts fields 1 and 3).
-d: Specifies the delimiter to use (default is the tab
character).
-c: Extracts characters by position (e.g., -c1-5
extracts characters 1 to 5 of each line).
diff
compare the contents of two files line by line. Showing the differences.
find
search for files and directories within a specified path. locates files based on various criteria such as filename, size, permissions, modification time, and more.
find <path> <options>
grep
search for specific strings within files
head
display the beginning or the first few lines of
a file. By default, it prints the first 10 lines of each
specified file to the standard output.
head -n
display the beginning specified lines of a file
join
joining lines of two files on a common field
less
use to page through files; similar to more
ln
create links between files
links are references or pointers to the original file
hard links and symbolic link
ln -s
Creates a symbolic (soft) link
ln -f
Forces the creation of the link by overwriting an
existing link with the same name.
ln -v
show what links are being created
ln -i
Prompts before overwriting an existing link.
more
view files a screen at a time
mv -f
enforce
od
display the contents of files in
various formats, such as octal or
hexadecimal.
paste
merge lines horizontally (side by side) of files, separated by a specified delimiter (by default, a tab).
paste [options][file ...].
pr
format text files for printing.
Headers, divide text into columns, set custom margins, add page numbers, and adjust the layout to make printed output more readable.
pr -n
Sets the number of columns (e.g., -2 for two
columns).
pr -d
Double-spaces the output.
pr -l N
-l N: Specifies the number of lines per page
(default is 66).
pr -w N
Sets the width of the output in characters
(default is 72).
rm -i
prompt before removal
sed (stream editor)
text transformations on an input stream. Used for search, replace, substitute text.
sort
sorts the text file by line
strings
extract printable strings from binary files
tac
the reverse of “cat” command. It is used to concatenate and display the contents of files in reverse order, line by line
tail
display the last few lines of a file.
By default, it prints the last 10 lines of
each specified file to the standard output.
tail -n
display the last specified lines in each specified file
tee
reads input and writes output to screen and/or file
command | tee [options] [file …].
view and save the output
of a command.
tr
translate or delete characters from standard input.
character substitution, deletion, case conversion.
tr -d
d: Deletes characters specified in set1.
tr -s
Squeezes multiple occurrences of a character in
set1 into a single occurrence in the output.
uniq
remove duplicate lines
wc
word, line and character counts
-lcw
pr -h
Sets a custom header text