Page Content

Tutorials

What Is Command Line Crash Course Navigation In Ruby

Command Line Crash Course Navigation in Ruby

The Command Line Crash training is marketed as a quick, basic training that may be finished in one or two days on average. Its main objective is to impart basic abilities such that the user is “barely capable” of interacting with the shell in the same way as a real coder.

Instruction a series of regulated activities intended to develop expertise through repetition is the foundation of the fundamental educational approach. Because the goal is to teach the hands, brain, and mind to read and write code, users are constantly reminded to “Shut up and type all of this in” and are not allowed to copy and paste.

In order to help students remember key commands, the course frequently recommends making index cards for drilling (e.g., matching the command name to its description, and vice versa).

You can also read Modules In Ruby: Supplies Mixins And Serving As Namespaces

Core Navigation Commands

Users should only input the command that appears after the prompt while interacting with the command line; they should not type the prompt characters ($ for UNIX/Linux/OS X or > for Windows/PowerShell).

Print Working Directory ()

The user’s current location inside the file system is displayed by this command. The phrases directories and folders are synonymous.

CommandDescription
pwdPrints the working directory (folder).

Change Directory ()

CommandDescriptionKey Usage and Context
cdChange directory.Moves the current location from one directory to another. If the directory name contains spaces, it must be enclosed in quotation marks (e.g., cd "I Have Fun").

List Directory Contents ()

CommandDescriptionKey Usage and Context
lsLists out the contents of the directory.Crucial for navigation as it shows the user what is in a directory. On UNIX, variations like ls -lR can be used.

You can also read What Is Mean By Mixins In Ruby With Practical Code Examples

An example of Linux/OS X code:

$ pwd
/Users/zedshaw
$ 
``` 

#### Change Directory (`cd`)
The `cd` command moves the user between directories.

| Command | Description |
| :--- | :--- |
| `cd` | Changes the current directory. |
| `cd ..` | Moves up one level in the directory structure . |
| `cd ~` | Returns the user to their home directory. |

**Navigation Tip:** If you become lost, you should immediately type `pwd` to see your location, and then `cd ~` to return to safety (the home directory) before continuing the exercises

Code Example (Linux/OS X – Moving Down and Up):

```bash
$ cd temp
$ pwd
~/temp
$ cd stuff/things/frank/joe/alex/john
$ cd ..
$ cd ..
$ pwd
~/temp/stuff/things/frank/joe
$ 
``` 

If a directory name contains spaces, it must be enclosed in quotes when using `cd`, for example: `cd "I Have Fun"`.

#### Make Directory (`mkdir`)
This command creates a new directory or folder

Code Example (Linux/OS X)


```bash
$ mkdir temp
$ mkdir temp/stuff
$ mkdir -p temp/stuff/things/frank/joe/alex/john
$
``` 

#### List Directory (`ls`)
This command lists the contents of the current directory

Here is a single, simple code example demonstrating these fundamental navigation commands, shown in a typical Linux/OS X session format (note: you should not type the $ character, which represents the command prompt):

$ pwd
/Users/zedshaw 
$ mkdir temp
$ cd temp
$ pwd
~/temp
$ cd ..
$ ls
temp

You can also read File I/O In Ruby: Basic Operations To Advanced File Handling

Agarapu Geetha
Agarapu Geetha
My name is Agarapu Geetha, a B.Com graduate with a strong passion for technology and innovation. I work as a content writer at Govindhtech, where I dedicate myself to exploring and publishing the latest updates in the world of tech.
Index