Type a command into a terminal window after the prompt. Always end a command with the Enter key. The following is a list of some useful commands.
Open a text editor (gedit). The &
symbol at the end of the command tells
the terminal not to wait for gedit to
finish. That way, you can keep using
the terminal without closing gedit.
The gedit text editor is simple and
easy to use.
If you start gedit this way, you will get error messages that do not mean anything in the terminal. Ignore them, If you start gedit from a desktop menu, those messages will not show up. |
firefox&
Start the firefox browser. |
A directory is the same as a folder. It holds files and other directories. You always have a current working directory. Any files that you mention are assumed to be in the current working directory. The cd command sets the current working directory to a given directory. |
pwd
Show the current working directory. |
ls
List the names of the files and directories
in the current directory. (The first letter
of this command is a lower case ell.)
Use ls -lto get a listing that shows details about the files and directories. Use ls -Fto get a listing that shows a / after the name of each directory. Normally, the ls command does not show files whose names begin with a dot. To see all files, use ls -aAdd multiple options to get the effect of all of them. |
Paths
You refer to a file by saying how to find it, either
starting in the current working directory or
starting in the main directory of the computer
(called the root directory).
Use / to separate directories, or to separate a
directory from a file name. Do not use \.
Each directory has two special directories in it that are created automatically. File . (just a dot) refers to the directory itself. File .. refers to the directory that contains this directory. For example, if the current directory has a file called assn1.cpp, then you can write path ./assn1.cpp to say explicitly to look in the current directory. Command cd ..sets the current working directory to its parent, the one that contains it. For example, if your current directory as ~/2530/assn1 and you do command cd .., then your current directory becomes ~/2530. Another cd .. makes the current directory be ~. |
Create directory dir. For example,
mkdir 2530creates a directory called 2530. |
cp old new
Make a copy of file old, and call
the copy new. Both old and
new are paths. For example,
cp assn1a.cpp assn1b.cppcreates a copy of assn1a.cpp and calls the copy assn1b.cpp. If new is an existing directory, then cp creates a file in that directory with the same name as old. So if 2530 is a directory inside the current directory, then cp foo.cpp 2530makes a copy of foo.cpp in directory 2530. Use cp -R … to copy an entire directory. For example, cp -R 2530 2530.bakcreates a copy of directory 2530 and everything in it, and calls the copy 2530.bak. |
mv old new
Move file or directory old to
new. If new does not
already exist, then this is just a
renaming. For example, command
mv assn1.cpp assn1a.cpprenames assn1.cpp to assn1a.cpp. If new is an existing directory then the mv command just moves old into directory new |
rm path
Remove file path. If you want to
remove a directory and everything in it, use
rm -r dirBe careful. The rm command does a permanent removal. You cannot get the file back. |
rmdir dir
Remove directory dir, but only if it is empty. (A directory is defined to be empty if it only contains . and ... |
man command
Read the manual entry for command.
For example,
man lsshows the manual entry for ls in the terminal. It will show one page at a time. To go to the next page, press the space bar. |
!!
Redo the previous command. |
You can set environment variables that control how
Linux works for you. One environment variable tells Linux where
to look for the executable files that perform commands. Its value
is a string that is a sequence of directories separated by colons.
For example, a setting of PATH =
.:/bin:/usr/local/bin
says to look first in the current directory (.), then in /bin (where
many commands are kept) and then in /usr/local/bin (where a few
commands are put).
In a command, you refer to path by $PATH. Command
echo $PATH
shows you the current value of PATH. Command
export PATH=.:/bin:/usr/local/bin
sets PATH to be .:/bin:/usr/local/bin. Typically, you put
commands into a file such as ~/.bashrc (which is read each time
the bash command processor starts).
How to you enter commands? Answer
How can you create a C++ file using Linux? Answer
How do you create a directory called dir? Answer
How can you set your current working directory to dir? Answer