Basic Linux Information and Commands

A UWB Linux workstation is not “private” in the same way that a Windows or Macintosh workstation can be “private”. Someone else could be working on the same machine as you are, remotely, while you are working, and you wouldn't know it.

We don't reboot, unplug, or disconnect any Linux workstation from the network because someone else could be using it.

All 32 Linux computers in the LinuxLab (the podium, the 15 desktops, and the 16 blades in the rack) can be accessed from “outside” through ssh by connecting to uw1-320-lab.uwb.edu.

More remote login instructions are available here: http://www.uwb.edu/CSS/advising/undergrad/unix.xhtml. More ssh instructions are available here: http://www.uwb.edu/CSS/advising/undergrad/sshCertification.xhtml

Login with your UW NetID.

Most work will be done “in a terminal” and “on the command line”. To open a terminal, on RHE5 (Red Hat Enterprise, version 5) in Gnome (the desktop environment), either right-click and select “Open Terminal”; or use the top pull-down menu: Applications→Accessories→Terminal

In Linux, “folders” are called “directories”.

Directory Operations

pwd “print working directory” returns your current location in the file system.
mkdir <directory> “make directory” creates a new empty directory.
rmdir <directory> “remove directory” removes a directory only if it is empty.
cd “change directory” allows you to navigate the filesystem. File navigation maybe be by “absolute path” (beginning at the “slash” directory) or by relative path (beginning where you are).
cd without any arguments or as cd ~ will always return you to your login home directory.
cd <directory> will make your path longer by one directory, moving you into the directory represented by <directory>.
cd <path>/<dir> will make your path longer, moving you into the directory represented by <dir> at the end of the path represented by <path>. This is a relative path.
cd /<path>/<dir> will make your path longer, moving you into the directory represented by <dir> at the end of the path represented by <path>. This is an absolute path.
cd .. will make your path shorter by one directory, moving you closer to the slash directory.
cd ../.. will make your path shorter by two directories, moving you closer to the slash directory.
du -sh ~ “disk usage”, summarized, in human-readable form for the directory ~. This command will tell you how much space you are using in your home directory.

On the command line, filenames need to be written carefully. It is acceptable to use upper and lowercase letters, numbers, underscores, dashes, and dots (periods). Avoid using spaces or “special characters”. Also, filenames are case-sensitive: FilenAme and filenaMe are not the same file; (warning) unless you move them from Linux to Windows.

File Operations

ls “list”. Lists all “visible” files in current directory. An “invisible” file begins with a dot.
ls -la “list”, long, all. Lists all files in current directory, both visible and invisible, and presents them in a long list format. The “long list” format displays the file “permissions”
cp <filename1> <filename2> “copy”. copy existing filename1 into new filename2.
cp -r <dir1> <dir2> “copy”, recursively. copy existing contents of directory1 into directory2.
rm <filename1> <filename2> “remove”. delete filename1 and filename2. * Not reversible!
rm -r <directory1> “remove”, recursively. delete directory1 and all its contents. * Not reversible!
mv <file1> <directory1> “move”. move file1 into directory1. * Not reversible! Be careful with mv, cp is safer.
cat <filename> “catalogue”. Display file contents (concatenate file contents to “standard output”)
cat <file1> > <file2> “catalogue” with a “redirect”. Overwite the contents of file2 with the contents of file1.
cat <file1> >> <file2> “catalogue” with an “append”. Write the contents of file1 to the end of file2. If file2 already has contents, they will still be there also.
cat <file1> 2> <file2> “catalogue” with an “error redirect”. Write the contents of file1 to standard output, and any errors (like “permission denied”) to file2.
cat <file1> 2>> <file2> “catalogue” with an “append error redirect”. Write the contents of file1 to standard output, and any errors (like “permission denied”) to the end of file2. If file2 already has contents, they will still be there also.
cat <file1> > <file2> 2>&1 “catalogue” with an “output and error redirect”. Write all output (regular output plus any errors) cataloguing file1 into file2.
cat <file1> | tee <file2> “catalogue” with a “pipe to tee”. Write standard output to standard output AND to file2.
more <filename> “more”. Display file contents, one screen-full at a time. Display a single line more by hitting the <enter> key. Display the next screenful buy hitting the <spacebar>. Exit before the end of the file by typing the letter “q”.
tar -cvf <dir_1.tar> <dir_1> “take archive”, create, verbose, filename. Bundle all the contents of dir_1 into a single file called dir_1.tar. This is like zipping only without the compression. The target filename needs to be written immediately after the space following the “f switch” (the -f).
tar -xvf <dir_1.tar> “take archive”, extract, verbose, filename. Unbundle all the contents of dir_1.tar into the current directory.
tar -tf <dir_1.tar> “take archive, list, filename. Display the contents of dir_1.tar in standard output.
tar -tvf <dir_1.tar> “take archive”, list, verbose, filename. Display the contents of dir_1.tar in standard output, using long list format.

* Not reversible: Linux does not have a recycle bin or trash bin as an intermediary step before real deletion occurs. In addition, Linux assumes you know what you are doing and doesn't ask “are you sure?” by default.

Job Operations

ps “process”. Display a “snapshot” of the current processes owned by the current user in the current terminal. The list will include the process id number which can be used with kill if needed.
ps -fu <username> “process” - full listing for user <username>”. Display a full listing of all current processes on this machine owned by the user <username>. The list will include the process id number which can be used with kill if needed.
ps -fu <user> | grep <process> “process” - full listing for user “username”; “piped to grep” for <process>. Search the output of ps -fu for lines that contain <process> and print them to standard output
ps aux “process” aux (without any hyphen). Display a listing of processes on the current machine.
Ctrl-c terminates a job
Ctrl-z suspends a job
Ctrl-d terminates an external process
kill <process_id> terminates the process identified by the number <process_id>
<command> & Allow <command> to run in the “background” so you can reuse this same terminal (to run ps or other work). Try this with firefox &
<command>; Will make all subsequent calls to job <command> act as if they were called as <command> & Try this with firefox
bg “background” Resume a suspended job in the background (as if it had been started with &).
fg “foreground” Resume a suspended job in the foreground.
top “top process” Show real time resource usage by job for the machine. To kill this use Ctrl-c

Printing

lpr -Puw1-320-p1 <file> “print file to printer uw1-320-p1”. Our printers in the LinuxLab are named uw1-320-p1 and uw1-320-p2
lp -duw1-320-p1 <file> “print file to destination uw1-320-p1”. Outputs a job number which can be used with cancel if needed.
a2ps -Puw1-320-p1 <file> print file <file> formatted for a postscript printer to Printer uw1-320-p1. Output will be one-sided, like a folded booklet; two sheets on one page.

Network Operations

ssh <hostname> “secure shell”. Open a new terminal on the <hostname> computer. Use hostname to see the name of your current host
ftp “file transfer protocol”. An unsecure way to transfer files from one host to another which is not used here because it sends passwords in the clear. Use scp instead.
scp <localfile> <remotehost>:/dest/path/ “secure copy protocol”. Copy a local file <localfile> to /destination/path on the <remotehost>
exit “exit”. Close a terminal or a foreign connection. If exit doesn't work, try quit or q
who “who”. Show who is logged in

Software Development

g++ -o <executable> <cppfile> “compile <cppfile> as C++, creating program named executable”. If you want to compile all of the .cpp files in the current directory, use ”*.cpp” as <cppfile>.
tar xvzf <file> “extract all files from the compressed archive <file>”. The tar command pre-dates the use of dashes to mark command options; the above is equivalent to tar -x -v -z -f <file>. The 'x' option means to extract from the archive, 'v' is “verbose” (display the file names as they're being extracted), 'z' means that the archive is compressed, and 'f' indicates that the next argument is the name of the archive file (without that argument, tar defaults to looking for the archive on a tape drive, as befits it full name, “tape archiver”).
tar cvf prog0.tar *.{cpp,h} “create archive file called prog0.tar with all .cpp and .h files in it”. This use of tar creates a tar file called prog0.tar in the current directory, placing in it all files that end in either .cpp or .h. Neither Unix nor any of its commands care what file names or extensions are, but it's useful documentation for a human and is used by whatever GUI you have (Gnome, KDE, Mac OS X).

You can reduce your typing a bit by creating a simple shell script. Please enter the following into a file, perhaps called build (or b, if you want to minimize typing), in the same directory as your source files:

#!/bin/sh
g++ -o prog1 a.cpp b.cpp d.cpp

Where, of course, you need to substitute your own list of .cpp files and the program name. Make the script executable by typing chmod u+x build (or whatever you called the file, if not build) at the command line. You can now compile your code by just typing build (or b).

More Essentials

man <commandname> “manual”. The instructions pages for <commandname>. Use q to exit from manual.

The following Text Editors are installed on the LinuxLab machines. Some of them colorize code. Use whichever you like best. Start them from the command line

  • vi <filename>: pronounced “vee eye”. Visual Editor, now the improved version called “vim”
  • vim <filename>: pronounced “vim”. Improved Visual Editor
  • emacs <filename>: pronounced “ee-max”.
  • nedit <filename>: pronounced “en-edit”.
  • gedit <filename>: pronounced “gee-edit”. Gnu editor
  • pico <filename>: pronounced “pee-Koe”. Pine is written in Pico. If you have used Pine as an email client, you are already familiar with Pico. It was developed by the University of Washington.

More information about text editors is available on this page: text_editors.html

More Help http://www.uwb.edu/CSS/advising/undergrad/unix.xhtml http://www.uwb.edu/CSS/advising/undergrad/sshCertification.xhtml http://www.uwb.edu/computing/knowledgebase/index.xhtml http://www.uwb.edu/computing/students/remservlinux.xhtml http://www.washington.edu/computing/unix/commands.html http://en.wikipedia.org/wiki/Chmod

Also Linux help is available through linhelp@uwb.edu and

The uwb_linux email list: https://mailman1.u.washington.edu/mailman/listinfo/uwb_linux

Navigation

The best way to find something here is to use the search box in the upper right or the site index link below.

Print/export
Mobile QR Link