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
- 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
sed To Replace First Occurrence: sed 's/string/replacement-string/' To Replace All Occurrences: sed 's/string/replacement-string/g'
26
Simple Text Search Command
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
27
- Sends STDOUT to two different locations - Location 1: designated file - Location 2: STDOUT or STDIN to next pipeline command
tee
28
File Descriptor: 0
stdin
29
File Descriptor: 1
stdout
30
File Descriptor:2
stderr
31
What file is knows as the "black hole?"
/dev/null
32
Finds the following files for a command: - Binary - Source - Manual pages
whereis
33
Find a file by its name
locate
34
Manually update mlocate.db
updatedb
35
More configurable way to search for a file
find
36
Common 'find' search options
37
Determine a file's type with \_\_\_\_\_\_\_.
file
38
Update all the file's timestamps
touch [file]
39
Update only the modification timestamp
touch -m [file]
40
Update only the access timestamp
touch -a [file]
41
tar -c
Creates a tar archive by placing copies of the designated files in the designated archive. Also: tar --create
42
tar -u
Add files that were changed since an archive was created to pre-existing tar archive. Also: tar --update
43
tar -v
Displays a file's name as it is added to the archive. Also tar --verbose
44
tar -d
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
45
tar -t
Show the files in a tar archive file. Also: tar --list
46
tar -W
As a file is added or removed from the archive, verify it (not available when creating tarballs). Also: tar --verify
47
tar -x
Extract copies of the files from an archive file and places them in the current working directory. Also: tar --extract, tar --get
48
tar -O
Extract copies of the files from an archive file and send them to standard outpost (STDOUT). Also: tar --to-stdout
49
tar -v
Displays a file's name as it is copied from the archive. Also: tar --verbose
50
tar -j
Use bzip2 to compress/decompress archive file / tarball. Also: tar --bzip2
51
tar -J
Use xz to compress/decompress archive file / tarball. Also: tar --xz
52
tar -z
Use gzip to compress/decompress archive file / tarball. Also: tar --gzip
53
When using the ls command, what are the 5 file type codes associated with the output?
File (-) Directory (d) Symbolic Link (l) Block Device (b) Character Device (c)
54
What commands show your current group memberships?
1. groups 2. id -Gn
55
What command shows your current effective group?
id -gn | (id-Gn shows all group memberships)
56
What are the symbolic mode levels for the chmod command?
u - owner g - group o - others a - owner, group, and others (all)
57
What are the octal mode permissions for the chmod command?
0 - no permission 1 - execute permission 2 - write permission 4 - read permission
58
* Set on World level of permissions on a directory * Allows sharing of files in a directory * Only file's owner may delete file
Sticky Bit
59
How do you set special permissions in Octal Mode?
* 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
How do you set special permissions in Symbolic Mode?
* Execute permissions needed * SUID: chmod u+s file-name * SGID: chmod g+s file-name * Sticky bit: chmod o+t directory-name
61
What are the default file and folder permissions when they are created?
* Default file permissions when created: * 0666 (octal) * rw-rw-rw- * Default directory permissions when created: * 0777 (octal) * rwxrwxrwx
62
How do you view the default creation mask?
umask
63
What command is used to create a hard link?
ln file1.txt filehardlink
64
What command is used to create a soft link?
ln -s file1.txt filesoftlink
65
What command shows information about current running processes?
ps ## Footnote Information Shown: * PID: process ID * TTY: terminal associated with process * TIME: total CPU time consumed by process * CMD: name of program running
66
What command lets you search for processes on the system?
pgrep
67
Command to continuously monitor system and process information
top
68
Command to view uptime, number of users on system, CPU load averages
uptime
69
Command to view memory statistics
free (free -h provides a more readable format, using GB, MB, etc)
70
What are 2 common multiplexer utilities for the terminal window?
GNU Screen: Command: screen Screen information: screen -ls OR Ctrl+A, w tmux: Command: tmux new Screen information: tmux ls
71
Command to stop a running job
Ctrl + Z
72
Command to move a stopped job to the background
bg [job#]
73
Command to move a background job to the foreground
fg [job#]
74
Command to view background jobs, their job number, and status:
jobs | (jobs -l also shows PID)
75
Command to send a job to the background from the time it is started
[command to run]&
76
Command to see all available signals in "standard signals" section of signal man page:
man -s 7 signal
77
Signal to terminate process, when user logs out:
1, HUP, or SIGHUP **Syntax:** kill -s SIGHUP [PID] OR kill -s HUP [PID] OR kill -1 [PID]
78
Signal to unconditionally kill a process:
9, KILL, or SIGKILL **Syntax:** kill -s SIGKILL [PID] OR kill -s KILL [PID] OR kill -9 [PID]
79
Signal to terminate a process immediately, if possible:
(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
Command used to kill a background job or process
Adding % before the job ID **Syntax**: kill %[jobID] kill -15 %[jobID]
81
Command used to set nice value prior to execution
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
Command used to set nice values after process is already executed
renice **Syntax:** renice +15 [PID] OR when running top, press r
83
Identify the following environment variable for: Current username
USER and LOGNAME Example Syntax: echo $USER OR echo $LOGNAME
84
Identify the following environment variable for: Command-line prompt
PS1 Example Syntax: echo $PS1
85
Identify the following environment variable for: Present working directory
PWD Example Syntax: echo $PWD
86
Identify the following environment variable for: Default Text Editor
EDITOR and VISUAL Example Syntax: echo $EDITOR OR echo $VISUAL
87
Identify the following environment variable for: User's home directory
HOME Example Syntax: echo $HOME
88
Identify the following environment variable for: the Absolute directory reference of Bash shell
BASH Example Syntax: echo $BASH
89
Commands to see all environment variables on system:
env printenv set
90
Command to view current subshell level:
echo $SHLVL
91
Command for surviving a subshell:
Three Methods: ## Footnote 1. variable=setting export variable 2. export variable=setting 3. variable=setting; export variable
92
LVM command to designate a partition as a physical volume
pvcreate
93
LVM command to create a volume group of physical volumes
vgcreate
94
LVM command to add a physical volume(s) to a volume group
vgextend
95
LVM command to create a logical volume
lvcreate
96
Command to see all available LVM commands
lvm --help
97
Command to display information concerning PCI busses and their connections
lspci - t flag displays information in a tree format - v, -vv, -vvv flag for verbose mode
98
Displays information concerning USP connected devices
lsusb
99
Command to view all the modules inserted into the Linux kernel
lsmod
100
What command allows you to insert and remove modules and its dependents into the Linux kernel?
modprobe [module name] modprobe -r [module name]
101
How would you check to see if a particular file system is supported on the Linux kernel you're using?
cat /proc/filesystems
102
Commands for making a file system
mkfs -t [filesystem] [partition] OR mkfs.[filesystem] [partition] OR TO FORMAT AS SWAP mkswap [partition]
103
Command to view filesystems currently used on disk partitions
lsblk -f
104
Command to manually mount a filesystem
mount -t [filesystem-type] [filesystem] [mount-point] to unmount: umount [mount-point] OR umount [filesystem]
105
What configuration file contains filesystem records?
/etc/fstab Identifies filesystems by: filesystem, mount point, type, options, dump, pass
106
Command to view overall use of disk space
df df -h (more human friendly) df -i (view overall inode use)
107
Command to show space use of files and directory summary
du [directory name] du -s [directory name] (space use directory summary) du -i [directory name] (view inode use)
108
Command used to make/format an ext2 file system (can also be used for ext3 and ext4 using the -t flag)
mke2fs
109
* 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
tune2fs
110
Commands used to tune xfs file system:
* For XFS filesystems: * Improve the arrangement of the filesystem: xfs\_fsr * Tune filesystem parameters: xfs\_admin
111
Commands used to tune btrfs filesystems:
* For btrfs filesystems: * Improve the arrangement of filesystem data: btrfs balance * Tune filesystem parameters: btrfstune
112
* 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
fsck
113
Commands used to check and repair xfs file systems:
* For XFS filesystems: * Check and repair filesystem: xfs\_repair * Only check filesystem: xfs\_db or xfs\_repair -n
114
Commands used to check and repair btrfs file systems:
* For btrfs filesystems: * Check and repair filesystem: btrfs check * Check and repair filesystem (deprecated): btrfsck
115
What command is used to view kernel messages in the kernel ring buffer?
dmesg | (no super user privileges needed)
116
What command is used to view kernel messages in systemd journal file?
journalctl -k OR journalctl --dmesg (super user privileges required)
117
Configuration file that contains the default runlevel:
/etc/inittab
118
Command to view past or current system runlevels:
runlevel
119
Commands to switch runlevels:
init [runlevel-number] telinit [runlevel-number]
120
Command to view default target on a machine using systemd
systemctl get-default
121
Command to change default target using systemd
sudo systemctl set-default [new target]
122
Command to check the status of a service
systemctl status [service name]
123
Command to jump to a systemd target
sudo systemctl isolate [target name]
124
Command to send a message to other users logged onto the system using TTY terminals
wall