Resource: Command line crash course

Basic built-in terminal commands

  • Navigate computer’s file system:
    • Move around your directory(folder) structure: cd
    • Create directories: mkdir
    • Create files (and modify their metadata): touch
    • Copy files or directories: cp
    • Move files or directories: mv
    • Delete files or directories: rm
  • Download files found at specific URLs: curl
  • Search for fragments of text inside larger bodies of text: grep
  • View a file’s contents page by page: lesscat
  • Manipulate and transform streams of text (for example changing all the instances of <div>s in an HTML file to <article>): awktrsed

1. Navigation on the command line cd pwd ls

  • pwd can print the current directory(folder)
  • ls can list the contents in the current directory
  • The cd command lets you Change Directory
cd desktop
  • To move back up to the previous directory, you can use
cd ..
  • Can also type entire path
cd Desktop/project/src

Note: clean can clean the terminal

2. Open content open

open can open the folder, website ecc.

open downloads
open https://traversymedia.com

3. Command Options

Most terminal commands have options — these are modifiers that you add onto the end of a command, which make it behave in a slightly different way.

ls -l

To find out exactly what options each command has available, you can look at its man page. This is done by typing the man command, followed by the name of the command you want to look up, for example man ls.

4. Creating, copying, moving, removing

  • mkdir — this creates a new directory inside the current directory you are in
  • rmdir — removes the named directory, but only if it’s empty.
  • touch — creates a new empty file, inside the current directory.
  • mv — moves a file from the first specified file location to the second specified file location
  • cp — similar in usage to mvcp creates a copy of the file in the first location specified, in the second location specified.
  • rm — removes the specified file.

5. Connecting commands together with pipes |

if we wanted to quickly count the number of files and directories inside the current directory. There is another Unix tool available called wc. This counts the number of words, lines, characters, or bytes of whatever is inputted into it.

wc -l myfile.txt

Since ls prints each file or directory on its own line, that effectively gives us a directory and file count.

ls | wc -l