Part 6: Linux Shortcuts and Commands
by Peter, Stan, Barbara and Marie Klimas
Answers to Some Frequently Asked Linux Questions
Distributed under the General Public Licence http://www.gnu.org/copyleft/gpl.html.
Your feedback, comments, corrections, and improvements are appreciated.
Send them to either bklimas@magma.ca
or bw641@freenet.carleton.ca
Start: Linux Newbie Administrator Guide
Part 0: For the Undecided (Linux Benefits)
Part 1: Before Linux Installation
Part 2: Linux Resources, Help and Some Links
Part 3: Basic Operations FAQ
Part 4: Linux Newbie Administrator FAQ
Part 5: How to Upgrade the Kernel
Part 6: >Linux Shortcuts and Commands<
Part 7: Essential Linux applications (proprietary
or not)
Contents of this page:
Linux shortcuts and commands:
A. Linux essential shortcuts and sanity commands
B. Common LINUX commands--system info
C. Basic operations
D. Process control
E. Basic administration commands
F. Networking tools
G. Linux built-in developer tools and programming languages
Linux Shortcuts and Commands:
Legend:
<> = single special or function key on the keyboard,
for example <Ctrl>
italic = name of the file or variable you
probably want to substitute with your own
Notes for the UNIX Clueless:
1. PLEASE REMEMBER THAT LINUX IS CASE-SENSITIVE. For example: Netscape,
NETSCAPE and nEtscape are three
different commands. Also my_filE, my_file, and my_FILE are three different
files. Your password is also case sensitive. (UNIX and the "c" programming
language are also case sensitive).
2. Filenames can be up to 256 characters long and can contain letters,
numbers, "." (dot), "_" (underscore), "-" (dash), plus some other not recommeded
characters.
3. Files with names starting with "." are not shown by the ls
(list) or dir commands ("hidden" files) unless you use ls
-a (list with the option all).
4. "/" is an equivalent to DOS "\".
5. In a configuration file, a line starting with # is a comment.
A. Linux essential shortcuts and sanity commands
B. Common LINUX commands--system info
<Ctrl><Alt><F1> Switch to the first text terminal. Under Linux you can have several terminals opened at the same time. <Ctrl><Alt><Fn> (n=1..6) Switch to the nth text terminal. <Ctrl><Alt><F7> Switch to the first GUI terminal (if one is running). <Ctrl><Alt><Fn> (n=7..12) Switch to the nth GUI terminal (if a GUI terminal is running on screen n-1) <Tab> Autocomplete the command (in a terminal). THIS SHORTCUT IS GREAT! It works at LILO prompt too! <ArrowUp> Scroll and edit the command history. Press [Enter] to execute. <Shift><PgUp> Scroll terminal output up. Work also at the login prompt, so you can scroll through your bootup messages. <Shift><PgDown> Scroll terminal output down. <Ctrl><Alt><+> (in X-windows) Change to the next X-server resolution (if you set up the X-server to more than one resolution). <Ctrl><Alt><-> (in X-windows) Change to the previous X-server resolution. <Ctrl><Alt><BkSpc> (in X-windows) Kill the current X-windows server. Use if the X-windows server crushes and cannot be exited normally. <Ctrl><Alt><Del> Shut down the system and reboot. This is the normal shutdown command for a user at the text-mode console. <Ctrl>c Kill the current process. <Ctrl>d Logout from the current terminal. <Ctrl>d Send [End-of-File] to the current process. <Ctrl>s Stop the transfer to the terminal. <Ctrl>q Resume the transfer to the terminal. Try if your terminal mysteriously stops responding. <Ctrl>z Send the current process to the background. reset Restore a screwed-up terminal (a terminal showing funny characters) to default setting. Use if you tried to "cat" a binary file. You may not be able to see the command as you type it. <MiddleMouseButton> Paste the text which is currently highlighted somewhere else. This is the normal "copy-paste" operation in Linux. (It doesn't work with Netscape and WordPerfect which use the MS Windows-style "copy-paste".) Best used with a Linux-ready 3-button mouse (Logitech or similar). ~ My home directory. For example, cd ~/my_dir . (dot) Current directory. .. (two dots) Directory parent to the current one.
C. Basic operations
Command Description pwd Print working directory, i.e., display the name of the current directory on the screen. hostname Print the name of the local host (the machine on which you are working). Use netconf (as root) to change the name of the machine. whoami Print my login name. id username Print user id (uid) and his/her group id (gid), effective id (if different than the real id) and the supplementary groups. date Print or change the machine date and time. E.g., change the date and time to 2000-12-31 23:57 using this command:
date 123123572000time Determine the amount of time that it takes for a process to complete + other info. Don't confuse it with date command. E.g. I can find out how long it takes to display a directory content using:
time lswho Determine the users logged on the machine. rwho -a Determine all users logged on your network. The rwho service must be enabled for this command to run. If it isn't, run "setup" as root to enable "rwho". finger user_name System info about a user. Try: finger root uptime Amount of time since last reboot. ps List the processes currently run by the current user ps axu | more List all the processes currently running, even those without the controllling terminal, together with the name of the user that owns each process. top Keep listing the processes, sorted by cpu usage. uname -a Info on your server. free Memory info (in kilobytes). df -h (=disk free) Print disk info about all the filesystems (in human-readable form) du / -bh | more (=disk usage) Print detailed disk usage for each subdirectory starting at root (in human legible form). cat /proc/cpuinfo Cpu info. Note that the files in the /proc directory are not real files. They are hooks to look at information available to the kernel. cat /proc/interrupts List the interrupts in use. cat /proc/version Linux version and other info cat /proc/filesystems Show the types of filesystems currently in use. cat /etc/printcap Show the setup of printers. lsmod (as root) Show the kernel modules currently loaded. set|more Show the current user environment. echo $PATH Show the content of the environment variable "PATH". This command can be used to show other environment variables as well. Use "set" to see the full environment. dmesg Print the boot messages. (It displays the file: /var/log/dmesg.)
D. Process control
ls List the content of the current directory. Under Linux, the command "dir" is an alias to ls. cd directory Change directory. Using "cd" without the directory name will take you to your home directory. "cd -" will take you to your previous directory and is a convenient way to toggle between two directories. cp source destination Copy files. mcopy source destination Copy a file from/to a dos filesystem (no mounting necessary). E.g., mcopy a:\autoexec.bat ~/junk . See man mtools for related commands: mdir, mcd, mren, mmove, mdel, mmd, mrd, mformat .... mv source destination Move or rename files. ln -s source destination Create a symbolic link. rm files Remove files. mkdir directory Make a new directory. rmdir directory Remove an empty directory. rm -r files (recursive remove) Remove files, directories, and their subdirectories. Careful with this command as root! There is no undelete in Linux (yet). cat filename | more View a content of a text file called "filename", one page a time. The "|" is the "pipe" symbol (on many American keyboards it shares the key with "\") The pipe makes the output stop after each screenful. For long files, it is sometimes convenient to use the commands "head" and "tail" that display just the beginning and the end of the file. If you happend to use "cat" a binary file and your terminal displays funny characters afterwards, you can restore it with the command "reset". less filename Scroll through a content of a text file. Press q when done. "Less" is roughly equivalent to "more" , the command you know from DOS, although very often "less" is more convenient than "more". pico filename Edit a text file. pico -w filename Edit a text file, while disabling the long line wrap. Handy for editing configuration files, e.g. /etc/fstab. lynx file.html View an html file or browse the net from the text mode. tar -zxvf filename Untar a tarred and compressed tarball that you downloaded from the Internet. find / -name "filename" Find the file "filename" on your filesystem starting from / . The "filename" may contain a wildcard (*,?). locate filename Find the file name of which contains the string "filename". Easier and faster than the previous command. pine A good text-mode mail reader. Another good and standard one is "elm". Your Netscape mail will read the mail from your Internet account. Pine will let you read the "local" mail, e.g. the mail your son or a cron process sends to you. talk username1 Talk to another user currently logged on your machine (or use "talk username1@machinename" to talk to a user on a different computer) . To accept the invitation to the conversation, type the command "talk username2". If somebody is trying to talk to you and it disrupts your work, your may use the command "mesg n" to refuse accepting messages. You may want to use "who" or "rwho" to determine the users who are currently logged-in. mc Launch the "Midnight Commander" file manager (looks like "Norton Commander" for Linux). telnet server Connect to another machine using the TELNET protocol. Use a remote machine name or IP address. You will be prompted for your login name and password--you must have an account on the remote machine. Telnet will connect you to another machine and let you operate on it as if you were sitting at its keyboard (almost). Telnet is not very secure--everything you type goes in open text, even your password! rlogin server (=remote login) Connect to another machine. The login name/password from your current session is used; if it fails you are prompted for a password. rsh server (=remote shell) Yet another way to connect to a remote machine. The login name/password from your current session is used; if it fails you are prompted for a password. ftp server Ftp another machine. This is good for copying files to/from the remote machine. minicom Minicom program (looks like "Procomm for Linux"). ./program_name Run an executable in the current directory, which is not on your PATH. xinit Start a bare X-windows server (without a windows manager). startx Start an X-windows server and the default windows manager. Works like typing "win" under DOS with Win3.1 startx -- :1 Start the next X-windows session on the display 1 (the default is opened on display 0). You can have several GUI terminals running concurrently. Switch between them using <Ctrl><Alt><F7>, <Ctrl><Alt><F8>, etc. xterm (in X terminal) Run a simple X-windows terminal. Typing "exit" will close it. xboing (in X terminal). Very nice, old-fashioned game. gimp (in X terminal) A humble looking but very powerful image editor. Takes some learning to use, but it is great for artists. Use your mouse right button to get local menus. netscape (in X terminal) Run netscape (requires a separate Netscape installation). The current versions of Netscape (4.06 and 4.5) are known to be big and buggy. They occasionally crash by vanishing (no other harm done). Also, when not connected to the network , Netscape likes to refuse to do anything (looks like it hangd)-it revives when you connect. netscape -display host:0.0 (in X terminal) Run netscape on the current machine and direct the output to machine named "host" display 0 screen 0. You must give the current machine a permission to display on the machine "host" using the xhost command. shutdown -h now (as root) Shut down the system to a halt. Mostly used for a remote shutdown. Use <Ctrl><Alt><Del> for a shutdown at the console (which can be done by any user). halt
reboot(as root) Halt or reboot the machine. Used for remote shutdown, simpler to type than the previous command.
E. Basic administration commandsPlease note also the control shortcuts: <Ctrl>c, <Ctrl>z, <Ctrl>s, and <Ctrl>q. They were described previously.
ps (=print status) Display the list of currently running processes with their process IDs (PID) numbers. Use
ps axu
to see all processes currently running on your system (also those of other users or without a controlling terminal), each with the name of the owner. Use "top" to keep listing the processes currently running.fg PID Bring a background or stopped process to the foreground. bg PID Send the process to the background. Opposite to fg. The same can be accomplished with <Ctrl>z. kill PID Force a process shutdown. First determine the PID of the process to kill using ps. killall program_name Kill program(s) by name. xkill (in an xwindow terminal) Kill a GUI-based progrma with mouse. (Point with your mouse cursor at the window of the process you want to kill and click.) lpc (as root) Check and control the printer(s). lpq Show the content of the printer queue. lprm job# Remove a printing job from the queue. nice program_name Run program_name adjusting its priority. Since the priority is not specified in this example, it will be adjusted by 10 (the process will run slower), from the default value (usually 0). The lower the number (of "niceness" to other users on the system), the higher the priority. The priority value may be in the range -20 to 19. Only root may specify negative values. Use "top" to display the priorities of the running processes. renice -1 PID (as root) Change the priority of a running process to -1. Normal users can only adjust processes they own, and only up from the current value (make them run slower).
F. Networking tools
printtool (as root in X-terminal) Configuration tool for your printer(s). Settings go to the file /etc/printcap. setup (as root) Configure mouse, soundcard, keyboard, X-windows, system services. alias ls="ls-Fskb --color" Create an alias for the command "ls" to enhance its format. In this example, the alias is also called "ls". Put the alias into the file /etc/bashrc if you would like the alias to be always accessible to all users on the system. adduser user_name Create a new account (you must be root). E.g.,
adduser barbara
Don't forget to set up the password for the new user in the next step. The user home directory is /home/user_name.useradd user_name The same as adduser. userdel user_name Remove an account (you must be a root). The user's home directory and the undelivered mail must be dealt with separately. groupadd group_name Create a new group on your system. Non-essential on a home machine with a small number of users. passwd Change the password on your current account. If you are root, you can change the password for any user using:
passwd user_namechmod perm filename (=change mode) Change the file access permission for the files you own (unless you are root in which case you can change any file). You can make a file accessible in three modes: read (r), write (w), execute (x) to three classes of users: owner (u), members of the same group as the owner (g), others on the system (o). Check the current access permissions using:
ls -l filename
If the file is accessible to all users in all modes it will show:
rwxrwxrwx
The first triplet shows the file permission for the owner of the file, the second for his/her group, the third for others. A "no" permission is shown as "-".
E.g., this command will add the permission to read the file "junk" to all (=user+group+others):
chmod a+r junk
This command will remove the permission to execute the file junk from others:
chmod o-x junk
Also try here for more info.
You can set the default file permissions for the news files that you create using the command "umask" (see man umask).chown new_ownername filename
chgrp new_groupname filenameChange the file owner and group.
You should use these two commands after you copy a file for use by somebody else.su (=super user) Assume the superuser (=root) identity (you will be prompted for the password). Type "exit" to return you to your previous login. Don't habitually work on your machine as root. The root account is for administration and the su command is to ease your access to the administration account when you require it. rpm -ivh files (=Red Hat Package Manager) Install a content of RedHat rpm package(s) and print info on what happened. See next command if you prefer a GUI installation. glint (in X terminal) Nice GUI front to the Red Hat Package Manager (rpm). Use it to to view the software packages installed on your system, the not-installed software packages available on your RH5.2 CD, display the info about them, and install them if you want (installation must be done as root). kernelcfg (as root in X terminal). GUI to to add/remove kernel modules. You can do the same from the command line using the command "insmod", but "insmode" is less "newbie-friedly". setserial /dev/cua0 port 0x03f8 irq 4 (as root) Set a serial port to a non-standard setting. The example here shows the standard setting for the first serial port (cua0 or ttyS0). The standard PC settings for the second serial port (cua1or ttyS1) are: address of i/o port 0x02f8, irq 3. The third serial port (cua2 or ttyS2): 0x03e8, irq 4. The forth serial port (cua3 or ttyS3): 0x02e8, irq 3. Add your setting to /etc/rc.d/rc.local if you want it to be set at the boot time. See man setserial for good a overview. fdisk (as root) Linux hard drive partitioning utility (DOS has a utility with the same name). cd /usr/src/linux-2.0.36
make xconfig(as root in X terminal). Nice GUI front-end for configuration of the kernel options in preparation for compilation of your customized kernel. (You need the "Tk" interpreter and the kernel source code installed). The alternatives are: "make config" (runs a scripts that asks you questions) and "make menuconfig" (runs a text-based menu-driven configuration utility). Try:
"less /usr/doc/HOWTO/Kernel-HOWTO" for more information.
After the configuration, you may choose to proceed with kernel compilation of the new kernel by issuing the following commands:
make dep
make zImage
The last command will take some time to complete (maybe 0.5 h, depending on your hardware). It produces the file "zImage", which is your new Linux kernel. Next:
make modules
make modules_install
Read: /usr/doc/HOWTO/Kernel-HOWTO for information on how to install the new kernel. You will probably also find it useful to read "man depmode". Configuration, compilation and installation of a new kernel is not difficult but it CAN lead to problems if you don't know what you are doing.
Compilation of a kernel is a good way to test your hardware, because it involves a massive amount of computing. If your hardware is "flaky", you will most likely receive the "signal 11" error (read the beatiful /usr/doc/FAQ/txt/GCC-SIG11-FAQ).
See this for detailed text on kernel upgrade.depmod -a (as root) Build the module dependency table for the kernel. This can, for example, be useful after installing and booting a new kernel. Use "modprobe -a" to load the modules. touch filename Change the date/time stamp of the file filename to the current time. Create an empty file if the file does not exist. mknod /dev/fd0 b 2 0 (=make node, as root) Create a device file. This example shows how to create a device file associated with your first floppy drive and could be useful if you happened to accidentlally erase it. The options are: b=block mode device (c=character mode device, p=FIFO device, u=unbuffered character mode device). The two integers specify the major and the minor device number. fdformat /dev/fd0H1440
mkfs -t -c ext2(=floppy disk format, as root) Perform low-level fromatting of floppy in the first floppy drive (/dev/fd0), high density (1440 MB). Then make a Linux filesystem (-t ext2), checking/marking bad blocks (-c ). Making the files system is an equivalent to the high-level format. badblocks /dev/fd01440 1440 (as root) Check the high density floppy for bad blocks and display the results on the screeen. The parameter "1440" specifies that 1440 blocks are to be checked. This command does not modify the floppy. fsck -t ext2 /dev/hda2 (=file system check, as root) Check and repair a filesystem. The example uses the partition hda2, filesystem type ext2. dd if=/dev/fd0H1440 of=floppy_image
dd if=floppy_image of=/dev/fd0H1440Create an image of the floppy to the file "floppy_image". Then copy the floppy image from a file to a floppy. Works like DOS "diskcopy". See here for details on mounting. This is a summary:
mount -t auto /dev/fd0 /mnt/floppy (as root) Mount the floppy. The directory /mnt/floppy must exist, be empty and NOT be your current directory. mount -t auto /dev/cdrom /mnt/cdrom (as root) Mount the CD. You may need to create/modify the /dev/cdrom file depending where your CDROM is. The directory /mnt/cdrom must exist, be empty and NOT be your current directory. mount /mnt/floppy (as user) Mount a floppy as user. The file /etc/fstab must be set up to do this. The directory /mnt/floppy must not be your current directory. mount /mnt/cdrom (as user) Mount a CD as user. The file /etc/fstab must be set up to do this. The directory /mnt/cdrom must not be your current directory. umount /mnt/floppy Unmount the floppy. The directory /mnt/floppy must not be your current directory.
G. Linux built-in developer tools and programming languages
netconf (as root) A very good menu-driven setup of your network. ping machine_name Check if you can contact another machine (give the machine's name or IP), press <Ctrl>-C when done. route -n Show the routing table. ipfwadm -F -p m Set up the firewall IP forwarding policy to masquerading. Not very secure but simple. See here for more secure settings. ifconfig (as root) Display info on the network interfaces currently active (ethernet, ppp, etc). Your first ethernet should show up as eth0, second as eth1, first ppp over modem ppp0, etc. The "lo" is the "loopback only" interface which should be always active. Use the options (see ifconfig --help) to configure the interfaces. ifup interface_name (/sbin/ifup to run as a user) Startup the interface. E.g.:
ifup eth0
ifup ppp0
Users can start up or shutdown the ppp interface only when the right permission was checked during the ppp setup using "netconf".ifdown interface_name (/sbin/ifdown to run it as a user). Shut down the network interface. netstat | more Displays a lot (too much?) information on the status of your network.
o Don't forget about the excellent shell programming which is even difficult to compare to MS DOS batch files. A shell script written for the "sh" shell starts with the comment:
emacs (in X-terminal) The emacs editor. For gurus only. Yes, the "vi" editor is also available (not recommended for newbies). To exit "vi" press:
<Esq>
:
q!<Enter>gcc filename.c GNU C compiler. Quite straight-forward. Good free manuals are available on the net. g++ filename.cpp GNU C++ compiler. perl Powerful and widely used scripting language. Flexible but with somewhat cryptic syntax. Very popular among gurus. python Modern and elegant object oriented interpreter. Seems as powerful and easier than perl. Very good (and large) free handbooks by G. van Rossum are available on the net (try: http://www.python.org/doc/ for browsing or ftp://ftp.python.org for downloading). tcl Popular scripting language. wish (xterm) A front end to Tk, an X-windows extension of tcl. Often used for building front-ends of a program. g77 GNU FORTRAN. If you are into FORTRAN, you may want to check:
http://studbolt.physast.uga.edu/templon/fortran.html
to find a FORTRAN compiler that suits your particular needs under Linux.f2c FORTRAN to c converter. fort77 FORTRAN compiler. Invokes f2c and then gcc or g++. basic "Chipmunk Basic". cvs Concurrent versions system. Try: info cvs diff file1 file2 > patchfile Compare content of two files and list any differences. Save the output to the file patchfile. sdiff file1 file2 Side-by-side comparison of two text files. patch file_to_patch patchfile Apply the patch (a file produced by diff, which lists differences between two files.) grep Search content of text files for matching patterns. Definitely worth to learn at least the basics of this command. The patterns are specified using a powerful and standard notation called "regular expressions". tr Translation utility (e.g. replace characters in a text file). gawk GNU awk (mostly for processing delimited text files). sed Tool for processing text files.
#!/bin/sh
o There are two good free versions of Pascal that I know of (Free Pascal and GNU Pascal), but they have to be downloaded/installed separately.
Go to Part 7: Essential Linux
applications (proprietary or not)