Linux Shell Cheatsheet Flashcards

1
Q
  1. General: Unix file layout
A

the tree-like logical system layout that organizes and stores all files under directories. at the top of the system is the root, represented with /.

/bin/cp
/bin/is
/bin/pwd
/home/daniel/bin
/home/daniel/profile
etc
https://media.geeksforgeeks.org/wp-content/uploads/20221206120522/noname.png

tree

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. General: * UTF
A

Unicode Transformation Format.
UTF-8: 9bit unicode conversion format.
UTF 65 = A
UTF 66 = B
etc

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Install: sudo
A

super user do
gives admin/root access rights, applies root access to commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. Install: apt-get
A

command line tool for interacting with Advanced Package Tool (APT) Library. (package management system for Linux distributions)

allows you to search, install, manage, update and remove software.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. Install: install
A

copies files and sets file permissions.
install text.txt /target_directory
install -m 700 text.txt new_directory
(copies to new directory with rwx— permissions)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. Processes: jobs
A

process managed by shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. Processes: ^Z/^C
A

^C kills current process,
^Z pauses the process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. Processes: bg/fg
A

fg continues process from the background,
bg continues process in background

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Processes: &
A

sends the command to the background

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Processes: kill
A

kills a process. can also kill [ID] to target which process to kill

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. Processes: killall
A

kills all processes in the background
killall sleep // kills all sleeps in the backgground

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Processes: wait
A

wait() system call suspends execution of the calling thread until one of its children terminates.

or, waits for the completion of any running processes. if multiple processes are running, only uses the last known command’s process id.
wait PID // waits until PID process finishes

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

3.1: Processes: %n

A

brings the job at position n to the foreground

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

3.1: Processes: ps

A

abbreviates ‘process status’.

ises to list currently running processes and their PIDs along with other info

lists PIDs and

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

3.1: Processes: nice

A

lowers a process’s priority

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

3.1. Processes: time

A

checks how long a process takes to complete

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

3.1: Processes: htop

A

nicer view compared to top. shows active processes, the PIDs, and other info

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

3.1: Processes: top

A

shows active processes, their PIDs and other info. but not as pretty as htop.

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

3.1: Processes: watch

A

reruns commands in a loop until stopped manually, or runs into a condition that stops the loop.

helps monitor something until it changes.

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

3.2: Processes: /proc

A

pseudo-filesystem, provides an interface to kernel data structures. mostly read-only.

displays kernel/system state, but read-only

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

3.2: Processes: suspend

A

uh, CTRL+Z?
can be continued with bg or fg

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

3.2: Processes: Notify-Send

A

sends notifications, alternative to windows pop-ups.

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

3.2: Processes: * batch

A

telling the system to execute commands from a list or queue.

can be made to run at late night or early morning to free the system for interactive.

can also set batch process priority to when CPU is not busy. nice.

use queuedefs fo;e tp describe queues managed by cron daemon. letters between a and y define queue name. tasks started by the at command placed in default queue for a. batch-started commands are placed in b queue. c is for tasks from the crontab file.

batch command will execute commands from standard input or a specified fille when the system load levels drop to a specific point.

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

3.2: Processes: * at

A

creates a list of commands to be excecuted at a specified time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
3.2: Processes: * atq
displays listed jobs to be executed
26
3.2: Processes: * crontab
chron table. lists jobs under cron command. cron meaning the jobs will be executed automatically according to a set schedule
27
3.2: Processes: * ^Q/^S
^S - stops all output to the terminal(program will keep running) which can be restarted with ^q ^q - releases (displays) terminal output which has been paused with q.
28
4. History: history n
outputs previous n commands to terminal
29
4. !!
*inputs* the previous terminal input
30
s/old/new
replaces found instance of old with new
31
4. !-2
displays the 2nd previous command, and inputs it to the terminal
32
4. !!:p
*displays* the previous terminal input
33
5. Wild Cards & WS: *
* represents any number of characters (even 0 characters). h*t = hat, hot, hoot, hlnjasjdnaisjnt
34
5. Wild Cards & WS: ?
? represents any single character. h?t = hat, hot, hit, but not hoot.
35
5. Wild Cards & WS: |chroot
creates a new root directory chroot [options] /path/to/new/root /path/to/server mkdir $HOME/jail //creates jail mkdir -p $HOME/jail/{bin, lib64} //create directories in jailus cd $HOME/jail cp -v /bin/{bash, ls} $HOME/jail/bin //copy /bash and /ls to fake home directory ldd /bin/bash //print shared libraries cp -v [whatever the displayed libraries are] $HOME/jail/lib64 sudo chroot $HOME/jail /bin/bash// user now treats /jail as root directory.
36
5. Wild Cards & WS: " "
preserves literal values except for $, `, ", \, and !. \ only has speacial meaning whewn followed by $, `, " \ or a newline character. also guves * and @ meaning if introduces as $@ (passing specified parameters seperately)) or $* (passing all parameters as a single parameter).
37
5. Wild Cards & WS: ' '
preserves the literal value of each character within the quotes. echo !! echo '!!'
38
5. Wild Cards & WS: [A-Z]
specifies a range. m[a,o,u]m becomes man, mom and mum. m[a-d]m will include mam, mbm, mcm and mdm.
39
5. Wild Cards & WS: {A..Z}
specifies a range seperated by commas. m{a,o,u}m becomes man, mom and mum. {*.doc, *.pdf} will include bob.doc, sam.doc, word.pdf, what.pdf
40
6. FS/*: mount
mount -t TYPE DEVICE DIR attaches the file system found on some device to the file tree/file hierarchy of the unix system
41
6. FS/*: umount
umount {directory|device} removes the file system found on some device form the file tree/hierarchy of the unix system
42
6. FS/*: {un}compress
sudo install ncompress
43
6. FS/*: df
reports file system disk usage
44
6. FS/*: du
estimates file space usage
45
6. FS/*: sync; sync
synchronizes cached writes to persistent storage sync;sync
46
6. FS/*: swapon
specifies devices on which paging and swapping are to take place. swapon [options] [specialfile] mount/unmount devices as swap files
47
6. FS/*: swapoff
disables swapping on the specified devices and files. -a flag disables swapping on all known swap devices and files (form /proc/swaps, or /etc/fstab)
48
inode, table
each file has an inode containing metadata about the file. apps can retrieve the metadata using stat inode table (df -i) contains all the inodes and is created when file system is created
49
6. FS/*: linux file types
Linux supports 7 different file types: Regular file, various data; text, script, image, video, etc. Directory file, name and address of other files Link file, point or mirror other files Character special file, represents device files, like hard drives annd monitors Block special file, represents device files, like hard drives annd monitors Socket file, provides inter-process communication and Named pip file. allows processes to send data to other processes or recieve data from other processes
50
7. Compression/*: tar
tar cfz bigfile.tgz bigfile compress tar xf bigfile.tgz decompress tar balls. generally used to pull files together for easy transport into another system or backup as a group. compression is a bonus feature by adding z to cfz
51
7. Compression/*: dd
boot into rescue mode, create mount point for external drive: mkdir /mnt/external mount /dev/sdb1 /mnt/external create compressed disk image: dd if=/dev/sda | gzip -9 > /mnt/external/filename.img.gz copies data block by block future recovery: zcat /mnt/externak/filename.img.gz | dd if=/dev/sda
52
7. Compression/*: g{un}zip
replace original file with encrypted file gzip bigfile gunzip bigfile.gz
53
7. Compression/*: {un}zip
creates compressed file and leaves original intact. zip ./bigfile.zip unzip bigfile.zip
54
7. Compression/*: zcat
identical to gunzip -c; standard output, keepigng original file unchanged.
55
7. Compression/*: zgrep
invokes grep on compressed or gzipped files. zgreo [grep_options] [-e] pattern filename
56
7. Compression/*: zless
filter for crt viewing of compressed text. crt; certificate and private key files. public-key certificate following x. 509 standard, containind info in the server identy, name, geolocation and public key. deep dives into the files
57
7. Compression/*: zmore
file perusal filter for crt viewing of compressed text.
58
8. Data Streams: cat
cat [OPTION] [FILE] concatenate files and print them on the standard output cat bill.txt
59
8. Data Streams: cmp
compares two files, byte by byte cmp bill.txt bob.txt differe on byte 171, line 1
60
8. Data Streams: cut
remove selections from each line of files cut -c 1-7 bill.txt // outputs first to 7th character, 1- //first character to end, -40 up to 40th character
61
8. Data Streams: diff
compare files line by line diff bob.txt bill.txt
62
8. Data Streams: diff3
compare 3 files line by line
63
8. Data Streams: more
more [options] file paging through the text, one screenful at a time
64
8. Data Streams: less
opposite of more. paging through a text, all at once.
65
8.1. Data Streams: sort
sort lines of text files. sort [OPTION]... [FILE]... write sorted concatenation of all files to standard outpit
66
8.1. Data Streams: head
outputs the first part of files (1st 10 lines of each file)
67
8.1. Data Streams: tail
outputs the last part of files (last 10 lines)
68
8.1. Data Streams: tr
translate or delete characters. works like substituting one patter for another
69
8.1. Data Streams: uniq
report or omit repeated lines uniq [OPTION]... [INPUT [OUTPUT]]
70
8.1. Data Streams: wc
print newline, word and byte counts for each file
71
8.1. Data Streams: grep
print lines that match patterns grep o bob.txt
72
8.2. Data Streams: find
search for files in a directory hierarchy
73
8.2. Data Streams: hd
hexdump. displays file contents in hexadecimal, decimal octal or ascii.
74
8.2. Data Streams: rev
rev bob.txt 'reverse line characterwise'. outputs the file but reverses all the characters.
75
8.2. Data Streams: locate
doesn't search the entire file system like file. looks through regularly update file database (index) in the system, ergo faster. sudo apt update sudo apt install mlocate locate bob.txt
75
gcp
advanced command line copier gcp [OPTIONS] FILE DEST acts like cp (copy) but with high level functionality (shows cp progress, skips problem files, logs which files copy succesfuly, remove incompatible chars like /. or * on VFAT),) and more
76
9. Shell: man
interface for displaying reference manuals
77
9. Shell: man -k
searches the short descriptions and manual page names for the given keyword as regular expresson. prints out matches. works like apropos
78
9. Shell: history
GNU history library keeps track of lines input by the user. try history for giggles
79
9. Shell:
CTRL+v+tab tab autocompletes input
80
9. Shell: bash
GNU Bourne-Again SHell sh-compatible language interpreter, executes commands read from an input .sh filew
81
9. Shell: env
runs a program in a modified environment env [OPTIONS]... - [NAME=VALUE]... [COMMAND [ARG]...]
82
9. Shell: echo
echo xyz displays a line of text
83
9.1 Shell: alias/unalias
alias rt~='rm -r *~' unalias rt~='rm -r *~'
84
9.1 Shell: true/false
true does nothing, succesfuly. false does nothing, unsuccessfuly.
85
9.1 Shell: sleep
delays for a specified amount of time. sleep 100 // sleep for 100 seconds
86
9.1 Shell: which
locates a command (which file it belongs to)
87
9.1 Shell: #!/bin/bash
"shabang". inscructs the program loader to use the /bin/sh program instead of any other, passing the oath of the script as the first argument.
88
9.1 Shell: if [] then else fi
if [COMMAND] then: RUN IF COMMAND IS TRUE else: RUN IF COMMAND IS FALSE fi: finish
89
9.1 Shell: do while
while [COMMAND] do: WHILE COMMAND IS TRUE done: IF COMMAND IS FALSE.
90
9.2 Shell: ulimit
get and set user limits. obsolite routine. but in shell: displays or sets shell resource limits. ulimit // reports the soft limit on file size. ulimit -H // reports hard limit on file size. ulimit -u 8000 // set soft limit on number of user processes to 8000
91
9.2 Shell: /dev/tty
controlling terminal for the current process. ps -a // to find out which ttys are attatched to which process.
92
9.2 Shell: set
allows you to change the values of shell options and set the positional parameters, or display the names and values of shell variables. https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
93
9.2 Shell: $?
ls duck echo $? $? is the return value of the last executed command. 0 if succesful, 2 if not. or anything other than 0, depending on the progra,. last process's exit status
94
9.2 Shell: for i in [] do done
for VARIABLE In 1 2 3 4 5 .. N do command1 command2 command 3 done for VARIABLE in file1 file2 file3 do command1 command2 command3 done for OUTPUT in $(cmd) do command1 on $OUTPUT command2 on $OUTPUT commandN done
95
9.2 Shell: apropos
searches the short descriptions and manual page names for the given keyword as regular expresson. prints out matches. works man -k. search manual's short descriptions
96
9.2 Shell: * bind -p
bind command is for viewing and modifying readline keybindings. -p will display both the keybindings and the corresponding function names.
97
10. Login & System: su
run command iwth substitute user and group ID run su [options] [-] [user [arguments...]]
98
10. Login & System: reboot
reboots the machine. returns 0 on success, non-zero failiure otherwise.
99
10. Login & System: shutdown
shutdown [OPTIONS] [TIME] [WALL...] -H halts the machine -P poweroffs -r reboot
100
10. Login & System: users
print the user names of users currently logged in to the current host
101
10. Login & System: clear
clears the terminals screen
102
10. Login & System: hostname
show or set the system'sdisplays the system's DNS name host name
103
10. Login & System: ifconfig
configure a network interface with no additional commands, displays the status of the currently active interfaces.
104
10.1 Login & System: exit
causes normal process termination
105
10.1 Login & System: date
prints or sets the system date and time
106
10.1 Login & System: w
show who is logged on and what they are doing gives users, with more info (users)
107
10.1 Login & System: whoami
prints effective userid
108
10.1 Login & System: lshw
lists hardware. run with sudo, something might be missing.
109
10.1 Login & System: last reboot
shows a listing of last logged in users
110
10.1 Login & System: ssh -X/rsh/telnet
opens remote login client. -X enables X11 forwarding. enable with caution: users bypassing remote host file permissions can perform attacks like keystroke monitoring. use -x to disable x11 forwarding.
111
10.2 Login & System: ~^Z
stops the current process and sends it to the background
112
10.2 Login & System: * xterm
terminal emulator for the X window system.
113
10.2 Login & System: * scp
openSSH secure file copy. copies files between hosts on a network
114
10.2 Login & System: * uptime
tells how long the system has been running
115
10.2 Login & System: * xload
displays a constantly updating histogram of the system load average
116
10.2 Login & System: * wall
writes a message to all users
117
10.2 Login & System: * write
send a message to another user write daniel tty
118
10.2 Login & System: * netstat
prints network connections, routing tables, interface statistics, masquerade connections, and multicast memberships
119
10.2 Login & System: * free
display amount of free and used memory in the system
120
11. Files: pwd
print name of current working directory
121
11. Files: ls
list directory contents
122
11. Files: lsof
list open files
123
11. Files: cp
copy files and directories
124
11. Files: mv
move (rename) files
125
11. Files: rm
remove files or directories
126
11. Files: mkdir
make directories
127
11.1 Files: rmdir
remove empty directories
128
11.1 Files: cd
change current directory
129
11.1 Files: ln
make links between files. lan [OPTIONS]... TARGET... DIRECTORY... -P physical, creates a hard link. (hard link is its own file, soft link just points to the name of the original file)
130
11.1 Files: touch
creates the file if it doesn't exist, updates the access and mod times of each FILE to the current time, -c flag will not create any file,
131
11.1 Files: ftp
ftp host [port] functions like open host [port]
132
11.1 Files: ~
shortcut for user's home directory
133
11.1 Files: .
current directory
134
11.2 Files: ..
directory immediately above the current one
135
11.2 Files: .bashrc
script file that's executed when a user logs in
136
11.2 Files: .profile
present in your $HOME directory, overrides /etc/profile file to customize individual working environment.
137
11.2 Files: pushd
pushd [OPTIONS] [DIRECTORY] pushd /home // push the current directory to the top of the directory stack and change to /home popd will pop the top directory from the stack and move 'down' the stack.
138
11.2 Files: popd
pushd [OPTIONS] [DIRECTORY] pushd /home // push the current directory to the top of the directory stack and change to /home popd will pop the top directory from the stack and move 'down' the stack.
139
11.2 Files: source
reads and executes the file content in the current shell. (can type set of commands into a text.txt and use source to run all the commands) source cmdlist.txt
140
11.2 Files: * readlink
print resolved symbolic links or canonical file names, path links and buffer
141
11.2 Files: * tree
list contents of directories in a tree-like format
142
12. I/O Redirection: stdin
extern FILE *stdin; standard input
143
12. I/O Redirection: stdout
extern FILE *stdout; standard output 1
144
12. I/O Redirection: sterr
extern FILE *stderr; standard error 2
145
12. I/O Redirection: <
read the command's input from a file instead of from the keyboard sort < data.txt overwrite stdin
146
12. I/O Redirection: >
sends input (from terminal?)to output file cat bill.txt > bob.txt overwrite stdout
147
12. I/O Redirection: 2>
2 denotes standard error, > output, therefore 2> outputs the standard error overwrite stderr
148
12. I/O Redirection: &>
redirect standard output write over stdout AND stderr
149
12. I/O Redirection: <<
append stdin
150
12. I/O Redirection: >>
append stdout
151
12. I/O Redirection: 2>&1
stdout and stderr
152
12. I/O Redirection: /dev/null
vacuuuuuuum go vuuuuum
153
12. I/O Redirection: tee
named after and functions like a T-pipe. wc -l text1.txt|tee -a text2.txt outputs the bit count of text1.txt to console, but also appends it to text2.txt (-a flag appends. removing the -a flag will overwrite the contents of text2.txt)
154
12. I/O Redirection: script
makes typescript of terminal session. script [options] [file]
155
12. I/O Redirection: cmd - command substitution
allows the output of a command to replace the command itself. $(command) `command` for example: $(cat file) whatever was written in that file becomes the command
156
12. I/O Redirection: ^D
logs you out of any terminal and closes it, or gets to back to the original user before using su or sudo.
157
13. Compilation/*: {g}cc/g++
g++: GNU C and C++ compiler. compiles .c and .cpp files. gcc: GNU C compiler. compiles .c files g++ is an alias for including c++ files
158
13. Compilation/*: gcc/g++ -g
g++: GNU C and C++ compiler. compiles .c and .cpp files. gcc: GNU C compiler. compiles .c files -g flag generates debug info to be used by GDB debugger. tells gcc to generate source-level debugging/symbol info within the executeable itself. IF the program crashes and produces a core file, is killed, or a program calls a function that dumps its core
159
13. Compilation/*: ld
GNU linker. ld [OPTION] objfile. combines object/archive files, relocates their data and ties up symbol differences last step in compiling a program is to run ld, usually converts multiple linked files into a single .a/out
160
13. Compilation/*: nm
list symbols from object files
161
13. Compilation/*: ar
create, modify and extract from archives. archive: single file holding collection of other files ina structure that that makes it possible to find/retrieve the original files/'members' runes compiler and finds the issues
162
13. Compilation/*: gdb
GNU debugger. interface for seeing what happens 'inside' a program as it executes, or what another program was doing as it crashed.
163
13. Compilation/*: make
GNU make [OPTION]... [TARGET] GNU make utility to maintain groups of programs auto-detects what pieces of a large program need to be recompiled, and issues commands to recompile them.
164
13. Compilation/*: valgrind
tool for debugging, finding memory leaks, detection and profiling
165
13. Compilation/*: splint
Secure Program Lint programming tool for statically checking C programs for security vulnerabilities and coding mistakes. automatically finds and points out vulnerabilities and mistakes in C programs
166
13. Compilation/*: core file
generated when a program terminates unexpectedly, helps determine what caused the termination.
167
13. Compilation/*: gprof
display call graph profile data
168
14. Permissions: chmod
change file mode bits changes file moded bits of each given file,
169
14. Permissions: chown
change file owner and group chown [OPTION] [OWNER] FILE chown [OPTION] [OWNER][:[GROUP]] FILE
170
14. Permissions: chgrp
change group ownership chgrp [OPTION]... GROUP FILE
171
14. Permissions: mask
manipulate nmh message sequences change spe
172
14. Permissions: unmask
user file creation mode mask set file mode creation mask set default
173
14. Permissions: setuid
set user identity
174
15. Information tools: espdiff
apply the appropriate transformation to a set of patches
175
15. Information tools: fortune
displays a fortune
176
cosway
cow goes moo
177
16. User Montor: xeyes
googly eyes