04-05-2003
|
#1 (permalink)
| | Linux Engineer
Join Date: Mar 2003 Location: U.S.A.
Posts: 1,025
| Guide for people new to linux command line NOTE: if you read the tutorial and are still experiencing difficulties and would like help, you are asked to start a new topic on the forums.
Please do NOT reply to this thread to ask a technical question. Replies to THIS thread should be corrections and enhancements on the tutorial/howto only.
Thanks in advance for your co-operation.
LinuxForums.org
------------------------------------------ Code: 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.
__________________
Dan
\"Keep your friends close and your enemies even closer\" from The Art of War by Sun Tzu\"
|
| |
06-08-2003
|
#2 (permalink)
| | Linux Guru
Join Date: Apr 2003 Location: London, UK
Posts: 3,284
| If you want a soft introduction to the linux shell, have a look at this site: http://www.linuxcommand.org/
Jason |
| |
07-23-2003
|
#3 (permalink)
| | Just Joined!
Join Date: Jul 2003
Posts: 5
| jus one more command I would add jus' one more command to the wonderful list given by Dan
"enscript [-2E] file -o file.ps"
With this command you can print out any file in emacs(tex,cpp,java,..)
ones in bracket at optional
2 - if u wanna make it in two columns
E - To highlight the key words in c/c++/java....
cheers,
me |
| |
07-23-2003
|
#4 (permalink)
| | Linux Engineer
Join Date: Mar 2003 Location: U.S.A.
Posts: 1,025
| Quote:
I would add jus' one more command to the wonderful list given by Dan
"enscript [-2E] file -o file.ps"
With this command you can print out any file in emacs(tex,cpp,java,..)
ones in bracket at optional
2 - if u wanna make it in two columns
E - To highlight the key words in c/c++/java....
| The tut has been written for new users. There are many addon's that could be made like yours so its a grey line to draw. I could have included cat but decided the typical ex-windows user would not use it until they got beyond the new user level.
I do believe you do have a good idea and wonder (out loud  ) if another user here would like to create and submit for approval to Jaguar a cmd line tut for the intermediate/advanced user? The author would take the basic tut and expand the cmd's beyond their basic usage as well as discuss additional cmd's like the print output cmd's like yours, cat, etc... Maybe even some common app specifice stuff? It would be up to the author.
I made mine off a existing doc I made for myself. I needed it because I didn't and still don't have it all memorized  I'm still a nOOb. 
__________________
Dan
\"Keep your friends close and your enemies even closer\" from The Art of War by Sun Tzu\"
|
| |
07-24-2004
|
#5 (permalink)
| | Just Joined!
Join Date: Jul 2004
Posts: 15
| Been looking for this type of stuff and links since starting to use Linux Suse9.1 Thanks
Any chance of writing other stuff to help the new user like me? For example i've been trying to installl a bz2 file but when reading the install explinations you come across things like (eg)
(driver to your Voyager 100 modem) and unzip it (as Root in a shell) with
CODE
bzip2 -d eciadsl-usermode-nortek2021.tar.bz2
It will extract the driver, then you must untar it with
CODE
tar -xzvf eciadsl-usermode-nortek2021.tar.bz2
Then change directory to the dir it untarred to, then follow the instructions in the README file.
I couldnt even follow it never mind get the system responce I thought I would
Anyway i'd prefare to be taken by the hand and taken from system startup to the installation of the driver package without fealing like i'm running all over the place and getting nowhere fast like I am at the mo cos I aint as brainy as some others. |
| |
07-25-2004
|
#6 (permalink)
| | Linux User
Join Date: Jul 2004 Location: Hartlepool, England
Posts: 384
| great tut there, we n00bs are not worthy 
__________________
Graham - You'd better Use Linux!
I'm registerd Linux user #397030. What about you? |
| |
07-25-2004
|
#7 (permalink)
| | Linux Guru
Join Date: Mar 2004 Location: Lat: 39:03:51N Lon: 77:14:37W
Posts: 2,397
| wouldn't evne say just newbies, but i think, most everyone can benifit from something liek that. all my cli knowlege was a hodpodge of waht was needed at the moment, an actual list of flags and uses is nice.
__________________
Avoid the Gates of Hell. Use Linux
A Penny for your Thoughts Formerly Known as qub333 |
| |
10-07-2004
|
#8 (permalink)
| | Just Joined!
Join Date: Oct 2004 Location: North Port, Florida
Posts: 3
| Thanks for the tutorial man! Just installed Linux this week and was looking for somethin like this! 
__________________
nothing can stop me now
|
| |
10-12-2004
|
#9 (permalink)
| | Just Joined!
Join Date: Oct 2004 Location: UK
Posts: 12
| Tar and it's flags... Will allow you to unzip as well - including bzip2 files
tar -jvf somefile.tar.bz2 will untar and unbzip2 the file. No need for two commands.
Also remember you can use the pipe | to pass the output of one file as the input of the next line
bunzip2 -d file.tar.bz2 | tar -vf -
The - after the f in tar says use standard in. |
| |
10-12-2004
|
#10 (permalink)
| | Just Joined!
Join Date: Oct 2004 Location: UK
Posts: 12
| Wow - other useful ones that aren't mentioned mounting an ISO image.
Linux has the ability to mount an ISO (image of a CD) and have it appear as a filesystem
mount -t iso9660 -o loop,ro /path/to/iso /path/mount/point
/path/mount/point has to exist
example
mount -t iso9660 -o loop,ro ~/isos/windows.iso /mnt/windows/
You can then see the content of the CD as files in your /mnt/windows directory. |
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Thread Tools | | | | Display Modes | Linear Mode |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | | | | Free Magazines | Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe | Systems Management News, the newspaper for IT systems administration and data center managers!
Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe | The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe | Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe | Total Telecom Total Telecom is "The Economist of the communications industry". subscribe | | More free magazines » | All times are GMT. The time now is 11:56 PM. |
| |