FactorPad
Build a Better Process

Navigate Linux Directories with 7 Basic Linux Commands

Yes, the Linux learning curve is steep. The payoff is faster navigation.
  1. 7 commands - Lay out the commands covered here.
  2. Terminal - Practice moving around in directories and making files.
  3. Command syntax - Discuss the consistent command structure.
  4. Takeaways in nano - Review notes on what we've learned.
  5. Next up: finding help - Access help that sits on the system already.
face pic by Paul Alan Davis, CFA
Updated: February 21, 2021
With practice you will memorize more than you think is possible. Let's press on together.

Outline Back Tip Next

/ factorpad.com / tech / full-stack / navigate-linux.html


An ad-free and cookie-free website.


Learn Linux Navigation Commands Faster

Beginner

Video Tutorial

Videos can also be accessed from our Full Stack Playlist 2 on YouTube.

Navigate Linux directories with 7 basic Linux commands | Linux Tutorial for Beginners (4:55)

Code Examples and Video Script

Welcome. Today's question: How do you navigate Linux?

I'm Paul, and in this video you will learn how to negotiate the fast lane using the Linux command line.

Step 1 - Overview of Linux navigational commands

Okay, so these seven commands cover most of our basic navigation.

And we will practice with others introduced earlier in this Project, Linux for Beginners.

We will start at the Terminal with command syntax, practice with each command, then highlight a few takeaways with notes using nano, before the next video on finding help. Here we go.

Step 2 - Practice at the Linux Command Line

Linux pwd command to print working directory

Let's use this Windows PC, open a Terminal and find our bearings with the pwd command showing where we currently sit on this local server.

paul@fullstack:~$ pwd /home/paul paul@fullstack:~$ whatis pwd pwd (1) - print name of current/working directory

It will help to understand that you're always sitting somewhere in Linux. The directory structure starts here / at what is called the root, and inside it sits a directory called home, and within that is my directory paul.

Linux cd command to change directories

Next, use the cd command to change directories to a subdirectory called notes and pwd again.

paul@fullstack:~$ cd notes paul@fullstack:~/notes$ pwd /home/paul/notes paul@fullstack:~/notes$ clear

Step 3 - The basics of Linux command syntax

Let's talk syntax, and most of the time it goes like this: $ command -option(s) argument(s), so there can be none or multiple options and arguments.

paul@fullstack:~/notes$ # command -option(s) argument(s) paul@fullstack:~/notes$

With this pound or hash symbol here #, known as a comment, the rest of the line isn't processed by Linux. I just wanted to note that.

Linux ls command to list files

Let's practice with commands by using four versions of ls, listing files in this directory.

paul@fullstack:~/notes$ whatis ls ls (1) - list directory contents

First, ls without options and without arguments and it defaults to the current working directory.

paul@fullstack:~/notes$ ls video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt

Second, the ls command, with one option, -1, and no arguments shows the same list but in one column.

paul@fullstack:~/notes$ ls -1 video0002.txt video0003.txt video0004.txt video0005.txt video0006.txt video0007.txt video0008.txt video0009.txt video0011.txt video0012.txt

Third, going with multiple options at once, adding o and g shows details but suppresses owner and group information.

paul@fullstack:~/notes$ ls -1og -rw-r--r-- 1 282 Jan 18 12:08 video0002.txt -rw-r--r-- 1 347 Jan 19 11:37 video0003.txt -rw-r--r-- 1 635 Jan 20 22:06 video0004.txt -rw-r--r-- 1 201 Jan 21 20:08 video0005.txt -rw-r--r-- 1 341 Jan 23 10:59 video0006.txt -rw-r--r-- 1 434 Jan 24 19:47 video0007.txt -rw-r--r-- 1 211 Jan 25 23:04 video0008.txt -rw-r--r-- 1 149 Jan 27 10:18 video0009.txt -rw-r--r-- 1 399 Jan 30 19:37 video0011.txt -rw-r--r-- 1 420 Feb 1 00:41 video0012.txt

And fourth, let's skip the options and add an argument, here explicitly saying which directory to look in.

paul@fullstack:~/notes$ ls /home/paul notes paul@fullstack:~/notes$ clear

There's our directory called notes.

So now you know ls and command syntax. Don't worry about memorizing just yet, it would be better if I show you where to find options and arguments for yourself, later, and in tutorial #13.

Linux mkdir command to make directories

Next, mkdir. Let's make a directory within the current directory using mkdir with the argument backup, and use ls to verify, okay.

paul@fullstack:~/notes$ whatis mkdir mkdir (1) - make directories paul@fullstack:~/notes$ mkdir backup paul@fullstack:~/notes$ ls backup video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt
Linux cp command to copy files

Next, cp is for copying files and directories, so let's copy notes from video0011.txt to the new backup directory, and then ls to verify.

paul@fullstack:~/notes$ cp video0011.txt backup paul@fullstack:~/notes$ ls backup video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt paul@fullstack:~/notes$ ls backup video0011.txt paul@fullstack:~/notes$ clear
Linux mv command to move or rename files

Next, mv moves and renames files, but it also works with directories, and let's test it, with a convenient option -i, called interactive. It prompts us if we're about to overwrite something. Linux assumes you know what you're doing, so when in doubt use -i.

paul@fullstack:~/notes$ whatis mv mv (1) - move (rename) files paul@fullstack:~/notes$ ls backup video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt paul@fullstack:~/notes$ mv -i backup bak paul@fullstack:~/notes$ ls bak video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt paul@fullstack:~/notes$ clear
Linux rm command to remove files or directories

Okay, rm is used to remove both files and directories. Let's say we want to undo what we just did, which can be accomplished using two options and one argument. The -i option again for a prompt, and -r for recursive, meaning it will delete directories and their contents. We'll accept these, then ls to verify.

paul@fullstack:~/notes$ whatis rm rm (1) - remove files or directories paul@fullstack:~/notes$ rm -ir bak rm: descend into directory 'bak'? y rm: remove regular file 'bak/video0011.txt'? y rm: remove directory 'bak'? y paul@fullstack:~/notes$ ls video0002.txt video0004.txt video0006.txt video0008.txt video0011.txt video0003.txt video0005.txt video0007.txt video0009.txt video0012.txt paul@fullstack:~/notes$ clear

And in some cases, options are specified with double-dash as with the whatis command. Watch this, -h shows help.

paul@fullstack:~/notes$ whatis -h Usage: whatis [OPTION...] KEYWORD... -d, --debug emit debugging messages -v, --verbose print verbose warning messages -r, --regex interpret each keyword as a regex -w, --wildcard the keyword(s) contain wildcards -l, --long do not trim output to terminal width -C, --config-file=FILE use this user configuration file -L, --locale=LOCALE define the locale for this search -m, --systems=SYSTEM use manual pages from other systems -M, --manpath=PATH set search path for manual pages to PATH -s, --sections=LIST, --section=LIST search only these sections (colon-separated) -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.

As does --help.

paul@fullstack:~/notes$ whatis --help Usage: whatis [OPTION...] KEYWORD... -d, --debug emit debugging messages -v, --verbose print verbose warning messages -r, --regex interpret each keyword as a regex -w, --wildcard the keyword(s) contain wildcards -l, --long do not trim output to terminal width -C, --config-file=FILE use this user configuration file -L, --locale=LOCALE define the locale for this search -m, --systems=SYSTEM use manual pages from other systems -M, --manpath=PATH set search path for manual pages to PATH -s, --sections=LIST, --section=LIST search only these sections (colon-separated) -?, --help give this help list --usage give a short usage message -V, --version print program version Mandatory or optional arguments to long options are also mandatory or optional for any corresponding short options.

And while we are here, make note of a nice summary of 12 short-form options and 13 long-form options available for whatis.

Step 4 - Notes in nano on Linux navigation

And while I open nano video0012.txt to save a few notes, I mentioned fast lane earlier. If you're addicted to your Graphical User Interface (GUI), like most of us are, think about how much longer this whole exercise would have taken using the point-and-click in Windows File Explorer or Finder in a Mac.

GNU nano 2.2.6 File: video0012.txt Navigation takeaways: - Command syntax command -option(s) argument(s) - Options short form - long form -- none, one or multiple options - Arguments none, one or multiple arguments - Navigation commands pwd - print working directory cd - change directories ls - list files mkdir - make directory cp - copy files and directories mv - move or rename files and directories rm - remove files and directories - tip when using cp, mv and rm use the -i option to preven mistakes ^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell

Yes, of course navigation isn't as visual in Linux, but if we were to judge on speed, Linux wins.

Step 5 - Next up: finding help in Linux

We covered a lot of ground in 4 minutes, so it may be helpful to play around with these commands later, because as we get going with this, our Data Science stack, navigation will be vital.

Next, I'll show you how to find help, going far beyond what we've done here with whatis.

Have a nice day.


What's Next?

If you didn't watch the video, you should. It will help with your retention and they're quick (under 5 minutes in this Playlist).

Outline Back Tip Next

/ factorpad.com / tech / full-stack / navigate-linux.html


navigate linux
navigate linux directories
basic linux
basic linux commands
linux commands
linux tutorial
linux pwd
linux cd
how to navigate linux
linux ls
linux mkdir
linux cp
linux mv
linux rm
linux options
linux navigation examples
linux arguments

A newly-updated free resource. Connect and refer a friend today.