==================================================
Manual
man {command}, Type man ls to read the manual for the ls command.
==================================================
Read
read This is an old trick to keep a telnet session from timing out on you.
==================================================
List
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.
==================================================
Change directory
cd {dirname} There must be a space between.
cd ~ Go back to home directory, useful if you're lost.
cd .. Go back one directory.
==================================================
Make directory
mkdir {dirname} To make a new directory
==================================================
Remove directory
rmdir {dirname} Only works if {dirname} is empty.
rm -r {dirname} Remove all files and subdirs. Careful!
rm -rf {dirname} Remove all file and subdir with force.
==================================================
Print working directory to screen
pwd Show where you are as full path.
==================================================
Copy
cp {file1} {file2}
cp -r {dir1} {dir2} Recursive, copy directory and all subdirs.
cat {newfile} >> {oldfile} Append newfile to end of oldfile.
==================================================
Move
mv {oldfile} {newfile} Moving a file and renaming it are the same thing.
==================================================
Remove
rm {filespec} ? and * wildcards work like DOS should. "?" is any character; "*" is any string of
characters.
==================================================
Date
date Shows sys date and time.
==================================================
Apps for basic configuration
Changes services installed or changes them:
Ntsysv or linuxconf
==================================================
Check dir sizes of homes (or any dir) use the following:
Cd /home
Du –s * | sort –rn |head –30
30 is the number of directories starting from the largest.
===================================================
Backup the dir's on a server run the following from /:
Tar -cfz /dir/filename.tgz /var/qmail/ /etc
Verify file is in /home and correct size/date.
Tar and Gunzip
Tar switches /source/ destination
1. Compress. Tar –cvzf filename.tar.gz /sourceoftar
Tar – cvzf etc.tar.gz /etc
2. Decompress
gunzip filename.tar.gz
gunzip etc.tar.gz
or
tar –xf etc.tar
=====================================================
RPM's (Redhat Package Manager)
To install a package: rpm –ivh
ex. rpm -ivh somepackage.1.1-4.i386.rpm
To upgrade a package: rpm -Uvh [filename]
ex. rpm -Uvh somepackage.1.1-5.i386.rpm
To remove a package: rpm -e [packagename only no .rpm or version number]
ex. rpm -evh somepackage
=====================================================
To see if a package is installed: rpm -q [packagename]
ex. rpm -q somepackage
Rpm –q webadmin
=====================================================
To get info on an installed package: rpm -qi [packagename]
ex. rpm -qi somepackage
=====================================================
Disk free space
df amount of free disk space df –I by drives
=====================================================
Disk usage
du amount of used disk space du –s or du -s*
=====================================================
Date
Date shows/sets current date date MMDDhhmmYYYY (sets date/time)
=====================================================
Who is online
Who users currently on system
=====================================================
Free
Free how much RAM and cache is free
=====================================================
Who is online
w users online and what files are being used
=====================================================
Touch
Touch create a empty file
=====================================================
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
user
=====================================================
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.
=====================================================
To locate file
find –name filename –print
=====================================================
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
=====================================================
Add a user
Adduser username
=====================================================
Change a password
passwd to set or change password
=====================================================
Delete a user
Userdel username
=====================================================
Modifiy user name
usermod to change username, Usermod -l newname oldname
=====================================================
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
=====================================================
Process identification number and name
ps or ps –ax for all services running or ps –ef > file.txt
=====================================================
Stop Process idendification number and name
kill ps#, kill 188 or kill Kill 188, or kill -9 188
=====================================================
Start or Restart a process
ServiceName , then enter i.e. sshd or httpd etc...
=====================================================
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 (eg S55sshd) instruction from there and that would stop the service starting.
=====================================================
Last
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)
=====================================================
Uname
uname –r is to determine kernal ver
=====================================================
Top
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)
=====================================================
ifconfig for status of active interfaces.
ifconfig To get the currently active interfaces.
ifconfig -a Displays the status of all interfaces, even those that are down.
=====================================================
Apache httpd.conf syntax checker (typo's)
apachectl configtest
==========================%D=====
Touch
Touch create a empty file
=====================================================
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
user
=====================================================
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.
=====================================================
To locate file
find –name filename –print
=====================================================
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
=====================================================
Add a user
Adduser username
=====================================================
Change a password
passwd to set or change password
=====================================================
Delete a user
Userdel username
=====================================================
Modifiy user name
usermod to change username, Usermod -l newname oldname
=====================================================
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
=====================================================
Process identification number and name
ps or ps –ax for all services running or ps –ef > file.txt
=====================================================
Stop Process idendification number and name
kill ps#, kill 188 or kill Kill 188, or kill -9 188
=====================================================
Start or Restart a process
ServiceName , then enter i.e. sshd or httpd etc...
=====================================================
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 (eg S55sshd) instruction from there and that would stop the service starting.
=====================================================
Last
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)
=====================================================
Uname
uname –r is to determine kernal ver
=====================================================
Top
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)
=====================================================
ifconfig for status of active interfaces.
ifconfig To get the currently active interfaces.
ifconfig -a Displays the status of all interfaces, even those that are down.
=====================================================
Apache httpd.conf syntax checker (typo's)
apachectl configtest
=====================================================
Directory Structure basics
/ The 'root' directory; reference point for all directories.
/bin Binaries which are absolutely essential to run Linux.
/boot All the files required for booting Linux on a system.
/dev All the devices have their corresponding files here.
/etc All the configuration files for the various software are stored here. Don't play with this directory.
/home All users will have their 'My Documents' under this directory. If your id is tomh, your 'My Documents' (called home-directory) /home/tomh.
/lib The libraries required by system-applications. (Just like DLLs in Windows.)
/lost+found When a disk-check finds files which are damaged or which are not linked to any directory, they are recovered to this directory. Such damages are almost always due to incorrect shutdown.
/misc Miscellaneous files!
/mnt The directory where peripherals and other file-systems are mounted.
/opt The directory where optional software are installed.
/proc proc houses a pseudo-filesystem. Its contents really do not exist anywhere on the disk, and are made available only when you cd to this directory and look at some file. Don't worry about it, anyway.
/root The home-directory for the super-user: root.
/sbin The system-administration binaries exist here.
/tmp The directory where temporary files are created and stored.
/usr Everything related to users!
/usr/bin /bin houses critical binaries, whereas /usr/bin stores other binaries: not so critical but required nevertheless.
/usr/include The header-files required by programs for compilation.
/usr/lib The libraries required by user-applications.
/usr/local Files peculiar to this particular machine.
/usr/sbin User-administration binaries.
/usr/share Information that can be shared by most users.
/usr/src The source-code for the Linux kernel.
/usr/X11R6 Files needed by the X Window system.
/var Files whose contents vary frequently are in this directory.
/var/log The log-files of the system.
/var/spool Directories for mail, news, printing and other queued work.
Written by FLW from www.elitelinux.com