Friday, November 25, 2005

Linux command line tips

Startup dir(s)

rc3.d is the normal multi user startup (non gui) bootup file in RH.
rc5.d is the normal GUI bootup file in RH.

To stop a service at bootup, you can remove the start instruction from there and that would stop the service starting.

last monitors logins
Last bad logins

lastb monitors bad logins
Make a bootable disk

Bootable disk, Mkbootdisk –device /dev/.fd0 2.0.34-1 (kernal version)


top –c To see cpu usage overall and by sevices
clear cmd line history

rm /home/joe/.bash_history (from home dir of user)
rm /.hash_history (this is for the root user)

Apache httpd.conf syntax checker (typo’s)

apachectl configtest
Samba smb.conf syntax checker (typo’s)

Command SwitchOptional FileLocation_Name

testparm /etc/samba/smb.conf
Telnet command to stop from being timed out of your session due to lack of activity (like your looking something up or going to the head).

Type “read” then press enter and when ready to start back just press enter again.

create a compress file of a directory
$tar cf - dir/* | gzip > dir.tar.gz
$tar cf - dir/* | bzip2 > dir.tar.bz2

shell loop to repeat something 20 times:
for i in `seq 1 20`; do echo "Number $i"; done

for netstat… see what programs have what ports open (probably better results when run as root):
netstat -nape --inet

kill any processes using the sound card (probably better results when run as root):
fuser -k /dev/dsp

see if a package named ‘mplayer’ is installed:
rpm -qa | grep mplayer

alias in my ~/.bashrc to get more efficient
alias r='rpm -qa | grep'

~/.bashrc alias to open the last edited file:
alias lvim='vim -c "normal '\''0"'

~/.bashrc alias to find a running process:
alias p='ps auxwww | grep'

A better ‘cd’… this does an ‘ls’ right after chaging dirs (add to ~/.bashrc):
cd() {
if [ "$PS1" ]
if [ "$1" ]
then builtin cd "$1" && ls
else builtin cd && ls
if [ "$1" ]
then builtin cd "$1"
else builtin cd

Handy disk space commands
ls -lSr #show files, biggest last
df -h #free disk space
df -i #free inodes
du -hs ... #disk usage of specified files/dirs
fdisk -l #show disks partitions sizes (run as root)

reload squid config file. it could be used with any signal and any process name. Useful when the process has more than one child.
kill -SIGHUP `pgrep squid`

shows every mounted file system whith total space, used, available and filesystem type
df -hT

useful to get directories sizes o file sizes as well
du -hs *

shows all process owned by any user in a tree (forest) way.
ps xaf


read This is an old trick to keep a telnet session from timing out on you.
fdisk -l

The minus lower case “l” displays the names of all physical and logical drives. You’ll need this if you wish to work with other drives like mounting a windows drive etc… The output on a RedHat box is like:



ls {path} It’s ok to combine attributes, eg ls -laF gets a long listing of all files with types.

ls {path_1} {path_2} List both {path_1} and {path_2}.

ls -l {path} Long listing, with date, size and permisions.

ls -a {path} Show all files, including important .dot files that don’t otherwise show.

ls -F {path} Show type of each file. “/” = directory, “*” = executable.

ls -R {path} Recursive listing, with all subdirs.

ls {path} > {filename} Redirect directory to a file.

ls {path} | more Show listing one screen at a time.

Emacs-nox text editor

Cntrl/x cntrl/s saves document
Cntrl/x cntrl/c closes document
Cntrl/k cut a individual text line
Cntrl/y paste the previously cut test line
Su - Login as root w/root profile via telnet or ssh i.e. paths for root is not the same as

VI text editor

I or esc =insert
:=preface all commands
:w= save (:w!)
:u= undo
:q= quit
:d= delete line
:p= pastes at cursor
= pastes after cursor
:yy= copies line where cursor is
:dd = deletes line at cursor
Change access permissions

chmod determines file rights, Chmod 0777 file.txt all can r/w/x, chmod 0755 file.txt public or

grp can only r/x, chmod 0644 test.txt public or grp can only read,
chmd 0711 file.txt public or grp can only x

Another to look at it is:
chmod 600 {filespec} You can read and write; the world can’t. Good for files.

chmod 700 {filespec} You can read, write, and execute; the world can’t. Good for scripts.

chmod 644 {filespec} You can read and write; the world can only read. Good for web pages.

chmod 755 {filespec} You can read, write, and execute; the world can read and execute. Good for

programs you want to share, and your public_html directory.

Grep searches a file(s) for matching pattern such as text search.

grep ‘text string’ -r /home | awk ‘{print$2}’ This goes to the monitor.

grep ‘text string’ -r /home > textstring.txt For redirect to file.

-r is recursive/home/usrname is starting point

Enable floppy disk or CD access

mount –t vfat /dev/fd0 /mnt/dos or floppy (for DOS file system) or mount /dev/fd0 (working dir is /mnt/floppy) or mount –t iso9660 /dev/cdrom /mnt/cdrom
Remove floppy disk or CD access

umount /dev/fd0 or /mnt/floppy