Linux 2 Flashcards
How would you copy a single file?
Call the cp command with two arguments, the source file you want to copy and the target file you want to copy it to.
What happens if you use the cp command with a directory as the target?
You will end up with a copy of the source file inside of the named directory.
How can you copy multiple files at once?
Using the cp command, you can list several source files and use a directory name to specify where you want copies of those files to go. The original file names of the source files will be used as the names of the new files in the target directory.
What will happen if you try to copy a directory to another directory using cp?
If you didn’t use -r (the recursive flag), you will get an error message.
What flag can you use to overwrite a file that is not under your current username?
The -f (force) flag.
What flag can you use in order to prompt for confirmation when copying over existing files?
cp -i
What command is used to delete files and folders?
rm
The process for moving files is almost identical to that of copying files. Which command is really just a combination of cp and rm to achieve the desired outcome of moving a file from one location to another?
mv
Can you use the mv command to move a file across systems?
No.
What is the Unix philosophy for commands?
Don one thing, and do it well.
With these seemingly small individual commands, we can build some impressive work flows by redirecting the output of one command to the input to another command using the ____ operator.
pipe ( | )
In addition to redirecting the output from one process and sending it to another process, we can alos write that output to a file using the ____ operator.
>
We can use the > to write data to a file, but how can we read data from a file?
With the
What are two common command line search tools?
ack and ag
How do you run an ag search?
ag
By default, your ag query is run recursively against _____.
the current directory
If you want to specify a path to search against with ag, what can you do?
Pass as a final argument the path you want to search.
Both Ack and Ag treat the search term as a _____ by default.
regular expression
How can you stop Ag and Ack from treating your search term as a regular expression, and instead find the exact pattern you type?
using the -Q flag
What flag can you use if you just want to see the filenames where the pattern was found, rather than the line number, etc.?
the list flag (-l)
By default, all Ag and Ack searches are case-sensitive, but you can change this with the __ flag.
-i
What flag can you use to limit the scope of your Ack or Ag search?
the -G flag (-g for Ack, -G for Ag)
e.g.: ag readme -l -G action
searches for readme in files which have “action” in the filename
How do you use the -ignore-dir flag?
ag readme -l –ignore-dir=railties/lib
command, search term, flag, flag = name of directory to be ignored
Can you string multiple -ignore-dir flags together?
Yes
Can you use -ignore-dir to ignore particular files?
Yes
Which file specifies ignore files for Ag and Ack, respectively?
.agignore and .ackrc
Since Ag and Ack expect standard input as a source for searching, we can use other commands to _____.
provide data to search over.
How would you search through all of the running processes to find one that contains the term forego?
ps -e | ag forego
How can you get a print out of Ag or Ack’s full features?
Call the command with no parameters.