Command Line Flashcards

1
Q

What’s the difference between abc/ and /abc?

A

The path ‘abc/’ (or ‘./abc’ and ‘./abc/’) are relative to the current working directory.

The path ‘/abc’, however, is the file or directory in the ROOT directory.

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

How do you access the root directory? Example?

A

Using the / symbol.

e.g. $ /abc
Access the directory abc in the root directory.

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

How do you access the current directory? Example?

A

Using . or ./ symbols

e.g. ‘import from ./components’
(Import a file from the components folder that is located in the same directory as the file with the line of code.)

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

How do you access a directory one level up? Example?

A

Using .. or ../ symbols

e.g. $ ../../abc
Access the “grandparent” folder that is two directories up.

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

What is the home directory and how do you access it?

A

Using ~ symbol

The home directory is the directory you are placed in when you log in (i.e. when you log in to the mac, you are placed in ~ jennyhai).

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

What is the wildcard symbol? Example?

A

Using the * (aka splat or glob) symbol

The wildcard symbol can represent and characters.

e.g. $ cp ../folder/* ./
(Copy all files in ‘folder’ to current directory.)

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

How do you create a set of nested directories?

A

Using ‘mkdir -p’

e.g. ‘mkdir -p ~/parents/children/grandchildren’
(Create nested directories in home directory if they do not already exist.)

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

How do you copy and rename a folder?

A

Using ‘cp -r’

e.g. $ cp -r grandchildren ../nephews
(Copy the grandchildren folder located in the current folder to the parent folder and also rename it ‘nephews’.)

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

What is the tree command?

A

Use the ‘tree’ command to view the directory tree of a certain folder.

e.g. 'tree ~/home'
└── parents
  ├── children
  │   ├── bob
  │   └── grandchildren
  │       └── bob
  └── nephews
      └── bob
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a command? Where are they located?

A

A command is just a file. ‘ls’, ‘mkdir’, and ‘cd’ are all files. Files that can be used as commands are called executables. These files have special characters in the beginning to tell computer how to execute. They also have scrips or machine language as their content and executable permission.

e.g. $ /bin/echo “Hello World”
(Print “Hello World”)

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

How do you show the list of hidden files?

A

$ ls -a
(Show all files including hidden files)

$ ls -d
(Show only hidden files)

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

What is the fastest way to move multiple files in a folder except for one?

A

The fastest way till be to move all files in the folder using ‘$ mv * ~/newfolder’ and then move back the single file ‘$ mv ~/newfolder/1.file ./’

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

How do you find the path of your current location in the command line?

A

Using ‘pwd’ command

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

What are environment variables in the command line?

A

Environment variables are stored data that can be referenced and retrieved at a later point using a name.

e.g. $ MESSAGE=’Hello World’
$ echo $MESSAGE
==> Hello World

NOTE: Method above will only temporarily modify/create environment variables. Once the terminal is closed and restarted, the variables will no longer exist.

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

How do you change environment variables permanently?

A

Modify the .bash_profile and .bashrc files to permanently modify environment variables. .bash_profile is a log-in shell that runs every time the terminal starts.

i.e. export PATH=”/path/to/my/executables-directory:$PATH”

(adding the above line of code into .bashrc will modify the PATH variable)

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

What is the $PATH variable in the command line?

A

The $PATH variable tells the command line where to find a particular command (file) to execute. It is an ordered list of directories (connected by colons) that contain executables.

Using the command ‘$ which cd’ will tell you which folder the cd command is located in.

You can also modify the $PATH variable to add commands.

e.g. $ PATH=$PATH:/usr/jennyhai
(appends /usr/jennyhai as a path to search for commands to execute)

17
Q

What types of permissions are available in Unix and Linux systems?

A

Permissions are divided into two parts: ownership and access types.

3 levels of ownership: user, group, and other
3 levels of access types: read, write, and execute

Each level of ownership can be granted any or all the access types. Total possible combinations is 2^ 9, or 512.

IMPORTANT: Permissions are assigned to files and directories - not users and groups.

18
Q

What is the chmode command and how does it modify permissions?

A

chmode stands for change mode and allows you to set permissions on a file or directory

You can prefix the permission with u (user), g (group), o (other), or a (all).

e.g. 
// Add write access: $ chmod +w sample.txt
// Remove write access for user: $ chmod u-w test.txt
// Add execute access for group: $ chmod g+x test.txt
19
Q

How do users and groups work?

A

Users can belong to multiple groups and groups can have multiple users. If a user belongs to a group, it will have the access types granted to the assigned group.

Using the ‘groups’ command, you can see if the user is part of a certain group.

IMPORTANT: Permissions are assigned to files and directories - not users and groups.

20
Q

What is a root user?

A

The root user is the super user and can read, write, and delete any file. Because the root user has so much power, it is common recommendation to not log in as a root.

21
Q

What is the sudo command?

A

The sudo command can perform actions that require root privileges. When the command is used, you will usually be prompted to input a password.

i.e. sudo reboot

22
Q

What are bob’s permissions to the laptop file in the following example? What are the permissions for the group acmeinc?

-r-xrwx— 1 bob acmeinc 0 Jul 21 17:57 laptop

A

The user bob has read and execute permissions, and the group acmeinc has read, write, and execute permissions.

23
Q

What is a nested Bash interface?

A

Bash is a special interface in which a command line may be nested within a command line. For example, many databases also use the command line to manage their systems. Scripting languages and text editors may also utilize CLI.

You can exit the innermost “shell” by typing exit. When you’re in the outermost shell, you’ll see something like [process completed] or the terminal will exit.