Skip to content

Latest commit

 

History

History
105 lines (69 loc) · 4.34 KB

commandline.md

File metadata and controls

105 lines (69 loc) · 4.34 KB

Navigating the Command Line

Although it may seem intimidating at first, using command line allows you to quickly perform tasks in a non-cumbersome way.

Accessing Unix

First navigate to the command line. If you are using a Mac, open Terminal (in Applications in the Utilities folder).

If you are using a windows machine, use Putty or another terminal emulator.

You should see a black window that has a command prompt that looks like this:

Usernames-Macbook-Pro:~ Username$

man pages

By typing man before the name of each command, you can get information about how to use them. The manual pages are a set of pages that explain every command available on your system including what they do, the specifics of how you run them and what command line arguments they accept. Some of them are a little hard to get your head around but they are fairly consistent in their structure so once you get the hang of it it's not too bad.To search for something in the man pages, use / and then type the search term. To proceed to the next instance of the term, use n. To return to the command line, type q.

BASH Commands

There are hundreds of different commands you can use to perform a variety of different functions (hold ESC and press the "y" key for a complete list), but here are a few of the most useful.

cd
Executed by itself will bring you to your home directory, while adding a path after cd will bring you to that directory. A directory is basically a folder that holds your files or other directories.

cd ..
Changes directory to one-up the directory hierarchy

ls
Lists the files and directories in the current directory.

ls -a
Lists the files and directories in the current directory including the hidden (dot) files. ls -al will show the files in long form (with their sizes and permissions). However, these sizes are only of the directory itself and do not say how big everything in a directory is. To see this information, use the command ls -shR.

pwd
Returns the path to the current directory

cp file_name path_to_new_directory
Copies a file from you current directory and places in a different directory.

mv file_name path_to_new_directory
Moves the file to a new directory.

cat Concatenates files to standard output. Prints the contents of the file on the screen. cat file1.txt file2.txt > newfile.txt will concatenate 2 files into a third file.

head -100 filename Prints the first 100 lines of filename to the terminal.

tail -10 filename Prints the last 10 lines of filename to the screen.

less filename Lets you view just a page at a time of a file. After entering this command, the following commands can be used to display a document: space bar: display the next page, b: display the previous page, enter/return: display the next line, k: display the previous line, q: quit the viewer

rm This will remove or delete a file (be careful--cannot undo).

mkdir Makes a directory. This is what you call folders when you're in the terminal

rm -rf Removes a directory and all its contents

control c Kills the current process

control z Stops or pauses current process

fg Resumes last stopped job in the foreground

tab: autocompletes while typing

tab tab: see available autocomplete

ls -ll Lists the files in a directory as well as their dates and permissions

du -sh This tells you the disk usage--what is taking up space in a directory

ls directory | wc -l This lets you count the number of files in a directory

chmod Change permissions

sed -i -e 's/something/else/g' myfile This will replace every instance of "something" with "else" in myfile.

echo prints whatever is typed after it. Ex. echo "text" >file.txt prints "echo" to a file called file.txt

exit Disconnect form Colonial One or current node

Once you feel comfortable with these commands and moving around using the command line, you can create and edit files using a text editor like vim or nano, or log onto Colonial One.

For another great tutorial, visit this site. For more advanced bash commands go here