Command Line Flashcards

1
Q

What do the following keystrokes do when used in the terminal emulator?

Ctrl+Alt+(F2, F3, F4, etc)

A

Opens TTY2, TTY3, TTY4, etc.

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

Prints the user name associated with the current effective user ID. It is equivalent to the command ‘id -un’.

A

whoami

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

Prints the name of the current working directory.

A

pwd

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

Prints information about the machine and operating system it is run on.

A

uname

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

Print all of the information available about the system, except omit the processor type and the hardware platform name if they are unknown.

A

uname -a

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

Prints the kernel release

A

uname -r

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

Prints the kernel version

A

uname -v

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

Print the saved bash history file to screen (usually saved at logout unless done manually)

A

cat .bash_history (when executed from user’s home folder)

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

Lists all files (including hidden ones) in the directory specified.

A

ls -a

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

Lists files in the specified directory and adds the following classification indicators:
/=directory
*=executable file
@=symbolic link

A

ls -F

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

Produces a long listing of file information

A

ls -l

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

Displays all the lines of a text file. Also used to concatenate files together.

A

cat

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

What does the following command do?
cat -n 10 [filename]

A

Displays the first 10 lines of text from [filename]

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

Similar to cat command, but shows the last (10 lines by default) of a specified file

A

tail

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

What does the following command do?
tail -f [filename]

A

Displays text lines as they are added to a file

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

By default, displays the following counts of a text file:
1- lines
2- words
3- bytes

A

wc

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

By default, shows only unique lines of a text file; not duplicates:

Lines are considered duplicate, if:

  1. They have the exact same content
  2. Are on two lines, one after the other, in the file

The following options can be used with this command:

  • Display a count number of times duplicate line occurs (-c)
  • Print only duplicate lines, and show only one occurrence (-d)
  • Print only duplicate lines, but show all occurrences (-D)
A

uniq

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  • By default, provides a line number for each file text line
  • Lines numbers are not added to file; only displayed
  • By default, blank lines are not numbered
A

nl

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  • By default, sorts a designated text file alphanumerically
  • Use the -n option to sort a text file numerically
  • Does not modify the original file
A

sort

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  • Displays designated files’ data in a side-by-side column format
  • Output may be sloppy in appearance
  • Does not modify the original files
A

paste

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  • Splits up a text file
  • Does not modify original file; creates new files with data
  • By default, new file names are xaa, xab, xac, and so on
A

split

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
  • Displays a designated field from all the text file’s records
  • Use delimiter (-d) option to designate file record character that separate the fields
  • Use field number (-f) option to designate field to display
  • Use cut (-c )option to designate character(s) location to display
A

cut

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  • Translates one character in a file to another
  • Needs the < symbol prior to the text file name
  • Does not modify the original file
A

tr

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
  • By default, displays a files’ data in octal
  • Can display a files’ data in hexadecimal
  • Useful for analyzing binary files in hexadecimal
A

od

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
  • Stream editor utility
  • Searches for string in text file and replaces first occurrence
  • Searches for string in text file and replaces all occurrences
  • Does not modify the original file
A

sed

To Replace First Occurrence:
sed ‘s/string/replacement-string/’
To Replace All Occurrences:
sed ‘s/string/replacement-string/g’

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

Simple Text Search Command

A

grep

  • Simple text search: grep string file
  • Case insensitive text search: grep -i string file
  • Search for string at line’s beginning: grep ^string file
  • Search for string at line’s end: grep string$ file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
  • Sends STDOUT to two different locations
  • Location 1: designated file
  • Location 2:
    STDOUT or
    STDIN to next pipeline command
A

tee

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

File Descriptor: 0

A

stdin

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

File Descriptor: 1

A

stdout

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

File Descriptor:2

A

stderr

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

What file is knows as the “black hole?”

A

/dev/null

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

Finds the following files for a command:

  • Binary
  • Source
  • Manual pages
A

whereis

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

Find a file by its name

A

locate

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

Manually update mlocate.db

A

updatedb

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

More configurable way to search for a file

A

find

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

Common ‘find’ search options

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

Determine a file’s type with _______.

A

file

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

Update all the file’s timestamps

A

touch [file]

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

Update only the modification timestamp

A

touch -m [file]

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

Update only the access timestamp

A

touch -a [file]

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

tar -c

A

Creates a tar archive by placing copies of the designated files in the designated archive.

Also: tar –create

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

tar -u

A

Add files that were changed since an archive was created to pre-existing tar archive.

Also: tar –update

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

tar -v

A

Displays a file’s name as it is added to the archive.

Also tar –verbose

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

tar -d

A

Compare files in a tar archive with the same files that exist outside of the archive, and display any differences.

Also: tar –compare, tar –diff

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

tar -t

A

Show the files in a tar archive file.

Also: tar –list

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

tar -W

A

As a file is added or removed from the archive, verify it (not available when creating tarballs).

Also: tar –verify

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

tar -x

A

Extract copies of the files from an archive file and places them in the current working directory.

Also: tar –extract, tar –get

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

tar -O

A

Extract copies of the files from an archive file and send them to standard outpost (STDOUT).

Also: tar –to-stdout

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

tar -v

A

Displays a file’s name as it is copied from the archive.

Also: tar –verbose

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

tar -j

A

Use bzip2 to compress/decompress archive file / tarball.

Also: tar –bzip2

51
Q

tar -J

A

Use xz to compress/decompress archive file / tarball.

Also: tar –xz

52
Q

tar -z

A

Use gzip to compress/decompress archive file / tarball.

Also: tar –gzip

53
Q

When using the ls command, what are the 5 file type codes associated with the output?

A

File (-)

Directory (d)

Symbolic Link (l)

Block Device (b)

Character Device (c)

54
Q

What commands show your current group memberships?

A
  1. groups
  2. id -Gn
55
Q

What command shows your current effective group?

A

id -gn

(id-Gn shows all group memberships)

56
Q

What are the symbolic mode levels for the chmod command?

A

u - owner

g - group

o - others

a - owner, group, and others (all)

57
Q

What are the octal mode permissions for the chmod command?

A

0 - no permission

1 - execute permission

2 - write permission

4 - read permission

58
Q
  • Set on World level of permissions on a directory
  • Allows sharing of files in a directory
  • Only file’s owner may delete file
A

Sticky Bit

59
Q

How do you set special permissions in Octal Mode?

A
  • Execute permissions needed
  • Additional number to left of octal’s standard three digits
  • SUID: 4
  • SGID: 2
  • Sticky bit: 1
  • Example: chmod 6750 configFile.txt
60
Q

How do you set special permissions in Symbolic Mode?

A
  • Execute permissions needed
  • SUID: chmod u+s file-name
  • SGID: chmod g+s file-name
  • Sticky bit: chmod o+t directory-name
61
Q

What are the default file and folder permissions when they are created?

A
  • Default file permissions when created:
  • 0666 (octal)
  • rw-rw-rw-
  • Default directory permissions when created:
  • 0777 (octal)
  • rwxrwxrwx
62
Q

How do you view the default creation mask?

A

umask

63
Q

What command is used to create a hard link?

A

ln file1.txt filehardlink

64
Q

What command is used to create a soft link?

A

ln -s file1.txt filesoftlink

65
Q

What command shows information about current running processes?

A

ps

Information Shown:

  • PID: process ID
  • TTY: terminal associated with process
  • TIME: total CPU time consumed by process
  • CMD: name of program running
66
Q

What command lets you search for processes on the system?

A

pgrep

67
Q

Command to continuously monitor system and process information

A

top

68
Q

Command to view uptime, number of users on system, CPU load averages

A

uptime

69
Q

Command to view memory statistics

A

free

(free -h provides a more readable format, using GB, MB, etc)

70
Q

What are 2 common multiplexer utilities for the terminal window?

A

GNU Screen:

Command: screen

Screen information: screen -ls OR Ctrl+A, w

tmux:

Command: tmux new

Screen information: tmux ls

71
Q

Command to stop a running job

A

Ctrl + Z

72
Q

Command to move a stopped job to the background

A

bg [job#]

73
Q

Command to move a background job to the foreground

A

fg [job#]

74
Q

Command to view background jobs, their job number, and status:

A

jobs

(jobs -l also shows PID)

75
Q

Command to send a job to the background from the time it is started

A

[command to run]&

76
Q

Command to see all available signals in “standard signals” section of signal man page:

A

man -s 7 signal

77
Q

Signal to terminate process, when user logs out:

A

1, HUP, or SIGHUP

Syntax:

kill -s SIGHUP [PID] OR

kill -s HUP [PID] OR

kill -1 [PID]

78
Q

Signal to unconditionally kill a process:

A

9, KILL, or SIGKILL

Syntax:

kill -s SIGKILL [PID] OR

kill -s KILL [PID] OR

kill -9 [PID]

79
Q

Signal to terminate a process immediately, if possible:

A

(This is the default signal) 15, TERM, or SIGTERM

Syntax:

kill -s SIGTERM [PID] OR

kill -s TERM [PID] OR

kill -15 [PID] OR

kill [PID]

80
Q

Command used to kill a background job or process

A

Adding % before the job ID

Syntax:

kill %[jobID]

kill -15 %[jobID]

81
Q

Command used to set nice value prior to execution

A

nice -n [value -20 to 19] [command]

Exam Note: can remove -n from syntax as follows

Positive Nice Value: nice -[value from 0-19] [command]

Negative Nice Value: nice -[value including ‘-‘ from -20 to -1] [command]

82
Q

Command used to set nice values after process is already executed

A

renice

Syntax:

renice +15 [PID] OR

when running top, press r

83
Q

Identify the following environment variable for:

Current username

A

USER and LOGNAME

Example Syntax: echo $USER OR echo $LOGNAME

84
Q

Identify the following environment variable for:

Command-line prompt

A

PS1

Example Syntax: echo $PS1

85
Q

Identify the following environment variable for:

Present working directory

A

PWD

Example Syntax: echo $PWD

86
Q

Identify the following environment variable for:

Default Text Editor

A

EDITOR and VISUAL

Example Syntax: echo $EDITOR OR echo $VISUAL

87
Q

Identify the following environment variable for:

User’s home directory

A

HOME

Example Syntax: echo $HOME

88
Q

Identify the following environment variable for:

the Absolute directory reference of Bash shell

A

BASH

Example Syntax: echo $BASH

89
Q

Commands to see all environment variables on system:

A

env

printenv

set

90
Q

Command to view current subshell level:

A

echo $SHLVL

91
Q

Command for surviving a subshell:

A

Three Methods:

  1. variable=setting
    export variable
  2. export variable=setting
  3. variable=setting; export variable
92
Q

LVM command to designate a partition as a physical volume

A

pvcreate

93
Q

LVM command to create a volume group of physical volumes

A

vgcreate

94
Q

LVM command to add a physical volume(s) to a volume group

A

vgextend

95
Q

LVM command to create a logical volume

A

lvcreate

96
Q

Command to see all available LVM commands

A

lvm –help

97
Q

Command to display information concerning PCI busses and their connections

A

lspci

  • t flag displays information in a tree format
  • v, -vv, -vvv flag for verbose mode
98
Q

Displays information concerning USP connected devices

A

lsusb

99
Q

Command to view all the modules inserted into the Linux kernel

A

lsmod

100
Q

What command allows you to insert and remove modules and its dependents into the Linux kernel?

A

modprobe [module name]

modprobe -r [module name]

101
Q

How would you check to see if a particular file system is supported on the Linux kernel you’re using?

A

cat /proc/filesystems

102
Q

Commands for making a file system

A

mkfs -t [filesystem] [partition]

OR

mkfs.[filesystem] [partition]

OR TO FORMAT AS SWAP

mkswap [partition]

103
Q

Command to view filesystems currently used on disk partitions

A

lsblk -f

104
Q

Command to manually mount a filesystem

A

mount -t [filesystem-type] [filesystem] [mount-point]

to unmount:

umount [mount-point]

OR

umount [filesystem]

105
Q

What configuration file contains filesystem records?

A

/etc/fstab

Identifies filesystems by:

filesystem, mount point, type, options, dump, pass

106
Q

Command to view overall use of disk space

A

df

df -h
(more human friendly)

df -i
(view overall inode use)

107
Q

Command to show space use of files and directory summary

A

du [directory name]

du -s [directory name]
(space use directory summary)

du -i [directory name]
(view inode use)

108
Q

Command used to make/format an ext2 file system

(can also be used for ext3 and ext4 using the -t flag)

A

mke2fs

109
Q
  • Used to change parameters (tune) an ext2/ext3/ext4 filesystem after formatting
  • Best to unmount a filesystem before tuning, but not always required
  • Not all parameters can be modified post-formatting
  • See man tune2fs for utility details, and parameters that can be modified
A

tune2fs

110
Q

Commands used to tune xfs file system:

A
  • For XFS filesystems:
  • Improve the arrangement of the filesystem: xfs_fsr
  • Tune filesystem parameters: xfs_admin
111
Q

Commands used to tune btrfs filesystems:

A
  • For btrfs filesystems:
  • Improve the arrangement of filesystem data: btrfs balance
  • Tune filesystem parameters: btrfstune
112
Q
  • Used to check/repair an unmounted ext2, ext3, or ext4 filesystem
  • Use the -r option to produce a report
  • Some status codes:
  • 0 = No errors
  • 1 = Errors corrected
  • 4 = Uncorrected errors
A

fsck

113
Q

Commands used to check and repair xfs file systems:

A
  • For XFS filesystems:
  • Check and repair filesystem: xfs_repair
  • Only check filesystem: xfs_db or xfs_repair -n
114
Q

Commands used to check and repair btrfs file systems:

A
  • For btrfs filesystems:
  • Check and repair filesystem: btrfs check
  • Check and repair filesystem (deprecated): btrfsck
115
Q

What command is used to view kernel messages in the kernel ring buffer?

A

dmesg

(no super user privileges needed)

116
Q

What command is used to view kernel messages in systemd journal file?

A

journalctl -k OR

journalctl –dmesg

(super user privileges required)

117
Q

Configuration file that contains the default runlevel:

A

/etc/inittab

118
Q

Command to view past or current system runlevels:

A

runlevel

119
Q

Commands to switch runlevels:

A

init [runlevel-number]

telinit [runlevel-number]

120
Q

Command to view default target on a machine using systemd

A

systemctl get-default

121
Q

Command to change default target using systemd

A

sudo systemctl set-default [new target]

122
Q

Command to check the status of a service

A

systemctl status [service name]

123
Q

Command to jump to a systemd target

A

sudo systemctl isolate [target name]

124
Q

Command to send a message to other users logged onto the system using TTY terminals

A

wall