You need a shell to try these commands as you read. You may need help with this step.
Linux has been traditionally command line oriented. You type commands and then hit enter and something happens.
The program that listens to your commands is called the shell. There are different types of shells a common one is bash.
You should know the following commands to be functional:
man
pwd
ls
more
less
cat
cd
cp
mv
rm
mkdir
env
echo
tar
gunzip
hostname
vi
These commands will take you an hour to learn. Most valuable is the man command that shows you the manual for other commands. Try the command 'man pwd' to check it out. To exit from a manual page hit the letter 'q'
You enter the commands at the command prompt of the shell. Some commands are interactive and you need to end the interactive session by some form of quitting, to be able to enter further commands. vi is the most disconcerting of all the commands because it is not trivial to get out of it (vi is the standard editor for Unix environments). If you are inside a vi session and need to get out use <Esc> key followed by :q! sequence of keys (remember you need to hold the shift to use ':' and '!'. To exit a 'more' or 'less' session just hit 'q', yes the same one you used to exit the man page. man actually uses the less command to show the pages.
Learning these commands without context is boring and without benefit. Some of them have so many options or flags that it is impossible to learn them all. Here are some use cases to put context around these commands.
Know where you are in the file system. pwd - present working directory shows you where you are and ls lists the files and directories at the specified path or current directory if a path is not specified. Try these commands as you read.
[cox@ip-10-160-178-130 ~]$ pwd
/home/cox
[cox@ip-10-160-178-130 ~]$
create your directory and some files.
[cox@ip-10-160-178-130 ~]$ mkdir test
[cox@ip-10-160-178-130 ~]$ cd test
[cox@ip-10-160-178-130 test]$ echo "Simple text" > test_file.txt
echo prints the given text to screen and the '>' redirects the output to a file (test_file.txt). The following cat command prints the contents of our new file.
[cox@ip-10-160-178-130 test]$ cat test_file.txt
Simple text
[cox@ip-10-160-178-130 test]$ cp test_file.txt copy.txt
[cox@ip-10-160-178-130 test]$ cat copy.txt
Simple text
[cox@ip-10-160-178-130 test]$ ls
copy.txt test_file.txt
[cox@ip-10-160-178-130 test]$ mv copy.txt renamed_copy.txt
[cox@ip-10-160-178-130 test]$ ls
renamed_copy.txt test_file.txt
[cox@ip-10-160-178-130 test]$ cat renamed_copy.txt
Simple text
[cox@ip-10-160-178-130 test]$ rm renamed_copy.txt
[cox@ip-10-160-178-130 test]$ ls
test_file.txt
[cox@ip-10-160-178-130 test]$
cat, more, less help you see the contents of a file in different ways.
tar (tape archive) is useful for extracting files sent to you by others. These files typically have .tgz extension. Here we will create an archive and extract it.
[cox@ip-10-160-178-130 test]$ tar -cvzf archive.tgz test_file.txt
test_file.txt
[cox@ip-10-160-178-130 test]$ ls
archive.tgz test_file.txt
[cox@ip-10-160-178-130 test]$ rm test_file.txt
[cox@ip-10-160-178-130 test]$ ls
archive.tgz
[cox@ip-10-160-178-130 test]$ tar -xvzf archive.tgz
test_file.txt
[cox@ip-10-160-178-130 test]$ ls
archive.tgz test_file.txt
[cox@ip-10-160-178-130 test]$
Then let us remove what we just created. Before that in Unix '.' means current directory and '..' means parent directory. To switch to parent directory we use cd .. quite often.
[cox@ip-10-160-178-130 test]$ cd ..
[cox@ip-10-160-178-130 ~]$ pwd
/home/cox
[cox@ip-10-160-178-130 ~]$ ls
test
[cox@ip-10-160-178-130 ~]$ rm -rf test/
[cox@ip-10-160-178-130 ~]$ ls
[cox@ip-10-160-178-130 ~]$
notice the -rf flags to the rm command here. we give options or flags to commands to modify their behavior. You can mix multiple flags into a sequence -rf is same as -r -f (two flags). Here -r means remove recursively, -f means force. This is a common way to remove directories. rmdir works for directories that are empty.
Be careful with the rm command, there is no trash can to recover your data from.
What are the other commands?
[cox@ip-10-160-178-130 ~]$ echo $PATH
/usr/local/bin:/bin:/usr/bin:/opt/aws/bin:/home/cox/bin
[cox@ip-10-160-178-130 ~]$
the shell finds the commands/executable files from these directories list (each directory separated by ':').
You can see some of our commands are in the directory /bin (second directory in the list).
[cox@ip-10-160-178-130 ~]$ ls /bin
arch chmod date domainname false gunzip kill ls more nisdomainname raw rvi sort tcptraceroute traceroute6 usleep
awk chown dd echo fgrep gzip ksh mail mount pgawk readlink rview stty tcsh tracert vi
basename cp df ed find hostname ksh93 mailx mountpoint ping red sed su touch true view
bash cpio dmesg egrep gawk igawk link mkdir mv ping6 rm setserial sync tracepath umount ypdomainname
cat csh dnsdomainname env grep ipcalc ln mknod netstat ps rmdir sh tar tracepath6 uname zcat
chgrp cut doexec ex gtar iptables-xml login mktemp nice pwd rpm sleep taskset traceroute unlink
[cox@ip-10-160-178-130 ~]$
You can learn about these commands using the man command.
vi is a text editor that deserves its own section, but it is so ubiquitous everyone needs to know the first aid to survive in the Linux world.
You start a vi session (interactive session) by running it on command line. If a parameter is given it opens the path specified by the parameter. As with other commands you can use flags to modify behavior.
Once the interactive session starts you are not in the shell anymore, you are in vi. It has its own commands.
First how do I get out if I entered it accidentally?
<esc> key and then :q!
You may not need the <esc> key but sometimes you might have already entered the insert mode, and <esc> will get you to command mode. Yes vi has two modes insert and command. That is the toughest part about vi. It is vi's way of choosing who to be friends with.
Now for the easy part..
Say you did want to use vi to edit a file. Say you opened the session with
vi myNewFile.txt
assuming this file does not exist in the current directory, it will say at the bottom "myNewFile.txt" [New File]
vi tells you what is going on in the editing session by these messages at the bottom.
to add text you first enter the insert mode by the key 'i' (there are other ways but you just need to know there are other ways). Then you enter text, everything shows up as you expect! Great!
Now you are done editing or you just want to save your changes... anything you type shows up how do you do this? Well, you enter the command mode first by using the <esc> key first.
When in command mode, several keys have functionality, so be careful what you touch (you can learn some of these later). You need learn about the ':' commands first. If you hit ':' (shift + ';:' key) it shows up at the bottom. Now it is ready to take commands. Remember q!, that means quit don't ask questions. Normally if there is unsaved work it will refuse to quit unless you write. ! modifies q to force the quit command. We were talking about saving your work. 'w' for write will write your changes to the file. If you are done :wq will write and quit.
You should be able to survive a few vi sessions with these few commands. Too complicated? Well it is complicated, but it has its uses. You should learn at least this much if you are going to develop on Linux. A little more would be better. http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html and http://www.yolinux.com/TUTORIALS/LinuxTutorialAdvanced_vi.html should help.