Bash commands Flashcards
List contents of the directory
1) Display long form
2) Print one entry per line
3) Recursively list subfiles
4) Show hidden (dot) files
ls
1) ls -l
2) ls -1
3) ls -R
4) ls -a
Prints text to the cmd window
printf
echo
Improved echo that allows for formatting
Creates a file
touch
Update the access and modification times of each FILE to the current time
A FILE argument that does not exist is created empty, unless -c or -h is supplied
Create a directory
Create a directory with a subdir path
mkdir
Specify multiple directories
mkdir -p
Find out what a command does by printing manual or get help for a command
man
Print working directory
pwd
Change directory
1) One level up
2) Current Dir
3) Home Dir
cd
1) cd ..
2) cd .
3) cd ~
Move or rename a directory
mv
If filepath is the same, renames the file name
Remove empty directories
rmdir
Specify multiple directories
Locate a specific file or directory
locate
You can keep your search broad if you don’t know what exactly it is you’re looking for, or you can narrow the scope by using wildcards or regular expressions.
View the contents of a text file - displayed one page at a time
1) Go down
2) Quit
3) Go to the next file
less
Specify multiple filenames
1) spacebar to scroll down
2) :q
3) :n
Takes the output of a command and saves it to a file
Using the redirect operator >
echo Test > test.txt
head -n 5 filename.csv > head.txt
1) Read a file in CLI
2) Display contents with line numbers create a file, and concatenate files
3) Concatenate the outputs of two files and redirect it to a new file
4) Create a new file using the cat command
cat
cat -n
cat file1.txt file2.txt > combinedfile.txt
cat > file_name.txt
* type text, ENTER, ctrl + D to save the file
1) Print a list of commands run recently
2) Rerun a command based on its history number
3) Clear history
history
!600
history -c
1) Show lines containing specific values
2) Show lines that don’t match - invert the match
3) Print line numbers for matching lines
4) Print count of matching lines
grep
grep -v
grep -n
grep -c