Week 1 - File and Text Manipulation Flashcards
What command do you use to view files?
cat
What is cat short for?
concatenate
How do you limit viewing large file output to 1 page at a time? What command? Can also be used to view a file
windows
more
What commands can you use to navigate ‘more’? W
Enter advance one line
Space advance one page
Q to exit
arrows
Using cat, how do you only see only the beginning or ending lines?
You use the parameters:
-Head #of lines
-Tail #of lines
In Linux, what command to view file contents?
cat
In Linux, how do you customize the output size of the view file contents command? Can also be used to view a file
less
LESS IS MORE LOL
In the less program in Bash, what are the different commands you use to navigate around the text?
q to exit
g to go to the beginning
G to go to the end
/word_search
How do you open a Notepad++ and create a file on the same command line? w
start Notepad++ filename.txt
What’s the command to open a program? w
start
What’s the command in Linux to create a file using a Linux popular text editor? This also allows you to create/modify a text file in the Shell
nano filename
What does the ^K mean? (the carrot)
to use Control + K
With what command do you see the actual command that gets executed in Powershell?
Get-Alias (command)
What are 2 ways to execute commands in PowerShell?
- use cmd.exe and \? for the equivalent of Get-Help for cmd.exe commands
- use the real PowerShell commands (relatable aliases) and Get-Help for more information
How do you configure the service to index file contents? Windows. 5 steps
- indexing options (search bar)
- Users
- Advanced
- File Types
- Select ‘Index Properties and File Types’
What’s the shortcut to “Find in Files” in Notepad++? (searches specific sectors depending on settings)
CTRL + Shift + F
What are 2 ways to search within files on Windows? What should be done first?
First: enable indexing options
- use Notepad++
- use PS command sls
What does sls stand for? w
select desk string
finds strings of characters or words
What’s a regular expression? w
a pattern-matching language used by sls to find text that matches
What is a “string”?
A way for the computer to represent text
strings of characters, words, etc
What powershell command lets you search for a word in a file?
sls
or
Select-String
don’t have to be in the same directory as it
What does the wildcard asterisk mean?
selecting all
How do you use regular expressions and a command to search for a word in a pattern (entire computer directories)? Provide example
Select-String lemonade *.txt
How do you quickly change directories to go back to the desktop?
cd ..
What command do you use to search and display a list of patterns within a >specific< directory like D:\Program Files
ls ‘D:\Program Files' -Recurse -Filter *Adobe
Recurse to search specific directory
Filter filters results for file names that match
What command does the -Filter parameter combine with when listing items with patterns and what does it do?
Combines with ls to filter results matching specific patterns
What is a similar command to Select-String in Linux?
grep
On Linux, what does grep let you search? 4
search for words within files that match a pattern
if a certain file exists in a directory
if a word was in a file
search through multiple files
What’s an example of a search a word within a text file command on Linux?
grep apple fruit.txt
do you have to be in the same directory to search the targeted file using grep? Linux
yes
How do you search for a word in multiple files in Linux?
Use the asterisk and grep
grep notes *_notes.txt
like if the file name was biology_notes.txt
math_notes.txt
What is echo an alias for?
Write-Output
What does the echo command do?
Let’s us write the output we want to see (the alias is Write-Output)
What can every Windows process and PowerShell command do with input?
produce output using I/O streams or input output streams
What are the 3 types of I/O streams?
- standard input stdin
- standard output stdout
- standard error stderr
What is a redirect/operator and what is its function? w
A redirect operator lets us change where we want our standard output to go
> >
What redirector operator do you use if you only want to add onto a file, not overwrite it? What would it look like?w
You use the double greater than > > -Append command
echo relaxed faces > > existingfile.txt (no spaces in the > > brainscape gives me an error when they’re together)
echo used because we’re writing our keyboard input into the output existing file using the > > operator
What does the pipe operator look like?
|
What are 3 redirect/operators that let us change the standard out?
- >
- > >
- |
When would you use ls ‘(location)’ -Recurse -Filter *(search file or word)
and
cat words.txt | Select-String mi
ls and *wildcard etc is used when searching all directories in a location for a specific pattern (words, file extensions, etc)
the pipe operator and Select-String is only searching a specific file for words taken from the output of words.txt
What does it mean when you use 2> in regards to a standard error stream? How is it used in a command sequence when trying to remove secure_file?
2> means that you want to redirect the standard error stream to a file instead of the standard output (we won’t see it in the CLI)
example:
rm secure_file 2>error.txt
What’s a special variable that contains the definition of nothing? A black hole for the purpose of redirection?
$null
What variable do you use to filter out error message streams? What’s an example of its use when removing a secure_file? Windows
$null
rm secure_file 2>$null
What’s the difference between redirecting the output/error stream using 2> and the pipe | operator?
2> = this is used to filter or redirect error stream messages from the computer system/PowerShell itself
(1> would redirect output stream system messages)
Pipe | operator = used to redirect output results from a search or command
What redirect operator adds onto a file?
> >
What redirect operator creates or overwrites a file?
>
What number do we use to represent the standard error stream?
2
What number do we use to represent the standard output stream?
1
If I want to quickly make a text file with some text in it, no programs, what command can I use?
echo sentences > filename
You’re viewing the contents of Google.txt using ___, what command can you use to search for a word (hotdog) in that document and then create a file (hawdawg.txt) containing the results?
Using cat to view contents of Google.txt
cat Google.txt | Select-String hotdog > hawdawg.txt
Do you have to be in the same directory as the word you’re searching for using sls?
No
What does the standard input redirector look like?
<
less than
What does the standard in redirector do?
Instead of taking input from the keyboard, it uses a file as input
In Linux, how do you redirect the error message of some output from a ls?
ls /dir/fake_dir 2> error_output.txt
NOW name all 5 redirectors we’ve learned so far
- <
- >
- > >
- |
- 2>
What is the Linux version of windows’s $null?
/dev/null
How would you search to see which subdirectories are in a directory that match a certain word (toast)? Linux
A list of subdirectories that match Toast…
ls -la /locationtosearch | grep toast
In Bash, what command and 2 flags can be used to view a list of all files in the /home directory?
ls -l -a /home
ls -la /home
How do you change to another directory that’s in the same current directory?
cd ../directoryname
in Bash forward slash
Windows back slash
In Bash, what commands can be used to view the contents of a document? 2
less
cat
What are 2 ways to search for a word (fruit) in a group of text files? in Bash
grep fruit *.txt
grep fruit apple.txt chocolate.txt orange.txt
on Linux, we have a directory called /home/ben/Documents, how do we search for the word “important” in the filenames in that specific directory? 2 ways
ls /home/ben/Documents | grep important
grep -rw /home/ben/Documents -e “important”
on Windows, what command would you use to see the first 10 lines of a file called “more_information.txt”
cat more_information.txt -Head 10
Linux. What does adding the flag -l do when added to the ls command?
You can view more details about the files that are listed like ownership and permissions
What type of files is the less command suited for? Linux What happens when you use less? What is it similar to?
For large input files, it’s similar to cat but opens a program and allows movement within the files (scrolling by Enter, q, etc)
How would you create multiple directories at once?
mkdir dir1 dir2 dir3
What are 3 parameters that mkdir accepts?
- -p makes parent directories if they don’t exist
- -m mode used to set permissions of directories when created
- -v run command in verbose mode
What command removes empty directories? What are the directories to be removed referred to as?
rmdir
they’re referred to as an argument
What does the command look like to remove multiple empty directories?
rmdir dir1 dir2 dir3
How do you remove non-empty directories?
rm -r
What’s the only option that rmdir accepts?
-p removes parent directories if they’re also empty
By default, what does the touch command do? L
creates a new file with default permissions
the touch command changes the modification and access times of a file
what happens when you use touch for a file that doesn’t exist? L
touch command is used to create a file with default permissions
touch empty_file
what options does the touch command accept? Linux
-c do not create file if it doesn’t exist
what command lets you create a file with default permissions? L
touch
Does cp replace/overwrite existing files with the same name?
yes
What happens if you use cp but don’t specify a target name?
a copy of the source will be made in the target directory under the same name
When using cp, if the target is a directory that doesn’t exist, then the source must be a ____
directory
a copy of source directory and contents are made in target under same name
What does the mv command do?
moves one or more files or directories into a different location
also renames them to a new name
What does the command look like when moving fish.txt from home/Desktop to home/Desktop/Folder1?
mv fish.txt home/Desktop/Folder1
How do you insert a special character space for a file name? Linux What would it look like for /home/user/Movies/Europe Pictures?
/home/user/Movies/Europe\ Pictures
needs the space after the escaped backslash
What’s a shortcut to copy or move files to the current directory that you place? l
(takes the place of destination directory filepath)
mv and a dot after navigating to the directory you want to move something to
mv /home/user/Images/Vacation .
How do you remove a directory with content? L
rm -r non_empty_dir
-r tells rm to remove directory with its content recursively
What does grep do? L
powerful Linux command
searches through files for the occurence of a string that matches a specified pattern
What options and flags are accepted by grep? L 6 things
-r search recursively
-w match the whole word
-n only in line number
-e match pattern
–include and –exclude (to ex/include files in search)
–include-dir and –exclude-dir (to ex/include directories in search)
Explain what to search recursively means?
to search in each sub-level
How do you open an existing file to edit in nano on Linux?
nano /path/to/existing/file
What are some shortcuts for use in editing a text file in nano?
CTRL O to save modifications
CTRL X to exit
CTRL G get help
In the current directory of user/Documents create an empty file called editor_test.txt. Linux.
touch editor_test.txt