DEV Community

alanmynah
alanmynah

Posted on

6 1

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

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (2)

Collapse
 
bobbyiliev profile image
Bobby Iliev

Great tips!

Collapse
 
alanmynah profile image
alanmynah

Thanks a lot

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs