COMMANDdate
displays current date and time
COMMANDman
displays offline manual page for commandman [COMMAND]
COMMANDls
lists files and directoriesls [OPTION] ... [PATHNAME]
OPTIONS (ls)-l-a-d-i
-l: long-listing-a: all files/dir (hidden asw)-d: directories (no files)-i: inode number
COMMANDrm
removes files (permanently)rm [OPTION]... [PATHNAME]
OPTIONS (rm)-r
removes directories and all the files in them
COMMANDless
displays content one screen at a timeless [PATHNAME]
COMMANDcat
displays content in input. reads a text file(will contcatenate multiple pathnames)cat [PATHNAME]
COMMANDtouch
creates empy file if one doesn't exist.changes access/modification times of a file that does exist.touch [PATHNAME]
COMMANDwc
counts lines, words and bytes in input (hello world -> 1 2 12)wc [PATHNAME]
COMMANDsort
sorts provided input (alphabetically)sort [PATHNAME]
COMMANDecho
displays text on screenecho [STRING]
OPERATOR>
redirects output from commanddoes right side firstecho bye >hello.txt(bye)makes hello.txt first, then echos bye into it
OPERATOR>>
redirects and also appendsecho hello >hello.txtecho bye >>hello.txt(hellobye)
COMMANDmore
displays content one screen at a time, like less but cannot go upwardsmore [FILE]
COMMANDhead
displays first X lines of inputX=10 if not specifiedhead -3 myfile.txt (first 3 lines)head myfile.txt (first 10 lines)
COMMANDtail
displays last X linkes of inputX=10 if not specifiedtail -3 myfile.txt (first 3 lines)head myfile.txt (first 10 lines)
COMMANDcutwhat are the options?
displays fields seperated by delimiters-d : delimiter-f : field number (#,# or #-#)cut -d , -f 3(shows third field seperated by comma)cut [OPTION]... [FILE]...
history
lists history of commands
COMMAND!N
runs command number N from history
COMMAND!!
Runs previous command
COMMANDpwd
prints current working directory
COMMANDcd
changes current working directory
COMMANDmkdirwhat options?
creates empty directory-p : parent directoriesmkdir -p a/bmakes a w b inside
COMMANDrmdirwhat options?
removes empty directories-p: parent directories
COMMANDtree
visually displays directory tree
OPERATOR| (pipe)
redirects standard output from one command as input to another commanddoes right side to left sideecho hello | wc(1 1 6)
COMMAND2>
redirects only the error output of a command
COMMAND2>&11>&2
merge output of one channel into the other
;
runs multiple separate commands at the same command lineecho hello>hello.txt ; echo bye(bye)
COMMANDfgrep
output lines from input that match the pattern.
GLOB PATTERNS?*[]^!${}|
?: match any single char*: match 0 or more char[]: match char from range^: idk highlights them?!: same thing$: define end char (a$) ends in a{}: use multiple glob patterns|: multiple conditions 1 glob pat
COMMANDpaste
merges lines from multiple filesso like, line 1 gets added to line 1 of another file and so on...cat 1.txtonetwocat 2.txtthreefourpaste cat1.txt cat2.txtone threetwo four
COMMANDcp
copies source into destinationcp [OPTION] .. SOURCE.. DEST..
COMMANDmv
moves/renames source into destinationmove if file exists, renames if doesn'tmv SOURCE... DEST...
COMMANDfind
recursively searches for files/directoriesfind / -name lsfinds files or dirs named lsfind [STARTING POINT]... [EXPR]...
COMMANDlocate
search for names in a previously indexed databaselocate 1.txt(/home/student/1.txt)
COMMANDstat
lists info found in inode
COMMANDdftwo options
shows free/used disk space-i shows inodes-hhuman readable
COMMANDlnthere's one option too
creates hard link to the destination pathname-screates soft linkln TARGET [PATHNAME[
COMMANDid
shows current userID and groupIDs with their numerical values
COMMANDwhoami
shows current userID
COMMANDgroups
shows current user's groups
COMMAND chmod
changes file or directory's permissionschmod [MODE] [PATHNAME] ..
PERMISSIONSwhat are each number u know
0: no permission (-)1: execute (--x)2: write (-w-)3: execute/write (-wx)4: read (r--)5: read/execute (r-x)6: read/write (rw-)7: read/write/execute (rwx)
rwxrwxrwxwhat is the order whos permissions
user | group | others
umask
masks away certain permissions, only from newly created files/directoriesopposite of normal permissions... sort of
OPERATOR<
redirects input into commandcat < file.txtjust cats file.txt idk
COMMANDfreeone important option
shows memory availability information for physical and virtual memory-hhuman readable formatfree [OPTION] ...
COMMANDfdisk
view/create partition table or partitions on devicesshows a lil menu, changes need to be written before exiting or nothing happensfdisk [OPTION] ... [DEVICE]
COMMANDmkfsone option
creates file systems on partitions to be able to store files/dirs-tset filesystem type (ext4) (vfat)mkfs [OPTIONS]... DEVICE
COMMANDmount
associate device with a path on our filesystem, to be able to access the files/directories in it. without args, lists all mounted partitionsmount /dev/sdd4 /mnt/mydir
COMMANDumount
unmounts a mounted partition. writes all changes to disk
COMMAND mkswap
sets partition to be used as a swap (virtual memory)
COMMANDswapon
shows info about devices used for virtual memory, or enable/add new devices to the virtual memory
COMMANDswapoff
stops using a device for virtual memory. if device is being used, command will return when it's free
/etc/passwd
colon separated database file used for keeping info on users. this orderusername, UID, GID, Comment (full name), home dir, path to shell
/etc/shadow
colon separated database file used for keeping password information, expiry to each user.any access to shadow file is restricted, except administrators
COMMANDgroupadd
adds new group accountgroupadd [OPTION]... GROUPNAME
COMMANDgroupmod
modifies existing group
COMMANDgroupdel
deletes existing group
COMMANDuseradda bunch of options to probably remember
adds new user account.-c: comment (full name)-d: home-dir-m: creates home dir if doesnt exist-g: groupname-e: expiry date-s: Shell_Path: set to /bin/bash for new users$ sudo useradd -c "Jonathan Blow" -d /home/jblow -m -g jblow -e 2023-01-01 -s /bin/bash jblow
COMMANDusermod
modifies existing user accountsimilar options to useradd-c: comment (full name)-d: home-dir-m: creates home dir if doesnt exist-g: groupname-e: expiry date-s: Shell_Path: set to /bin/bash for new users
COMMANDuserdelone option
deletes existing user-r: deletes home directory which isn't done to keep company's info even when user is removed
COMMANDpasswd
changes user's password
COMMANDsu
switch user
COMMANDalias
lists all currently set aliases
COMMANDalias [name]=[replacement text]
sets new alias
COMMANDunalias [alias name]
removes alias
COMMANDenv
displays environment variables.
ENVIRONMENT VARIABLE$PATH
displays the contents of PATH.. which is also the stdout
COMMANDexport -f
exports a function so we can all use it
how does an if statement look
if [[ conditional expression ]]then statementselif [[ conditional expression ]]then statementselse statemetnsfi
Conditional Expression?
expression that returns a boolean
What are the comparison operators for BASH?
-ne: not equal-eq: equal-lt: less than-le: less than equal to-gt: greater than-ge: greater than equal to
String Operators?
[[ -z string ]] - is string empty[[ -n string ]] - is string not empty[[ string == string ]] - equality[[ string != string ]] - inequality
File Operators?
[[ -e file ]] - does file exist[[ -r file ]] - is file readable[[ -d file ]] - is file a dir[[ -w file ]] - is file writable[[ -x file ]] - is file executable[[ -f file ]] - is it a file[[ file -nt file ]] - newer than[[ file -ot file ]] - older than[[ file -ef file ]] - same
What are the different command line parameters? ($)
$# - number of params$* - all params as single string$@ - all params as separate strings$0 - returns command$1-9 - returns first 0 paramsshift # - shifts position of $1-9
how should variables look?
idk like ${name} and not like $namethis isn't truesortof
what does a case statement look like
case ${choice::1} inQ) echo "woop"P) echo "ahfahlfh"Z) echo AHHHH*) echo SLDKALesac
C Style Loop
for (( i=0; i<4; i++)dodone
Data Iteration for loop
for line in $(ls)
Range iteration for loop
for i in {a..g}
Traditional while loop
ls | whlie read line
COMMANDreadand its default location
reads input from stdin stream and puts t in a variable, or a set of variables. default location $REPLYread var1 var2 <<< "hello world"var1=hellovar2=world
${name}
expands as value of variable nameliteral string replacement
${name:0:1}
varname:position:length
${name::4}
first 4 chars of string name
${name: -2:2}
last two chars of value in name
${name/F/f}
all capital F chars turn into lowercase f chars
${name,,}
put name lowercase
${name^^}
puts name uppercase
how to declare array
declare -a my_array empty arrayormy_array=(red green yellow) creates and fills array
how to get an array element
echo ${my_array[2]}
how to show whole array2 ways
echo ${my_array[*]} expands to single stringecho ${my_array[@]} expands all elements but separate arguments
find size of array? (how many args)
echo ${#my_array[*]}
tput
makes things prettytput setab 7makes background white :otput boldothers