This is a cheat-sheet to go along with the stream I did on Scrimba YouTube channel about command line.
Command Line notes
Where am i? What's here? How do i console.log?
pwd ls echo 'hello Scrimba!'
CRU(M)D
# create mkdir cmd-session cd cmd-session touch script.sh mkdir sub-folder # read ls sub-folder cat script.sh # move/update mv script.sh sub-folder/script.sh mv script.sh new-name-new-file.sh # delete rm script.sh rm -rf sub-folder
Execute
Create a script.sh
, example:
# touch script.sh, open it and write something like: echo "hello, running script!" echo "where am i?" pwd echo "ok, let's go somewhere else!" cd /code pwd echo "that's better"
To execute a script:
./script.sh ### oh no, permission denied! what now?
Permissions
# see permissions ls -l # they are repeated, 3 times, for user (owner of the file), group of users, everyone else. # -rwx - read, write, execute # to change permissions chmod u+x ./script.sh
Alias
alias script='~/script.sh' # is this an alias? type script
Getting help and Man pages
node --help # -- is how you indicate a flag, -h is a shorthand, so node -h is the same.
For linux's own utilities, --help wouldn't work, so they have man
manual command.
man ls
For a more visually pleasant man
pages:
https://explainshell.com/
Bonus: Search
grep 'echo' ./script.sh grep '<body>' ./ # grep: ./: Is a directory error, so you need to add recursive flag to search through directories grep -r '<body>' ./
Top comments (2)
Great tips!
Thanks a lot