Terminal Usage and Shell commands Flashcards

1
Q

What is a Shell?

A

A shell is an OS-level application that interprets and executes user commands.
It provides an interface between the user and the operating system, allowing users
to interact with the system through text-based commands.

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

When navigating through the filesystem what do the following symbols represent: ~ | / | .. | .

A

▶ ~ Home directory
▶ / Root directory
▶ .. Parent of current directory
▶ . Current directory

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

When using vim how do you do the following:
- enter insert mode
- create a new file
- exit vim
- write in the file
- how to quit without saving

A
  • Press i to enter Insert mode.
  • Enter :save example.txt to create a file.
  • Enter :w to write the file without exiting.
  • Enter :q to exit and :q! to exit without saving
  • Enter :w to write in a file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do the following commands do:
- whoami
- uname
- id
- df
- echo

A

Command: whoami
Displays the username of the current user.
ex: user123

Command: uname
Shows system information.
ex: Linux ubuntu 5.4.0-72-generic

Command: id
Displays user ID and group ID.
ex: uid=1000(user123) gid=1000(user123) groups=1000(user123),27(sudo)

Command: df
Displays disk space usage
ex: Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 20G 28G 42% /

Command: echo
Displays a line of text or variables.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  • What command displays currently running processes?
  • What command Displays real-time process monitoring?
    -What command displays the manual page for other commands?
A
  • ps, ps aux(#all running processes (a) in a user-oriented format (u),
    #including those not associated with a terminal (x).)
    Ex:
    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME
    root 1 0.0 0.1 169336 1144 ? Ss 10:00 0:01
    user123 1836 0.1 1.5 50000 12300 ? S 10:10 0:00
  • top
    Ex:
    top - 10:15:42 up 1:15, 2 users, load average: 0.03, 0.05, 0.01
    Tasks: 92 total, 1 running, 91 sleeping, 0 stopped, 0 zombie
  • man command
    Ex: man ls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What do ls and ls -l do?

A
  • ls - list files and directories.
  • ls − l - shows child files and directories in a detailed format.
    ex:
    For ls -l it will display files in the mode drwxr—w-
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Explain what the Permissions configuration is and what it looks like

A

Permissions configuration:
The first character indicates whether it is a directory (d), a file (-), or a symbolic link
(l), among others.
The following 9 characters are divided into three groups of 3 characters each:
permissions for the owner, group, and others.
▶ r (read) - Permission to read.
▶ w (write) - Permission to write.
▶ x (execute) - Permission to execute.

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

What do pwd and cd do?

A
  • pwd (print working directory) - get current working directory.
  • cd (change directory) - change the directory.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you find files in the terminal?

A
  • Using the find command: Can be either name - case sensitive or iname - case insensitive
    -Ex: find . name “my_file.txt”
    -Ex: find ~ iname “my_File.txt”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do you create a file or a directory?

A

mkdir (make directory) - to make a directory.
touch - create empty files.

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

How do you remove a file or a directory?

A
  • rm file_name for files
  • rm -r dir_name for directories
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do you copy a file or a directory?

A
  • cp - copy files and directories.
  • cp -r for directories
    Ex:
    cp /source/file /dest/filename #to specify a new filename
    cp /source/file /dest/
    Ex:
    cp -r /source/dir/ /dest/dir/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do you move a file or a directory?

A
  • mv - move files and directories.
    Ex:
    mv /source/file /dest/dir/
    mv /source/dir/ /dest/dir/
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you change file permissions?

A

chmod (change mode) - change file permissions.
- +x for execute permission, +w for write permission, +r for read permission.
- u means user, g mean group, o means others.
Ex:
chmod u+w file.txt

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

How to sort lines in a file?

A
  • sort <filename.txt> #Sort alphabetically</filename.txt>
  • sort -r <filename.txt> #Reverse order</filename.txt>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What does uniq do?

A
  • uniq - filter out repeated consecutive lines.
  • uniq -u to display only truly unique lines
  • uniq -c counts duplicates
  • uniq -d shows only duplicates
  • uniq -i to ignore case
17
Q

What does grep do?

A
  • grep (global regular expression print)- return lines in file matching a pattern.
    Ex: grep do file.txt - returns all lines having do in them
    Ex: grep -i do file.txt - case insensitive
18
Q

What does cut do?

A
  • cut - extract a field from each line.
  • cut -c startLine endLine file.txt
  • cut -d “delimiter” -f2 file, where -f2 tells that you extract the second delimited value
19
Q

What does paste do?

A

paste - merge lines from different files.
Ex: paste file.txt file2.txt
- paste -d “delimiter” to add a delimeter