Basic Linux Commands



Command Description
repeat a command To recall and re-execute previous commands, use the up-arrow key. Keep pressing this key until you find the command you want to reuse, then press the return/enter key.
ls [-l] [-a] Lists contents of directory (folder). Including the option -l gives more detail (protection, size, and date) -a causes ls to include files whose name starts with a period - they are not normally listed (wild cards OK) e. g. "ls ics212" lists all the files in the directory called ics212. "ls -a -l" lists all the files in your current directory, including files whose names start with . and this gives many details about the files. (Files whose names start with . are "hidden" files.)
* Many commands allow wild card characters in the file names. An * (asterisk) stands for any string of 0 or more characters. For example, *.c means all files that end with .c and "program*" means all files that start with "program" If you use * alone, it means all files.
? Many commands allow wild card characters in the file names. A ? (question mark) stands for any single character. For example, ?.c means all files that end with .c with one character names, and program.? means all files that start with "program" with one character file extensions. If you use ? alone, it means all files with one character names.
dir Will list all the files in the current directory (folder).
clear Clears out all the commands and output on the terminal window, and puts the curser at the top of the terminal window.
history Displays the command history list with line numbers. To clear the history, type:
history -c
!! Will display and execute the last command issued.
vi filename Creates a file and opens the vi editor.
mkdir dirname Make a new directory e. g. "% mkdir assignments" makes a directory called assignments
rm file Remove (delete, erase) a file or files (wild cards OK)
rmdir dirname Remove a directory
cp file1 file2 Copy file1 to file2.
mv file1 file2 Rename file1 to file2.
cd dirname Change directory. For example, "cd ics212" will change to the ics212 directory. "cd .." will move one directory higher.
cat filename Display a file. For example, "cat aloha.c" will display the file aloha.c on your screen.
more filename Display file in controlled increments. For example, "cat aloha.c" will display the file aloha.c in one page increments.
less filename Display file. Option -N displays the line numbers. To quit, type q.
pwd Print working directory (your current directory)
man command Display on-line manual for command. For example, "man ls" will display a short manual on the "ls" command.
command > outputfile.txt Usually, output is displayed on the terminal However, we can "redirect" where standard output is stored by using a command, followed by a greater-than-sign (>), and then a file name The output will be stored in the file! This stores the contents of the "ls" command in file1.txt:
ls > file1.txt
This stores contents of "history" command in file2.txt:
history > file2.txt

Click to validate the HTML code

Click to validate the CSS code