Common Linux Commands

by Jim Krumm

|Home| |Computer Science| |Casper College| |Java Source Code| |C++ Source Code| |Visual C++.NET| |Visual Basic| |Assembly Source Code| |Linux| |Dice Program|

|Wyoming| |Casper Area| |American Album| |Personal Album| |Hawaii| |Denmark| |Greece| |Paris| |London| |Amsterdam| |Links| |Sitemap|

Click here to go to the Computer Science Department Home Page for Casper College at www.caspercomsci.com. 


A Short List of Common Linux Commands :

Cntrl-z or Cntrl-c Suspends or breaks out of a running Linux, C++, or java program and returns you to the console.

Up Arrow Reviews previous commands typed at the command line.

cat my  Displays text in the my file.

cd mine  Moves you to the mine folder, cd .. moves up a directory, cd \krumm moves you into the \krumm directory, cd home takes you to your home directory, cd ~krumm moves you into the krumm directory, where ~ is a mask to eliminate having to type the beginning of the path to move you to your home directory.

chmod  Used for changing permissions.

clear Clears the screen.

cp my.c my.cpp  Copies file my.c into a new file called my.cpp. cp my.c ./mine Copies the file my.c into a directory called my.c if this directory is in the same folder as my.c.

find  Allows you to search for files.

history  Gives a history of the commands you have executed from the command line.

locate javac  Displays the locations of the jdk directory and files (if any), giving the path. This is very handy as it will show the path to your jdk or java development kit so you can compile files. Locate works by scanning a database which is periodically updated using updatedb. If locate cannot find recent files invoke updatedb first. If too many matches are produced to view, output can be displayed in scrolling fashion typing locate javac | more (the | symbol can be found on the \ key).

kill 123  Turns off process with PID 123. PID can be determined using the ps command. Can use the more forceful:    kill -9 123, if the program does not stop.

ls Lists everything in a folder.

pico my.c  Edits a file called my.c with pico a common and easy to use Linux based console editor.

mail  A mail program, allows you to read your mail. + reads next, - reads last, h displays messages, d 1-100 deletes messages 1-100, 50 displays message 50.

man file  Displays the help files on the file command, or any other command. Also can use "help file" to open the manual's help files on file.

mkdir mine  Makes a folder called mine.

mv myfile.c .mine Used to move files. Here the file myfile.c is moved into a folder called mine. Can also be used to rename files, ie. mv myfile yourfile.

pico newfile.txt  Invokes a common and easy to use console text editor in Linux. Here it opens a new file to be called newfile.txt. Once running the program will display how to write text to file, exit the program, etc.

printenv  Prints relevant information about the environment including who you are, what current path you are located on, what your home directory is, what the operating system is, etc.

ps -ef   Lists all running processes, and give their id numbers. This is usually used to identify runaway processes which you need to "kill".

pwd   Prints the current path and directory you are in.

rm my.cpp  Deletes my.cpp (rm mine/my deletes a file called my in the mine folder.

rmdir mine  Removes the mine directory if no files are in it.

script myfile Records what is displayed on the console after this command is invoked to a file called myfile. This file written when the command exit is typed at the console.

tar -cf mytarfile.tar my.c your.c  Adds my.c and your.c to an archive. tar -xf mytarfile.tar restores files from the archive. tar -tv mytarfile -tv allows you to list the files stored in the archive.

uname -a  Gives the running version of Linux, uname -rs gives the operating system.


Compiling Programs in Linux and Linux Execution Commands:

g++ my.c –o my.o  Compiles a file called my.c makes a Linux executable called my.o

gcc my.c –o my.o  Compiles a file called my.c making a Linux executable called my.o

./executable Runs a file here called executable…no space between / and executable. This command is often used to run executables just created when compiling.

/usr/local/jdk-1.5-0-02-nb-4/jdk1.5/bin/javac kDyn44.java Compiles a java file called kDyn44.java where you are required to give the path to the version of java running. The path here prior to javac is one where jdk 1.5 might be. If this path is pre-configured all that is necessary is have javac kDyn44.java.

java kDyn44 Runs a java file. Using the running of java files is pre-configured (unlike javac).

It is possible to get bootable forms of Linux which load from a CD. One example of bootable Linux is Knoppix. Knoppix can be booted in seconds and does not interact with your hard drive. It loads into RAM. Knoppix is free and can be downloaded at http://www.knoppix.org/. Knoppix is easy to use, and is lean and mean. It is also visual and well thought out. It supports programming in C++. Knoppix comes complete with a number of open source and free GNU programs and does a superb job of hardware detection. If you are on a network and attached to the internet, chances are it will automatically detect the connection and you will have access which makes it easy to send your programs to yourself, as you cannot save to your hard drive. It is ideal for users who do not want to deal with partitioning a hard drive and setting up a dual boot Windows and Linux operating system.


©All rights reserved by James Krumm. Originally made available at www.caspercomsci.com. Materials here can be used, and redistributed, provided proper reference is made to the origin and author(s) of these materials. Please send any corrections or suggestions to jkrumm@caspercollege.edu. Last modified July 7, 2009.


To find out more about the Casper College Computer Science Program contact us at:

James Krumm
Department Head
Computer Science,
Wold Physical Sciences Building,
Casper College,
125 College Drive,
Casper, Wyoming 82601
(307) 268-2519 jkrumm@caspercollege.edu

[Return to Home Page]

|Home| |Computer Science| |Casper College| |Java Source Code| |C++ Source Code| |Visual C++.NET| |Visual Basic| |Assembly Source Code| |Linux| |Dice Program|

|Wyoming| |Casper Area| |American Album| |Personal Album| |Hawaii| |Denmark| |Greece| |Paris| |London| |Amsterdam| |Links| |Sitemap|