DEV Community ðŸ‘Đ‍ðŸ’ŧðŸ‘Ļ‍ðŸ’ŧ

DEV Community ðŸ‘Đ‍ðŸ’ŧðŸ‘Ļ‍ðŸ’ŧ is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
alanmynah
alanmynah

Posted on

Learn Command Line

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!'
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

To execute a script:

./script.sh

### oh no, permission denied! what now?
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Alias

alias script='~/script.sh'
# is this an alias?
type script
Enter fullscreen mode Exit fullscreen mode

Getting help and Man pages

node --help # -- is how you indicate a flag, -h is a shorthand, so node -h is the same.
Enter fullscreen mode Exit fullscreen mode

For linux's own utilities, --help wouldn't work, so they have man manual command.

man ls
Enter fullscreen mode Exit fullscreen mode

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>' ./
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
bobbyiliev profile image
Bobby Iliev

Great tips!

Collapse
 
alanmynah profile image
alanmynah Author

Thanks a lot

Update Your DEV Experience Level:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠