Professional Documents
Culture Documents
du Display usage
Most common use, under a specific directory: du a
Easily and quickly identify the size of files/programs in certain directories. A word of
caution is that you should not run this command from the / directory. It will actually
display size for every file on the entire Linux harddisk.
(replace the word appname with the name of a file or application like gimp)
This is a very powerful command and is best used when running as root or superuser.
The danger is that you will potentially look across every single file on every filesystem,
so the syntax is very important. The example shown allows you to search against all
directories below / for the appname found in directories but only on the existing
filesystem. It may sound complex but the example shown allows you to find a program
you may need within seconds!
Other uses and more complex but beneficial functions include using the -exec or
execute a command.
You may also try the commands: locate or try slocate
The server runlevels rely on scripts to basically start up a server with specific processes
and tools upon bootup. Runlevel 5 is the default graphical runlevel for Linux servers.
But sometimes you get stuck in a different mode and need to force a level. For those
rare cases, the init command is a simple way to force the mode without having to edit
the inittab file.
Of course, this command does not fix the underlying problem, it just provides a fast
way to change levels as needed. For a more permanent correction to the runlevel, edit
your /etc/inittab file to state: id:5:initdefault:
joe or nano Easy to use command line editors that are often included with the major Linux flavors
Most common uses:
joe filename
nano filename
A real world example for you to get a better sense on how this works:
nano /etc/dhcp3/dhcpd.conf
This allows you to edit using nano the dhcpd.conf configuration file from the command
line.
Maybe you are not up to speed on vi, or never learned how to use emacs? On most
Linux flavors the text editor named joe or one named nano are available. These basic
but easy to use editors are useful for those who need a text editor on the command line
but don't know vi or emacs. Although, I do highly recommend that you learn and use Vi
and Emacs editors as well. Regardless, you will need to use a command line editor
from time to time. You can also use cat and more commands to list contents of files,
but this is basic stuff found under the basic linux commands listing. Try: more
filename to list contents of the filename.
sudo The super-user do command that allows you to run specific commands that require root
access.
Most common use: sudo command (replace command with your specific one)
This command is useful when you are logged into a server and attempt a command that
requires super-user or root privileges. In most cases, you can simply run the command
through sudo, without having to log in as root. In fact, this is a very beneficial way to
administer your server without daily use of the root login, which is potentially
dangerous.
Note there are other commands for file permissions here. Below is a simple example of
the sudo capabilities:
sudo cd /root
This command allows you to change directories to the /root without having to login as
root. Note that you must enter the root password once, when running a sudo command.
top Displays many system statistics and details regarding active processes
Most common use: top
This is a very useful system administrator tool that basically gives you a summary view
of the system including number of users, memory usage, CPU usage, and active
processes. Often during the course of a day when running multiple servers, one of my
Xwindows workstations just displays the top command from each of the servers as a
very quick check of their status and stability.
However, another option that I've used in the past when administering servers, is to
force a specific timestamp on a set of files in a directory. Read more of our commands
on our reallylinux.com help page.
For instance, to force a specific date and time upon all files in a directory, type:
touch *
You can also force a specific date/time stamp using the -t option like this: touch
t200103041200.00 *
The command above will change all files in the current directory to take on the new
date of March 4th, 2001 at noon. The syntax follows this pattern:
YYYYMMDDhhmm.ss
YYYY represents the four digit year, then the two digit month, day, hour and minutes.
You can even specify seconds as noted above. In any case, this is a useful way to
control timestamps on any files on your server.
traceroute Traces the existing network routing for a remote or local server
Most common use: traceroute hostname
(replace hostname with the name of your server such as reallylinux.com)
This is a very powerful network command that basically gives the exact route between
your machine and a server. In some cases you can actually watch the network hops
from country to country across an ocean, through data centers, etc. Read more of our
commands on our reallylinux.com help page.
This comes in handy when trying to fix a network problem, such as when someone on
the network can not get access to your server while others can. This can help identify
the break or error along the network line. One strong note to you is not to misuse this
command! When you run the traceroute everyone of those systems you see listed also
sees YOU doing the traceroute and therefore as a matter of etiquette and respect this
command should be used when necessary not for entertainment purposes. A key
characteristic of gainfully employed server administrators: knowing when to use
commands and when not to use them!
w An extension of the who command that displays details of all users currently on the
server
Most common uses: w
This is a very important system admin tool I use commonly to track who is on the
server and what processes they are running. It is obviously most useful when run as a
superuser.
The default setting for the w command is to show the long list of process details. You
can also run the command w s to review a shorter process listing, which is helpful
when you have a lot of users on the server doing a lot of things! Remember that this is
different than the who command that can only display users not their processes.
who Tool used to monitor who is on the system and many other server related characteristics
Most common uses: who and also who q and also who b
The plain command just lists the names of users currently on the server. Using the -q
option allows you to quickly view just the total number of users on the system. Using
the -b option reminds you how long it has been since you rebooted that stable Linux
server! One of my servers had a -b of almost three years! Yes, that's why we at
reallylinux.com call it really Linux!
Options:
-s print the sum of bytes in your directories
-a print a line for each file in your directory
grep The grep command searches text files for a
particular word or string of words. Very helpful
when trying to find that needle in a haystack,
like a particular line in a large log file.
syntax: grep textstring filename(s)
ex: grep century history.text.doc
head: prints the beginning of a text file
tail: prints the end of a text file
These commands allow you to view parts of a text
Head file.
tail -n 5 textfile.txt
Tail
head -n 5 textfile.txt
The examples above will print the last 5 lines
of the file textfile.txt and then the first 5
lines.
Trying to find out where on your Linux server a
particular file resides? Having a real nasty
time doing it? If you have the Bash shell you
can try using the locate command to identify
where it is on your mounted drives.
locate
Type: locate filename and press enter. Replace
filename with the name of the file you are
looking for. This is a real time saving command
as you start navigating your Linux server!
If locate does not work for you try using which.
Nice: runs programs/commands at a lower system
priority
Nohup: runs nice programs even when you’re
logged off the system
By using the two commands simultaneously, your
Nice large processes can continue to run, even when
Nohup you have logged off the system and are relaxing.
Ex: nice nohup c program.c .
This command will allow the c compiler to
compile program.c even when you have logged off
the system.
ps The ps command displays all of the existing
related to "stopped jobs" processes. This command is also directly linked
to issues with stopped processes (also known as
"stopped jobs").
Occasionally, you may see the message There are
Stopped Jobs.
If you log off the system without properly
stopping your jobs, some jobs/processes may
remain in memory tying up the system and drawing
unnecessary processing bandwidth.
Type ps and hit enter. This will list all of
your current processes running, or stopped.
The number under PID is the process
identification number. To kill a process that is
stopped, type: kill pid. Replace pid with the
exact number of the process.
Ex: While in Vi, you accidentally press the
wrong keys. Vi's operation is stopped and you
are kicked back to the prompt. To kill the
stopped Vi command, you may type: kill 23070.
The stty command allows you to view a listing of
your current terminal options. By using this
command, you can also remap keyboard keys,
tailoring to your needs.
Ex: stty and hit enter. This lists your terminal
settings.
stty Ex: stty erase\^h . This remaps your erase key
(backspace) to the Ctrl and h keys. From now on,
holding down Ctrl and pressing h will cause a
backspace. So you're scratching your head asking
why is this handy? You'll see at some point how
stty is also used for a number of other useful
settings.
In order to contact someone who is on the
system, at the prompt you type: talk accountname
. Replace accountname with the full account name
of the person. If you don’t want anyone to
talk
disturb you using the talk command, at the
prompt
type: mesg n. This prevents others from using
talk to reach you.
tar You're bound to come across files that are g
also related to gzip zipped and tarred. Okay, now what? These are
methods of compressing and storing directories
and files in a single "file." Most new Linux
programs come off the web as something like
coolnewgame.4401.gz. This file is likely a tar
file that has then been gzipped for compression.
The way to handle these files is simple, but
requires that you put the file into an
appropriate directory. In other words, don't
plop the file in your root or /bin unless it
belongs there.
Now you can do a one fell swoop un-gzip it and
untar it into its original form (usually
multiple files in many sub directories) by
typing: tar -xvzf *.gz