Everyday Commands in Bash

There are several commands that you will need to learn so you can get around in a terminal. Below are a list of commands use might use everyday or almost everyday.

To learn more about these commands, you can use the command "man <command-name>" or "<command> --help", or just google it. Note: replace anything in <> with the content of interest (and then remove the <>).
Navigating through the Terminal

There are two important commands you will need to know in order to navigate through a terminal. First, how to list the contents of the current directory. And second, how to move between directories.

To list the contents of the directory you are in, use the command "ls". To get more information about the contents use "ls -l". To have the size of each file and directory written in something human readible, use "ls -lh". You can list the contents of any subdirectory with "ls <subdirectory>".

To navigate into a directory use the command "cd <directoryName>. To go up one directory, use the command "cd ..". To go to your home directory, use the command "cd ~". You can chain directories together, such as "cd directory1/subdirectory/subsubdirectory/etc" or "cd ../../../../..", to quicken the process of navigating.
Tab Completion

Instead of fully typing out the name of directories or files, you can press the tab key to have the computer finish what you are currently typing. If what you are typing is not unique, for instance there are two directories named "plotHist" and "plotGraph", the computer will complete up to "plot". But if you simply add in the next character and press the tab key again, it will complete the rest of the name.
Reading a File

To open a file for reading only (editing will be covered in another section on text editors), you can use the command "less <fileName>". To navigate you can use the up and down arrow keys to go line by line, or use the "u" and "d" keys to scroll up and down in half-page increments.
Figuring out where you are

If you are lost and need to know where you are in the file system, or simply need a path to copy and paste, use the command "pwd" to have path to your current directory printed to the terminal.
Moving Files

If you would like to change a file's name, use the command "mv <fileName> <newName>". If you would like to move a file to a new directory, us the command "mv <fileName> <path>".
Removing Files

To remove a file, use the command "rm <fileName>".
Making and Removing Directories

To make a new directory, use the command "mkdir <dirName>". To remove an empty directory, use the command "rmdir <dirName>". To remove a directory and all it's contents, use the command "rm -fr <dirName>" (BE VERY CAREFUL WITH THIS, THERE IS NO UNDO).

-- ForrestPhillips - 09 Aug 2017
Topic revision: r2 - 09 Aug 2017, ForrestPhillips
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback