On this page, I (and many others) just wrote some stuff that did not
deserve (or need) their own section because of their simple nature. I
suggest anyone new to Linux and Unix read this section so that you will
jump in with enough knowledge. You probably have a lot more to add to
this, so make sure you e-mail
it to me to help more people.
- Free Space:
To find out how much disk space you have
left on your hard drive or mounted floppy drive, type df.
- Program Info:
For details about using a program you can
use the "man" command to access the manual page for that
particular program. For a description of the command "ls"
you would type man ls. Some programs do not have manual pages
("manpages"), and there are manpages that aren't really much
help. However, as you get more advanced with Linux you will find
manual pages to be an invaluable resource. Mark Schreiber wants to remind
us of the info command as well. Use info when looking
for Texinfo documentation.
- Deleting Directories:
To remove an entire directory
without being prompted if you want to delete each file, type rm -rf
directory-name, where "directory-name" is the name of
the directory. Be careful with this! (Also works with the cp
(copy) command, when you overwrite old files.) In case you're
wondering, the r is for recursive (moves through
subdirectories) and the f stands for force.
- Copying Entire Directory Trees:
To copy an entire directory
tree, preserving all permissions, you could do something like:
cd /source/directory/
cp -ap . /path/to/dest/
However, this can take a while for large trees with lots of small files
(i.e. large source trees). Perhaps a better way would be:
cd /source/directory/
tar cpf - . | tar xvf - -C /path/to/dest/
The advantage of this method (especially copying between physical drives,
or different machines as we'll see in a moment) is speed. The 'cp'
command will read one file from the source, and write to the destination,
rinse repeat, ad nauseum until the entire tree is copied. Tar, on the other
hand, will read from the source as fast as it can fill up the machine's memory.
The second tar command will empty files from memory to disk as quickly as
possible, making for a much more efficient overall process. Another advantage
of this approach is that it can be used to copy between machines over ssh:
cd /source/directory/
tar cpf - . | ssh dest_machine tar xvf - -C /path/to/dest/
This will print a list of files as they are being written to the destination.
Together with password-less ssh authentication (using public/private keys),
this can be used as a fairly efficient method of syncing up passwd files,
dns zones, mirror sites, or simply critical data from many machines which must be
backed up to tape, cd, etc..
- Shutting Down:
Shut down your system properly. Use the
command shutdown -h now as root. If you want to reboot, type
reboot or shutdown -r now. Mark Schreiber reminds us that
the Ctrl-Alt-Delete combination works as well, and does not require a
root login.
- Pipes:
Pipes provide a way to get the output of one
command into another command. For instance, if you want to see what's
in a very large directory, you can see a screenful at a time by piping
the output of ls into less. To do that, just separate
the commands with the "pipe" symbol, which is usually
[Shift - Backslash]. Try it by typing this:
ls |
less
Here's another example that uses two pipes to sort the
directory listing in reverse alphabetical order:
ls | sort -r |
less
(Paul Winkler, slinkp@angelfire.com)
- Redirection:
Redirection is related to the idea of
Pipes. Pipes "redirect" the output of a command into the
input of another command, but you can also redirect output to a file
(or even a device). To redirect the output of a command, use the
"<" symbol. One of the most common uses of redirection is
to save a directory listing:
ls > listing.txt
(Paul
Winkler, slinkp@angelfire.com)
- Checking File Integrity:
Use md5sum (or
md5 if you don't have that) to check whether a file is exactly
the same as where you transferred it from. Just run md5sum
filename and it should give you a string of letters and
numbers. This is useful for doing stuff across different systems where
you have transferred a file. If the results of md5sum on the same file
are different, then the file got corrupted or modified somehow, and
you don't want that. You want them to be the same.
- Finding Stuff:
Find any file on your system by typing
find / -name <name>. The "/" is telling it to
start from "/" and search everything under that, which is
everything on your filesystem. In place of "name" put the
name of the file you want to look for. You can also use
"*name*" to find anything with the string "name"
in its filename, for example.
- MOTD:
When a user logs in, you can edit /etc/motd
to print out a message on their screen. That file must be edited when
you are root. Just type in the plain text you want to display when
someone logs in.
- Do not IRC as root:
Do not log on to IRC as root. Even
if Nobody decides to try to penetrate your system, you are going to be
banned from a lot of the good technical help channels and
servers.
- Bailing Out:
If you're stuck in a program that won't
respond, try the "Ctrl-c" combination. In many cases even
that won't work, so use "Ctrl-z" to force it to stop. It's
best to exit the program the proper way, though.
- Managing RPMs:
In any distribution that uses the Red Hat
package manager (Red Hat, Caldera, and TurboLinux are a few) you can
just use the rpm command to install it from your CD. Use rpm
-i <filename> to install a package; rpm -U
<filename> to upgrade a package; and rpm -i --force
<filename> if you installed a package, but didn't use
rpm to remove it and want to reinstall it. The file name should
end in "*.rpm". If rpm doesn't work on your system
then you don't have it installed.
- Upper-case to Lower-case:
This little script renames all
the stuff in a directory to lowercase... for x in *; do mv $x
`echo $x | tr [A-Z] [a-z]`; done. (code by Warren Blumenow)
- More Managing RPMs:
To find out if you have an RPM
package installed, the syntax is rpm -qa | grep
"part_of_package_name".
- Boot Scripts:
The startup scripts are usually located in
/etc/rc.d/. Inside that directory you may find files such as
rc.local, rc.sysinit, rc.serial, and even
some subdirectories. The files contained in there may vary with each
distribution. If you want to start a program when Linux boots, you
probably want to put it in the rc.local file.
- Continuing FTP:
To continue downloading an
incomplete/interrupted file in FTP, use reget <filename>
after logging in to the FTP server.
- Finding Text in Files:
To search for a text string, the
basic syntax is grep "text string"
/directory/you/want/to/start/searching/from. If you don't want it
to be case sensitive then use grep -i "text string"
/directory/to/start".
- Exiting vi:
To exit from vi, the
standard text editor, type [ESC], : and then q. Typing
: will put you in command mode; wq will quit and write
any changes to the file; [ESC] i will put you back in insert
mode so that you can type text in.
- Red Hat Oopsies:
Regularly check the Red Hat Errata
pages for updates to your Red Hat distribution. The URL is http://www.redhat.com/support/docs/errata.html.
- Fresh Meat:
Check for Linux software updates at FreshMeat. Or, join and subscribe to
the mailing list to have the day's announcements mailed to you every
night.
- Filename Completion:
Tab filename completion allows you
to type in portions of a filename or program, and then press [TAB],
and it will complete the filename for you. If there's more than one
file or program that starts with what you already typed in, it will
beep, and then when you press [TAB] again it lists all the files that
start with what you initially type. Play around with it a little bit
to see what its limits are, how it can work for what you do, etc.
- ifconfig:
You can check to see what your
current IP addresses are using the ifconfig command.
- HOWTO-reading HOWTO:
When looking through a Linux HOWTO,
try to read only what you think you'll need. If you're still confused,
then try additional portions of the HOWTO that you think will be
helpful. This is useful if you've figured out part of the problem and
want to know how to do the rest.
- How big is it, anyway?:
To find out how much space a
directory and its contents take up, use the command du -b
--total to give you the output in bytes. There's a lot more you
can do with this command, just read the manpage using man
du. Another good trick is to do du -b | sort +0n -r >
foo-du.txt, then use less to look for really big
files.
- Development packages:
In case you decided to skip
installing development packages during the installation of your
distribution, and now can't compile source into binaries that you can
use ("command not found" when you're following the guides on
this page), install the following packages: autoconf, automake, make,
gcc, egcs, glibc, glibc-devel, kernel-headers, libstdc++,
XFree86-devel, and binutils. This will probably vary depending on your
distribution, but they're basically what you'll need. (Based on
experiments performed on Parker
Mead)
- Long Filenames:
Linux can handle long filenames--with
spaces, too! However, it's not a good idea to use spaces in filenames,
as it creates problems for many programs. To refer to them you'll have
to use quotation marks. So if I have a file called That report I
was working on then I'll have to edit it using pico
"That report I was working on".
- ^D:
Pressing ^D (Ctrl-D) on an empty line will close
that shell, either with the exit or logout command,
whichever is appropriate. When you've already typed something, and
then you press ^D, you'll see a list of filenames that start with the
thing you typed! (Sybren
Stuvel)
- How Do I...?:
When you know what you want to do but not
what command you need, try typing apropos subject. This
will print out a list of all the man pages having to do with
subject. (Paul
Winkler)
- Instant Replay:
Another nice bash feature: typing
!string will execute the most recent command that began
with string. (Paul
Winkler) If you type !?string then it will redo the
last command with <string>> anywhere in the command. I think
this is a more useful version as it makes it easier to make the last
command lookup search pattern more unique. (Rob Denison)
- ^Z:
^Z (Control-z) stops a job. After stopping a job,
you can do two things with it - start it again in the foreground or
start it again in background. To start the job in foreground again,
use fg n; to start the job in background use bg n, where
n is the job number. jobs will list all the jobs (along with
numbers) you currently have running. Note that "all the jobs you
currently have running" is only on the current tty - if you're
logged in as joe on tty1 and tty2, and you stop a job on tty2,
you can't do anything to it from tty1 (play with the jobs,
bg and fg commands - you'll see what I mean). Also note
that job numbers are not the same as process id (PID) numbers, so
DON'T TRY "kill 2" WHEN 2 IS THE JOB NUMBER FOR
ANYTHING. (Instead, try kill %2. Thanks to Mark Schreiber for this one.)
If you have many jobs running background and make the simple mistake
of killing a job number instead of a PID, you risk having some large
nasty problems. Trust me on that one. Why? Because a lot of very
important processes are loaded with very low PIDs, and it's a bad idea
to be signalling them without a good reason. (jbm)
- No more root Logins:
To never have to log on as root
again (having to log on as root is generally looked down upon as a bad
practice), try two very useful utilities: su and sudo.
"su" allows users to become the superuser if they know the
superuser password. Simply type su - at the prompt (the
"-" is so that it will discard the PATH variable by the user
you're using to become the superuser; this means it is almost exactly
like having a root login), and the program will ask for the
password. Enter it in, and poof - your $ is now a #. Type exit
to get back to being a normal user. (Note: you can also use su -
username; "su" will prompt you for
"username"'s password. If you are a superuser, you can just
do su - username and it won't prompt for a password. Use
"exit" to get back to being your usual self). This is very
useful for installing system-wide programs, or moving things
around. (jbm)
- Less is More:
Most of the new Linux distributions come
with a version of less that will automagically handle gzip'd
and zip'd files. This means you can just do less
my-big-gzipped-text-file.gz and it will act just like normal
less! (Otherwise, try zless.) Also, less can read
the directory structure of tar files - gzip'd ones, too. So to make
sure that new package you got actually creates its own directory, do
less foobar-1.0.tar.gz to see where all it puts
things; it'll spit out a listing somewhat like ls
-l. (jbm)
- Screenshots:
To grab a screenshot in X, use
xv. Open up xv and click "grab". Set the delay to 5
seconds and check "Hide XV windows". Click Grab and then click on the
root window (your desktop) and leave the mouse cursor over the desktop
(not over a window). The edge of your screen will blink and your
computer will beep to tell you it's grabbed the screenshot. Move the
xv window a little bit, and suddenly your whole screen will be
filled with the screenshot image. Right-click on that to bring up the
control window, and save the image. (jbm) You can also use the
import command from the ImageMagick package. Just type this in
an xterm: import foobar.jpeg and then click on the window you
want to grab. You can do other formats than jpeg, too. To grab the
whole screen, just do import -window root wholescreen.jpg. You
can do a lot of other tricks, like leaving out window borders,
delaying a number of seconds, grabbing a sequence of images to make an
animated GIF, etc. See man import. (Paul Winkler, slinkp@angelfire.com.
Got any tips of your own to add? Let me know and your name and
a link to your e-mail address or website will be included.
Copyright © 1997-1999 Joshua Go (joshuago at users dot sourceforge dot net). All
rights reserved. Permission to use, distribute, and copy this document is
hereby granted. You may modify this document as long as credit to me is
given.