reading-notes

reading notes for code fellows


Project maintained by dLeigh01 Hosted on GitHub Pages — Theme by mattgraham

Command Line Practice

The Command Line

A command line is an interface that takes in and returns data strictly through text. It typically will present you with a prompt and your response will be displayed after it. Terminals have something called a shell, which defines how the terminal appears and behaves.

A helpful shortcut is that you can go back through commands you have entered using the arrow keys rather than retyping them every time.

Basic Navigation

A path is a way to reach a particular file or directory. Absolute paths (which always being with a /) specify a location in relation to the root directory while relative paths specify a location in relation to you current directory. The root directory is the very top of your file hierarchy and is denoted by a single /.

cd [location] (change directory) is the command used to move between directories. You can either run it with a target directory, or you can just run cd, which will return you to your home directory.

A helpful shortcut is tab completion, which allows you to hit tab to auto-complete a path while you are typing it rather than writing out the entire path yourself.

I was previously unaware that you could add options to ls other than -a so that is something I will need to look into more for future use.

More About Files

Everything in linux exists as a file, whether it is an actual file or your monitor. Linux is also an extensionless system, which means that it looks inside a file to determine what it is rather than reading the extension that follows it. This can make it difficult to determine the type of some files, but the command file [path] will let you know. Linux is also case sensitive, so you can have multiple files with names that are spelled the same, but have slightly different casing. Spaces are a valid part of naming conventions for files in linux, but the terminal will not be able to find them just by typing the name as usual, you instead would need to either surround the name in quotes to refer to it, or use an escape character \ before the space to tell the terminal to ignore its normal meaning (If you use tab completion before the space, the terminal will automatically escape any spaces in the name).

If you want a file to be hidden, all you need to do is start the name with .. By default, ls will not show hidden files, but adding the -a option will show the hidden files as well as the visible ones.

It is interesting to learn how differently Linux treats things in the system as opposed to most other operating systems.

Manual Pages

The manual pages instruct you on what every different command does and can be invoked using man <command> and exited out of using q. You can also search for a specific keyword if your aren’t sure of the command you need using man -k <search term>. If you want results within a page you are already on, preceed the search term with a / and use n to cycle through results.

It may be easier to cement what commands are doing into your head using the longhand versions (for instance -a in longhand is --all), but either is acceptable. All longhand commands are preceeded by two dashes instead of one.

I didn’t know the manual pages existed, I’ve just been keeping a list on my computer of which commands do what for whenever I need to find something…

File Manipulation

It is important to put together a decnt file structure, especially as you amass more files. The command to make a new directory is mkdir [options] <Directory>. If you don’t use any options, a basic directory with the given anem will be created. Some different useable options when making a directory are -p which will also create necessary parent directories for the path you specify, and -v, which has the terminal say what it is doing as it creates the new directories.

To remove a directory, you use the command rmdir [options] <Directory>. A directory needs to be empty to be removed, but if you add the -r (recursive) option, it will allow you to remove the directory and everything within it (adding -i (interactive) as well will prompt you before deleting each file). The remove command for a file is rm [options] <file>. You should be careful using any of these, as these actions cannot be undone.

To create a new file, you use the command touch [options] <filename>. Touch is also used to modify files, but when you refer to something that does not exist, the terminal will create it.

If you want to copy a file or directory, the command is cp [options] <source> <destination>. To use this specifically on a directory, the option you want to add is -r (recursive), which will copy over every item within the directory.

To move a file or directory, you use the command mv [options] <source> <destination>. This works similarly to cp, but it is not necessary to use -r to move directories. You can also use mv to change the name of a file or directory by specifying the same path with a different name as the endpoint.

Final thoughts: Most of these commands I already knew, but I didn’t necessarily know everything going on behind the curtains. I think it was helpful and interesting to get a slightly different perspective on what is going on in the terminal and a few of the new things I learned about will hopefully be helpful to me in the future.

[< table of contents]

[< home]