Navigate Linux by the Command Line

Sometimes, just sometimes when you use Linux as a home user you need to navigate Linux by the command line. As the Linux novice you are, you need a quick intro to Linux shell commands if you want to find files and edit documents in that scary black hole that looks like it is going to suck you in when it opens up on your screen.

Lucky you, you have me. Here is a brief guide to the basic commands needed to get around Linux with text commands. Shell commands are easy to use and easy to remember but bookmark this page in case you get hit on the head later today and come down with a shocking case of amnesia.

Enjoy this quick guide to Linux command line navigation. Remember to share with friends and comment below.

This cheat sheet works for desktop Linux and web server Linux.

List files

Files are listed with the ls command.

File names that start with a dot are hidden. Type ls -a to view all files and directories including hidden files. Use ls to see only files and directories that are not hidden.

Hidden files are hidden to protect them from you. Treat hidden files with respect when you edit them.

  • First command is ls
  • Second command is ls -a

Change directory

Directory changes are made with the cd command. Type cd followed by the directory you wish to go to. If you typed cd /home/your-name you would be taken to your home directory.

A shorthand way to access your home directory is cd ~

The tilde, ~, represents the home directory of the active terminal user e.g. you. If you type cd ~ into a terminal you would be taken to the directory /home/your-name/.

To move up one directory, type cd ..

To go to the root directory type cd /

  • Third command is cd
  • Fourth command is cd ~
  • Fifth command is cd ..
  • Sixth command is cd /

Edit files

Files are edited with a command-line text editor. I like Nano. Other Linux admins use Vim. I think Vim is too complicated.

Type nano to start the Nano text editor.

You can tell Nano to open a file by either

  • Browsing to the file location then typing ‘nano file-name’, or
  • Telling nano the path to the file along with the file name

Opening nano with nano /home/downloads/example.txt would open example.txt stored in /home/downloads

Browsing to the downloads directory by first typing cd ~/downloads then typing nano example.txt would also open example.txt.

Some files can only be edited when opened by a user with admin rights. Type sudo nano file-name to edit protected files.

Nano has a menu that shows at the bottom of the screen. Commands in the menu are run by pressing Ctrl plus the specified key for the menu item. For example, Ctrl+X closes Nano.

Nano offers to save file edits on exit.

  • Seventh command is nano
  • Eighth command is sudo nano
  • Ninth command is nano /directory/file-name

Names with Spaces

Some directories and file names contain spaces. The easiest way to handle these directory names is to wrap them in single quotes.

  • If we need to edit a file name My Notepad we would open it with nano ‘My Notepad’.
  • If we need to enter a directory named My Documents we would enter it with cd ‘My Documents’.

Locate a file or directory

Use the locate command to locate files with loose name matching. Type locate file-name to find files with names that contain file-name.

Use find to find files with exact name matching. Type find -name file-name to find the file file-name. Type find PATH -name file-name to find files within or under the specified path.

For example,

  1. find / -name example.txt will list paths to files called example.txt stored in and below the root directory.
  2. find ~ -name example.txt will list paths to files called example.txt stored in and below your home directory.
  3. find -name example.txt will list paths to files called example.txt stored in and below the currently browsed directory.
  4. locate example will find files with names that contain the text ‘example’. The files could be anywhere on the computer.
  5. locate example.txt will find files with names that contain the text ‘example.txt’. The files could be anywhere on the computer.

Want to edit the files found with locate? Use backticks. Nano will open all files found:

  • nano `locate file-name`

Backticks look like single slanted quotes. The backtick key is normally found to the left of the number 1 on your keyboard.

If the list of locations is too long to display on one page, you  can pipe the results through the less command. This will spread the list of found files over several pages. The pipe is the vertical line character on your keyboard that looks like |. For example ls | less or locate text | less.

  • Tenth command is locate
  • Eleventh command is less

Locate a command program

Need to know where the launch script for kate is located or where the man page for Gimp cna be found? Use whereis. ‘whereis’ locates the binary, source, and manual page files for a command.

Type whereis kate to see where the kate binary program is (a binary file is called an executable file in Windows).

  • Twelfth command is whereis

Getting Help

Linux comes with a manual pre installed free of charge. There is a manual help page for most commands. Whenever stuck type man followed by the command name.

Type man man to see the help file for the manual.

Type man cd to see the manual for the cd command.

Pay attention to this: press Q or Ctrl+Q to quit the man page. Use arrow keys, page up and page down to navigate manual pages.

  • Thirteenth command is man

Miscellaneous commands

These next few commands are important. This commands make it possible to run a command line application like top, to stop the app then run another app like man.

  • See who you are logged in as with whoami
  • Stop a running program like top with Ctrl+C
  • Quit a running program like nano with Ctrl+Q
  • Shut the system with sudo shutdown -P now
  • Restart the system with sudo shutdown -r now
  • Or reboot the system with sudo reboot
  • View running processes with top
  • See Linux super moo powers with apt-get moo
  • View your terminal history with history
  • Clear the screen with clear

Sharing is caring!

Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x