Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
themeDJango
echo "foo bar" > foo.txt



Info

As an aside; a nice command to create an empty file named new_file.txt is the touch command, which is run as touch new_file.txt 

Info

Feel free to also do this with a code editor, if you've used one already!

...

Code Block
languagebash
themeDJango
wget https://www.gutenberg.org/cache/epub/10/pg10.txt -O james.txt
Info

As an aside; a nice command to create an empty file named new_file.txt is the touch command, which is run as touch new_file.txt 

Viewing Files

To view the text of a file in the terminal, the first command we can use is the cat command (short for concatenate), which takes in as an argument the file we want to view the text of, and simply prints it all to the terminal:

...

Info

If you are given a choice between copying a directory (using cp) and moving it (using mv), the latter will always be faster. cp has to move all the contents, but when using mv, the operating system simply has to move around the pointer to the directory in the directory hierarchy, and doesn't have to move all of the data individually (if you're curious about what a pointer is, check out the C/C++ Training!)

Removing Files

Infowarning

The commands discussed in this section will have permanent, irreversible effects. Use them with caution and at your own risk. Unless you are certain that you will never need the files again, it is recommended that you instead move them to a temporary location (C2S2 will likely come up with a command to automatically do this, poke Aidan or the team lead if you want it sooner (smile))

...

Footnote

Strictly speaking, what rm does under the hood is eliminates the pointer to the files from the directory structure (basically, lose the reference our operating system has to its contents) and frees up the memory for the operating system to store other content there. If you were able to externally access the hard drive before the operating system re-wrote that location (hint: turn off the machine immediately, hopefully before the operating system uses that memory), and discern the location in memory where the content was previously stored, one could theoretically get the contents back. There are specialists who have the tools to do this, but for 99.9% of users, it is impossible. If you're curious, to really get rid of data, you can use some systems have the shred command to overwrite the memory such that it can't be recovered even by experts - such an operation may be useful if you're disposing of sensitive data.

...