Command Line Basics

A lot of work on the programming team involves the terminal so here is a quick reference for getting comfortable with working in the terminal. Note that linux and macOS are both Unix operating systems.

GREAT

cd <folder-name>                  # Change current directory to specified folder
pwd                               # Print working directory
ls                                # List files & folders in the working directory
clear                             # Clear the terminal screen (shortcut: ctrl + l)
rm <file-name>                    # Remove a file
rm -rf <folder-name>              # Delete a folder
mv <source-name> <dest-name>      # Move/rename a file
cp <source-name> <dest-name>      # Copy a file
cp -R <source-name> <dest-name>   # Copy a folder
top                               # Show CPU usage

Note

In order to go into the parent folder use cd ..

Other Useful Unix Commands

  • which shows where an executable is installed on the path (ex: which python)

  • shutdown must be run on the Jetson to properly shut it down before removing power source.

  • ctrl + c will stop anything executing in the terminal (this is how you stop a node)

  • code . will open the current directory in vscode if vscode was added to the path as code

  • Use the pipe operator | to send output to another command:
    • Ex: In order to find a file in a huge directory: ls | grep <file-name>

  • chmod +x <file-name> will give a file executable permissions (chmod stands for change mode)

  • > will redirect the output from a previous command (e.g. ls > list.txt writes the directories to the file)
    • >> will append the output to the end of an existing file while > overwrites

    • Ex: echo "source /opt/ros/foxy >> .bashrc will append the sourcing command to your bashrc

  • More on Redirecting Output, Input, & Errors