Bash Tips
Basics
-
cdalone goes to the home directory. -
ls -ltgives the long format and sorted by modification time. -
file foo.txtgives the file type. -
less foo.txtgives the content of the file. -
We can double click a filename to copy it.
-
cpcopies the files. -
mvmoves the files or renames the files. -
lncreates links. -
Use
|to combine commands. -
Control A goes to the beginning.
-
Control R goes to revere searching in the history.
-
zip -r foo.zip foozips the file/directory.unzip foo.zipunzips. -
grep regex foo.txtsearches in foo.txt .- -i for case-insensitive
- -v for inversion
-
find . -name "foo*"finds the files with the name foo* . -
exec zshandexec bashswitch between the two shells. -
Control N clears the current line.
Writing Scripts
-
Put
#!/bin/bashat the beginning of the script. -
Use
chmod 755 foo.shto make the script executable for everyone. (700 for the owner only.)
Advanced Tricks
-
touch {a..z}{0001..0100}.txtcreates multiple files at once. -
grep -r "hello" .searches for hello recursively in the current directory. -
wget --no-parent -r https://cnds.jacobs-university.de/courses/os-2019/src/gets the content recursively. -
find . -name "*html*" -deleteremoves all files containing html. -
command &to run the command in the background.