3. Working with Text Files Flashcards

1
Q

How do you output the contents of a file to the terminal?

A

By executing the cat command and passing it the path to the file name.

eg. cat textfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you browse through the contents of a text file?

A

By executing the less command and passing it the file name. After this, you can press SPACE to go down, B to go up, and / to search for text.

eg. less textfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you reset the terminal?

A

By executing the reset command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you find out what type a file is?

A

By executing the file command and passing it the path to the file.

eg. file textfile.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What can be said about the necessity of file extensions in the UNIX world?

A

They are not necessary, although it’s usually a good idea to use them anyway.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you open a file in its default GUI application on Mac?

A

By executing the open command and passing it the path to the file.

eg. open textfile

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the two major commands you need to know for listing text files in the shell?

A

cat and less.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Are UNIX file names case-sensitive?

A

In Linux, they are. In MacOS, they are not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you remove a file?

A

By executing the rm command and passing the file path.

rm somedir/somefile.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What should be the mindset about using rm?

A

Be careful with it. It will remove your files without warning and you will not be able to get them back.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do you create a new directory?

A

By executing the mkdir command and passing it the name of the folder to be created.

mkdir my-directory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you create a new file?

A

By executing the touch command and passing it the name of the file to be created.

touch new-file.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How can you reference a file with a name that has space(s) in it in the shell?

A

By using backslashes before each space or wrapping it in singlequotes.

touch 'my file.txt'
// OR
touch my\ file.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you escape special characters in the shell?

A

By using a backslash before each of them or wrapping the reference with single-quotes.

touch sen\ kimsin\ yarram.txt
// OR
touch dur\ amk\ ben\ kimim\ lan.txt
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How do you create multiple files at the same time?

A

By executing the touch command and passing it multiple file names.

touch file1 file2 file3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the best practices for naming files?

A
  1. Use letters, numbers, dots, dashes, and underscores — want to be really safe? Only use lowercase letters.
  2. Be careful with spaces, especially trailing spaces.