Basic Linux Navigation
Overview
Learn the essential Linux commands for navigating the file system and managing files in your development environment.
Please keep in mind that many of these commands can be run with "flags" to add more functionality. If you want to see the list of flags a command has, the help flag -h will often give you a list of flags and what they do.
Essential Commands
Account Management
passwd- Change your passwordwhoami- Display current usernamewho- Show who is logged inexitorlogout- End your session
Important!
The first thing you should do when logging into a new account is change your password using the
passwdcommand. The server will prompt you for your current password, then ask you to enter and confirm your new password.
Basic Directory Navigation
ls- List directory contentscd- Change directorycd ..- Go up one directory levelcd ~- Go to home directory
An Example
In your home directory, if you look around with "ls" you should see a "www" folder. To navigate into the folder from your home directory, the command would be:
cd wwwOnce you've navigated into the www directory, to go back up a directory you could run
cd ..to traverse up. Or just runcd ~to go back to the home directory wherever you are.
File Operations
touch filename- Create an empty filemkdir directoryname- Create a new directoryrm filename- Remove a filerm -r directoryname- Remove a directory and its contentscp source destination- Copy files or directoriesmv source destination- Move or rename files/directoriesnano filename- Open file with nano editor
While it will be mostly unnecessary for us to modify files with nano, sometimes it's more convenient to quickly modify something through the terminal without setting up our entire coding environment.
An Example
If I wanted to create a file called
index.html, then make a copy of that file and place it into a new directory calledstaticpages/I would run the following commands:touch index.html mkdir staticpages cp index.html staticpages/If I wanted to rename the file during the copy to something like "nav.html", the last command could be modified to be
cp index.html staticpages/nav.html
File Viewing
cat filename- Display file contentsless filename- View file contents with paginationhead filename- Show first 10 lines of a filetail filename- Show last 10 lines of a file
These commands are useful for quickly viewing what's in the file without going into an editor.
Practice Exercises
Exercise 1: Basic Navigation
- Navigate to your home directory
- Create a new directory called
practice - Navigate into the
practicedirectory - Create a file called
test.txt - Open
test.txtand add your name to the file.
Exercise 2: Changing the index.html
- Navigate to your www directory
- Create a new directory called
backups - Copy the
index.htmlfile located inwww/public_htmlintowww/backups - Navigate to
www/public_html - Open your
index.htmlfile and look for the<title> </title>tag. - Put something between opening and closing tag to change the title of your webpage.
- Go to the umainecos.org site and confirm that the title of the page has changed.
Tips and Best Practices
- Use
Tabfor auto-completion - Use
Ctrl+Cto cancel a running command - Use
historyto see previously run commands - Use
clearto clear the terminal screen
Next Steps
Once you're comfortable with basic Linux navigation, proceed to VSCode Extension.