Basic command line stuff for non-programmer Newbies (like me)
Last update 09/08/03 by flw/Dan and
www.linuxforums.org This content is copywrited
==================================================
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.
==================================================
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:
/dev/hda1
/dev/hda2
/dev/hda3
and so on. In the above output hda1 is the c: drive for windows and hda2 is a
fat32 logical partition for Windows with hda3 being linux.
==================================================
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
=====================================================
To mount a share:
1. Type "mkdir /mnt/name_of_share" and press enter.
2. Type "mount -tsmbfs //servername/sharename /mnt/name_of_share -o
username=<USERNAME_HERE>,password=<PASSWORD_HERE>"
3. Replace <USERNAME_HERE> and <PASSWORD_HERE> with a valid username/password
that can be used to access that share.
Note: //server/share is the NETBIOS name of the pc (in example, "server" and the
sharename "/share".
4. To locate where your statup files are , run "updatedb".
5. Then run "locate rc.local". Put your commands in the rc.local file it finds.
All your files on the share will be accessable like normal files on the local
system from /mnt/name_of _share
6. If you edit the .bashrc file located in the /home/username/
and type the command mount -t there. Each user with that setting in .bashrc will
have that mounted drive.
=====================================================
How to unmount a drive :
From command line type "umount /mnt/name_of_ share" and enter.
=====================================================
Mount a Windows FAT32 drive:
As root, at the command line create the location for the windows partition:
"mkdir /mnt/windows"
Then mount the windows partition with: "mount -t vfat /dev/hda* /mnt/windows"
*=the partition you wish to mount as determined by "fdisk -l".
If you want this partition mount permanently then edit your /etc/fstab file and
add the partitions to be mounted at boot up.
=====================================================
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 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
=====================================================
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.
=====================================================
How to tell linux system time?
Use the `-R' option to output the date in the format described in RFC822 (see
section Word Lists and Reference Files): day of week followed by day of month,
month name, year, time, and time zone in numeric format. This is the date format
used in email messages.
To output the current date and time in RFC822 format, type:
$ date -R RET
Fri, 11 May 2001 11:10:29 -0400
$
You can also use the `-d' option to specify the precise fields to output, and
the order in which to output them. For more information, see the date man page
=====================================================
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.
Saturday, November 15, 2008
Guide for people new to linux command line
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment