Shell Command Sheet Cheat

Shell Command Sheet Cheat

Posting my collection of notes and cheat sheets I created during my time studying Software Engineering Immersive at General Assembly. 💛

🖥️ Command Line Interface

A command line interface (CLI) is a type of interface that's used to speak with your operating system. For example on a MAC we use the Terminal as our interface.

  • The Terminal command line controls your entire operating system
  • You use shell commands in order to communicate with your operating system to manipulate files and execute programs

🐚 Shell commands

Basics

  • ~ home directory
  • . current directory
  • .. up by one directory
  • pwd prints the current file path
  • clear clears the terminal screen (actually just pushes it up)
  • tree lists out all folders and files in the current directory (if tree is installed)
  • open opens a file, folder or URL that you specify
  • man another_command_name prints the manual for the specified command

Combined

cd - changes directory

  • cd or cd ~ will take you to the home directory
  • cd folder_name takes you to the specified directory
    • cd /Users/sammy/Documents follows the directory path and takes you to the Documents directory
  • cd .. takes you up by one directory
  • cd - takes you to the previous directory you were in

ls - lists directory contents

~ % ls
Applications   Downloads      Music          WebDevelopment
Desktop        Library        Pictures       venv

Can be combined with the following options to list the directory in a specific way or with specific information

  • ls -l - lists the directory in long format, with a total sum
~ % ls -l
total 0
------@  3 sammy  staff    99 12 Oct 16:01 Applications
------@ 10 sammy  staff    99  11 Dec 21:55 Desktop
------+  9 sammy  staff    99 17 Nov 19:09 Documents
  • ls -a - lists directory contents including hidden files
.Trash       Applications
.config      Desktop
Downloads    Documents
  • ls -la combines both -a and -l
~ % ls -la
total 40
-xr-x+ 31  sammy  staff    990  10 Dec 23:09 .
-xr-x   5  sammy  admin    990  10 Jan  2020 ..
--r--@  1  sammy  staff    990 10 Nov 14:04 .DS_Store
------  52 sammy  staff    990 31 Nov 20:57 .Trash
------   3 sammy  staff    990 21 Oct 22:41 .config

mkdir - creates a directory

  • mkdir Tuxedo_cats creates a directory called Tuxedo_cats
    • wrap the directory name in quotations to allow white spaces
~ % ls
Applications   Downloads

~ % mkdir Tuxedo_cats
~ % ls
Applications   Downloads   Tuxedo_cats

touch - creates a file

  • mkdir index.html creates a html file called index

rm - deletes directories or contents

  • Special note that rmdir will delete empty directories only
  • rm deletes file
  • rm -r folder_name deletes specified folder

mv - moves or renames a directory

  • mv file_or_folder new_location moves or renames the file or folder

cat - displays file contents

  • Additional options allows cat to display contents, combine contents or even creating new content
~ % cat hello.txt
Hello how are you?

✏️ Extras

Example of creating a directory, file and file content

mkdir hobbies
touch hobbies_list.txt
echo "video games" > hobbies_list.txt
echo "watching youtube" >> hobbies_list.txt

Tips

  • use Tab to auto complete directory or file names (case sensitive)
  • cd ../../../../ takes you up by 4 directories
  • Accessing folders or files that includes spaces in the name using backslash ls Creative\ Cloud\ Files or enclose them in double quotes "Creative Cloud Files"