Bash Commands Flashcards
vim -r
list swap files
tail ‘file’
shows last 10 lines of the file
vim
open or creates file
mv ‘file1’ ‘file2’
move file to destination or rename file
cp ‘file1’ ‘file2’
copy contents from file1 to file2
rm ‘file’
remove a file
rm -r ‘file’
remove a file recursively
rm -d
remove empty directory
rm – -foo
rm file that starts with foo
find . -name ‘file1’ -type d
find the directory called file1. Without the -type d, it will search for files and directories
diff ‘file1’ ‘file2’
compares files and shows where they are different
sort -n -r ‘file’
sort files, -n for numeric sort and -r for reversing order
rev
reverse string character
chmod +wrx
reach, write and execute permissions
chmod -o -g -a -u
removes permission for others not in group, group, all users and user
lpr ‘filename’
prints the file
grep -i ‘hello’ ‘filename’
search for hello in filenames (this will not be case-sensitive)
grep -r ‘hello’ ‘directory
search recursively for pattern in the directory
sed ‘s/hello/goodbye/g’ ‘filename’
This will replace all occurrences of hello with goodbye in ‘filename’ without modifying the file
sed -i ‘s/dog/cat/g’ file.txt
replaces “dog” with “cat” in file.txt and saves the change
echo “this” | sed ‘s/is/at/g’
replaces “is” with “at” in the input string “this”
mkdir ‘filename’
makes a new directory
rmdir -rf
removes a non-empty directory
cp -r ‘dir1’ ‘dir2’
copy dir1 into dir2 including subdirectories
pwd
print working directory
cd ~
changes to home directory
whoami
returns your username
sudo command
execute command as the root user
lsof
lists all open files
varname=value
defines a variable
echo $varname
checks a variables value
read -p “Please enter your name: “ name
prompts the user for input with a specified message and stores the entered value in a variable
export -f ‘f1’
export function called f1
How do you define an array
array[0]=valA
How do you display the array’s value for a certain index
${array[i]}
what do you put at the beginning of your bash script
!/bin/bash
what are some arguments for chmod
–recursive - changes files and directories recursively
–changes - report when a change is made
–silent - suppress most error messages
what does apropos keyword mean?
Its when you don’t know the command name but roughly know what you want to do.
man 3 printf
this will open up the third man page of the prinf command
what does rm file* do?
removes files 1 to infinity that have digits after the filename. Ex: file1 file2
rm file?
removes files with one character after filename. files{0-9}
*(abc)
would match “”, “abc”, “abcabc”, “abcabcabc”, etc.
+(abc)
would match “abc”, “abcabc”, “abcabcabc”, but not an empty string “”
?(abc)
would match “” or “abc”.
@(abc|def)
would match “abc” or “def”, but not both or neither