3. Working with Text Files Flashcards
How do you output the contents of a file to the terminal?
By executing the cat
command and passing it the path to the file name.
eg. cat textfile
How do you browse through the contents of a text file?
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 do you reset the terminal?
By executing the reset
command.
How do you find out what type a file is?
By executing the file
command and passing it the path to the file.
eg. file textfile
.
What can be said about the necessity of file extensions in the UNIX world?
They are not necessary, although it’s usually a good idea to use them anyway.
How do you open a file in its default GUI application on Mac?
By executing the open
command and passing it the path to the file.
eg. open textfile
What are the two major commands you need to know for listing text files in the shell?
cat
and less
.
Are UNIX file names case-sensitive?
In Linux, they are. In MacOS, they are not.
How do you remove a file?
By executing the rm
command and passing the file path.
rm somedir/somefile.txt
What should be the mindset about using rm
?
Be careful with it. It will remove your files without warning and you will not be able to get them back.
How do you create a new directory?
By executing the mkdir
command and passing it the name of the folder to be created.
mkdir my-directory
How do you create a new file?
By executing the touch
command and passing it the name of the file to be created.
touch new-file.txt
How can you reference a file with a name that has space(s) in it in the shell?
By using backslashes before each space or wrapping it in singlequotes.
touch 'my file.txt' // OR touch my\ file.txt
How do you escape special characters in the shell?
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 do you create multiple files at the same time?
By executing the touch
command and passing it multiple file names.
touch file1 file2 file3