Command Line Flashcards

1
Q

What is $echo ?

A

It repeats the argument you type in with a new trailing newline character

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

What does the flag in $echo -n mean?

A

No new trailing newline character for the echo command

e.g. $echo Hello World
=> Hello World
=> $
e.g. $echo -n Hello World
=>Hello World $
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Does $echo “Hello World” -n works to eliminate new trailing newline character?

A

No. Flag always comes before arguments.

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

What does it mean:

$cd /

A

Change directory to ROOT directory.

NOTE: there’s a space in front of “/”

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

How to go back to your home directory in CLI?

A

$cd ~

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

What does it mean:

$pwd

A

It shows you your current directory is at.

pwd = Print Working Directory

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

What does it mean:

$ls

A

It shows you the files and directory under your current directory

ls = LiSt directory

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

What does it mean:

$ mkdir This is good

A

It creates a new directory under the directory you’re at
** You should name the new directory in the arguments

mkdir = Make Directory

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

What does it mean:

$touch abc.txt

A

This command creates a new file (*not directory) in the current directory

** type the file name and its file type in the arguments

abc.txt = a text file named “abc”

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

How to rename a file (named “toy.txt”)?

A

$ mv toy.txt toy2.txt

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

How does the pattern of $ mv works?

A

$ mv [source] [destination]

1) if you want to change the file name, determine the source file name and write the new name in destination.
2) if you want to move a file to another directory - specify you source file name and write the destined directory in the destination (**it does not apply to move from a subdirectory back to parent directory, see point 3) (file directory needs to have slash behind file name, e.g. tmp/)

3) You can even take a file in a directory under your current directory back to your current directory; and then rename it (if you only move and no rename, still need to type in the original name).
e.g. $ mv tmp/example1.txt example2.txt
$ mv tmp/example1.txt example1.txt

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

How to go back to the parent directory?

A

$ cd ..

.. = two dots

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

How to remove a file (e.g. “abc.txt”)?

A

$ rm abc.txt

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

How to remove a directory (e.g. “Tealeaf”)

A

$ rm -r Tealeaf

*Remember to add the flag -r for recursive delete of a directory; it’s different from just deleting a file.

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

How to exit from content listing command like $ man or $ less ?

A

type q

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

What does $ cat do?

A

It prints out all contents of a file

see also: $ head / $ tail / $ more / $ less

17
Q

What does $ head do?

A

It prints out the first few lines of a file

see also: $ cat / $ tail / $ more / $ less

18
Q

What does $ tail do?

A

It prints out the last few lines of a file

see also: $ more / $ cat / $ head / $ less

19
Q

What does $ more do?

A

It prints out the content of a file but only fills one screen worth at a time

20
Q

In Linux/Unix CLI, what does “/” mean?

A

1) Root directory

2) Separator when listing directories

21
Q

In Linux/Unix CLI, what does “.” mean?

A

The current directory

=> also as “./”

22
Q

In Linux/Unix CLI, what does “..” mean?

A

The directory one level up

=> also as”../”

23
Q

In Linux/Unix CLI, what does “../..” mean?

A

The directory two levels up

24
Q

In Linux/Unix CLI, what does ~ mean?

A

Home diretory

25
Q

In Linux/Unix CLI, what does “*” mean?

A

The splat/ glob operator.
=> represents “any characters”

e.g. ls /*e
list all files (not directories) that ends with “e”

e.g.2 mv ./* ../
=> move all files in current directory to parent directory

26
Q

How to create a nested set of directories in your home directory: cli-tmp > parents > children > grandchildren

A

mkdir -p ~/cli-tmp/parents/children/grandchildren

27
Q

Which one represents one directory up?

/..
../

A

../

28
Q

How to copy a directory with files (e.g. phone) and change the name (e.g. eight) at once?

A

$ cp -r phone eight

29
Q

How to list all files, including hidden ones

A

$ ls -a

All hidden files are named with a dot as first letter.
Hence, hidden files are also named dotfiles

30
Q

How to list hidden only files?

A

$ls -d .*

.* => all dotfiles / hidden files

31
Q

How to set environment Variables on the fly?

2 methods: set and then execute everywhere; set for a specific command at the same line

A

1)
$ CALIFORNIA=’CA’
$ echo $CALIFORNIA

2)
$ CALIFORNIA=’CA’ env
this method only sets variable to $env

*quote the value of variable, especially if there is special character in the value.

**no space between equal sign and value

32
Q

What will it do: $ top

A

It shows your computer working environment like CPU usage, programs you are using, etc.